#include #pragma GCC optimize("O1") #define endl '\n' #include #include #include #include #include #include #include #include #include #include #include #define int long long int using namespace std; signed main() { #ifdef ONLINE_JUDGE freopen("planets.in", "r", stdin); freopen("planets.out", "w", stdout); #endif int n, m; cin >> n >> m; vector planets(n); for (int i = 0; i < n; ++i) { cin >> planets[i]; } vector years(m); for (int i = 0; i < m; ++i) { cin >> years[i]; } sort(planets.begin(), planets.end()); //sort(years.begin(), years.end()); long long maxWeight = 0; long long currentWeight = 0; int planetIndex = 0; for (int year : years) { while (planetIndex < n && planets[planetIndex] <= year) { planetIndex++; break; } maxWeight += (year - planets[planetIndex - 1]) * (year - planets[planetIndex - 1]); //cout << planetIndex << " "; } cout << maxWeight << endl; return 0; }