#include #define ll long long using namespace std; int N, M; ll sol, P[100005], Y[100005]; int main() { freopen("planets.in", "r", stdin); freopen("planets.out", "w", stdout); scanf("%d %d", &N, &M); for(int i = 1; i <= N; i++) { scanf("%lld", &P[i]); } for(int i = 1; i <= M; i++) { scanf("%lld", &Y[i]); } sort(P + 1, P + N + 1); sort(Y + 1, Y + M + 1); priority_queue H; for(int i = 1, j = 0; i <= M; i++) { while((P[j + 1] <= Y[i]) && (j < M)) { j++; H.push(P[j]); } sol += (Y[i] - H.top()) * (Y[i] - H.top()); H.pop(); } printf("%lld\n", sol); return 0; }