malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7f7f7f7f;   const double EPS = 1e-8;   int n, m;   int ans[707][707][3];   bool used[707];   int start;   void DFS(int v, int len = 0) {     used[v] = true;     for (int i = 0; i < n; i++) {       if (ans[v][i][0] && !used[v]) {         DFS(i, len + 1);       }     }     used[v] = false;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       ans[a][b][0] = ans[b][a][0] = 1;     }     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (ans[u][t][0] && !used[t]) ++ans[i][t][1];           }           used[u] = false;         }       }       used[i] = false;     }     long long sum = 0;     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (!used[t]) {               ans[i][t][2] += ans[u][t][1];               if (ans[i][t][0]) --ans[i][t][2];             }           }           used[u] = false;         }       }       used[i] = false;     }     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (!used[t] && ans[i][t][0]) {               sum += ans[u][t][2];               int minus = 0;               if (ans[u][t][0]) minus = 1;               sum -= (long long)(max(0, ans[i][u][1] - minus)) +                      (max(0, ans[i][t][1] - minus));             }           }           used[u] = false;         }       }       used[i] = false;     }     cout << sum / 5 / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> sn[100005], sp[100005];   bool myfunction(pair<long long, long long> i, pair<long long, long long> j) {     return (i.first > j.first);   }   int main() {     int n, p, a, first = 0, second = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p, &a);       if (p < 0) {         first++;         sn[first] = make_pair(p, a);       } else {         second++;         sp[second] = make_pair(p, a);       }     }     sort(sn, sn + first + 1, myfunction);     sort(sp, sp + second + 1);     for (int i = 1; i <= first; i++) sn[i].second += sn[i - 1].second;     for (int i = 1; i <= second; i++) sp[i].second += sp[i - 1].second;     sn[first + 1] = sn[first];     sp[second + 1] = sp[second];     int m = min(first, second);     long long ans = sp[m + 1].second + sn[m].second;     ans = max(ans, sp[m].second + sn[m + 1].second);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   const long long inf = (1ll << 58ll);   int k, n, q;   int ten[10] = {1, 10, 100, 1000, 10000, 100000};   long long F[7];   long long dp[maxn], g[7][maxn];   long long read() {     long long s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * f;   }   int main() {     k = read();     for (int i = 0; i < 6; ++i) F[i] = read();     fill(dp, dp + 1 + 999999, -inf);     dp[0] = 0;     for (int d = 1; d <= 6; ++d) {       long long left = 1ll * 3 * (k - 1);       long long group = 1ll;       while (left > 0) {         group = min(group, left);         long long val = 1ll * group * F[d - 1];         long long wei = 1ll * 3 * group * ten[d - 1];         for (int i = 999999; i >= wei; --i) {           dp[i] = max(dp[i], dp[i - wei] + val);         }         left -= group;         group *= 2;       }     }     for (int i = 1; i <= 6; ++i) fill(g[i], g[i] + 1000000, -inf);     for (int i = 0; i <= 999999; ++i) g[0][i] = dp[i];     for (int d = 1; d <= 6; ++d) {       for (int j = 0; j <= 9; ++j) {         long long val, wei;         if (j == 3 || j == 6 || j == 9)           val = 1ll * (j / 3) * F[d - 1];         else           val = 0;         wei = 1ll * j * ten[d - 1];         for (int i = 999999; i >= wei; i--)           g[d][i] = max(g[d][i], g[d - 1][i - wei] + val);       }     }     q = read();     for (int i = 1; i <= q; ++i) {       n = read();       printf( %lld n , g[6][n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, c[205], num = 1e9;   vector<int> a, ans;   void dfs(int n, vector<int> a, int d, int t) {     if (n == 0) {       if (d < num) {         ans.clear();         num = d;         for (int i = 0; i < d; i++) ans.push_back(c[i]);       }       return;     }     int m = a.size();     bool f = 1;     for (int i = 0; i < m; i++)       if (a[i] % 2 != 0) {         f = 0;         break;       }     if (f) {       for (int i = 0; i < m; i++) a[i] /= 2;       return dfs(n / 2, a, d, t + 1);     }     if (m == 2 && a[0] == 0 && a[1] == 1 || m == 1 && a[0] == 1) {       c[d] = 1 << t;       return dfs(0, a, d + 1, t + 1);     }     if (m == 2 && a[0] == -1 && a[1] == 0 || m == 1 && a[0] == -1) {       c[d] = -(1 << t);       return dfs(0, a, d + 1, t + 1);     }     vector<int> b;     b.clear();     int lst = -1e9;     for (int i = 0; i < m; i++) {       int u = a[i];       if (u % 2 == 0)         u /= 2;       else         u = (u - 1) / 2;       if (u != lst) {         b.push_back(u);         lst = u;       }     }     c[d] = 1 << t;     dfs((n + 1) / 2, b, d + 1, t + 1);     b.clear();     lst = -1e9;     for (int i = 0; i < m; i++) {       int u = a[i];       if (u % 2 == 0)         u /= 2;       else         u = (u + 1) / 2;       if (u != lst) {         b.push_back(u);         lst = u;       }     }     c[d] = -(1 << t);     dfs((n + 1) / 2, b, d + 1, t + 1);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a.push_back(x);     }     sort(a.begin(), a.end());     dfs(100000, a, 0, 0);     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, ans;   int main() {     scanf( %I64d%I64d , &n, &m);     if (n > m) swap(n, m);     if (n == 2) {       if (m <= 2)         ans = 0;       else {         ans = n * m;         if (m == 3)           ans -= 2;         else if (m == 7)           ans -= 2;       }     } else if (n == 1) {       ans = n * m;       long long t = ans % 6;       if (t <= 3)         ans -= t;       else if (t == 4)         ans -= 2;       else if (t == 5)         --ans;     } else {       ans = (n * m) - ((n * m) & 1);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a, b, c, d;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       int rice_left = a - b;       int rice_right = a + b;       int packeg_left = c - d;       int packeg_right = c + d;       rice_left *= n;       rice_right *= n;       if (rice_left > packeg_right || rice_right < packeg_left)         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[20000], i, j, s = 1;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] % 2) {         printf( %d n , (s + a[i]) / 2);         s *= -1;       } else         printf( %d n , a[i] / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 1;   const int INF_INT = 2e9 + 100;   const long long POLTOS = 50;   const long long SOTKA = 100;   const long long P = 1e9 + 7;   const long double eps = 1e-9;   const long long base = 1000 * 1000 * 1000;   const long long M = 3050;   const long long MAXN = 1e6 + 1;   const long long MAXN1 = 2 * 1e2;   const long long N = 2e5 + 1000;   const long double pi = acos(-1);   const long long mod = 1e9 + 7;   const int S_M = 20;   const long long LEN = 96;   const long long DMOD = 500000004;   const long long PR = 32000;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     for (auto &i : a) {       cin >> i.first;     }     for (auto &i : a) {       cin >> i.second;     }     sort(a.begin(), a.end(),          [&](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });     vector<int> used(k + 1, false);     multiset<int> b;     for (int i = 0; i < n; ++i) {       if (used[a[i].first]) {         b.insert(a[i].second);       } else {         used[a[i].first] = 1;       }     }     long long ans = 0;     for (int i = 1; i <= k; i++)       if (!used[i]) {         ans += *b.begin();         b.erase(b.begin());       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   inline long long pow(long long a, long long b, long long mod) {     long long ans = 1;     a %= mod;     for (; b; b >>= 1, a = a * a % mod)       if (b & 1) ans = ans * a % mod;     return ans;   }   struct Node {     int L, R;     mutable long long val;     Node(int L, int R = -1, long long val = 0) : L(L), R(R), val(val) {}     inline bool operator<(const Node& b) const { return L < b.L; }   };   std::set<Node> Chtholly;   inline std::set<Node>::iterator spilt(int pos) {     std::set<Node>::iterator iter = Chtholly.lower_bound(Node(pos));     if (iter != Chtholly.end() && iter->L == pos) return iter;     --iter;     int L = iter->L, R = iter->R;     long long V = iter->val;     Chtholly.erase(iter);     Chtholly.insert(Node(L, pos - 1, V));     return Chtholly.insert(Node(pos, R, V)).first;   }   inline void Add(int L, int R, long long val = 1) {     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     for (; iter != end; ++iter) iter->val += val;   }   inline void assign(int L, int R, long long val = 0) {     std::set<Node>::iterator terR = spilt(R + 1), terL = spilt(L);     Chtholly.erase(terL, terR);     Chtholly.insert(Node(L, R, val));   }   inline long long Rank(int L, int R, int k) {     std::vector<std::pair<long long, int> > s;     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     for (; iter != end; ++iter) {       s.push_back(std::pair<long long, int>(iter->val, iter->R - iter->L + 1));     }     std::sort(s.begin(), s.end());     for (auto iter : s) {       k -= iter.second;       if (k <= 0) return iter.first;     }     return -1ll;   }   inline long long Sum(int L, int R, long long k, long long mod) {     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     long long ans = 0;     for (; iter != end; ++iter) {       ans = (ans + 1ll * (iter->R - iter->L + 1) * pow(iter->val, k, mod) % mod) %             mod;     }     return ans;   }   long long n, m, seed, vmax;   const int MOD = 1e9 + 7;   inline long long rnd() {     long long ret = seed;     seed = (seed * 7 + 13) % MOD;     return ret;   }   signed main() {     int i;     scanf( %lld%lld%lld%lld , &n, &m, &seed, &vmax);     for (i = 1; i <= n; ++i) Chtholly.insert(Node(i, i, rnd() % vmax + 1));     Chtholly.insert(Node(n + 1, n + 1, 0));     for (i = 1; i <= m; ++i) {       int op = rnd() % 4 + 1, L = rnd() % n + 1, R = rnd() % n + 1, x, y;       if (L > R) L ^= R ^= L ^= R;       x = rnd() % (op == 3 ? R - L + 1 : vmax) + 1;       if (op == 4) y = rnd() % vmax + 1;       if (op == 1) {         Add(L, R, x);       }       if (op == 2) {         assign(L, R, x);       }       if (op == 3) {         printf( %lld n , Rank(L, R, x));       }       if (op == 4) {         printf( %lld n , Sum(L, R, x, y));       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   int vis[12];   bool ok(long long mid, int x) {     long long m = mid % 7;     int day = x;     long long res[5];     res[1] = mid / 7;     res[2] = mid / 7;     res[3] = mid / 7;     res[1] *= 3;     res[2] *= 2;     res[3] *= 2;     while (m--) {       res[vis[day]]++;       day++;       day %= 7;     }     return res[1] <= a && res[2] <= b && res[3] <= c;   }   long long ans(int x) {     long long st = 0, en = 1e12;     while (st < en) {       long long mid = (st + en) / 2;       if (ok(mid, x))         st = mid + 1;       else         en = mid;     }     return st;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> a >> b >> c;     vis[0] = 2;     vis[1] = 1;     vis[2] = 1;     vis[3] = 2;     vis[4] = 3;     vis[5] = 1;     vis[6] = 3;     long long mx = 0;     for (int i = 0; i < 7; i++) {       mx = max(mx, ans(i));     }     cout << --mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-7, PI = 3.1415926;   const int N = 2e5 + 10;   using namespace std;   int n, q, m, k, x, y, a[N], mx = -1, mn = 1e9, sum, t;   char c[N];   string s, s1, s2;   map<pair<int, char>, int> mp;   vector<int> vec;   int main() {     cin >> q;     while (q--) {       cin >> n;       cin >> s1 >> s2;       y = 0;       mp.clear();       sum = 0;       for (int i = 0; i < 20; i++) {         char v =  a  + i;         mn = 1e9;         int hg = 20;         while (hg--) {           mn = 1e9;           for (int j = 0; j < n; j++) {             if (s1[j] == v && s2[j] != s1[j]) {               mn = min(mn, s2[j] - s1[j]);             }           }           for (int j = 0; j < n; j++) {             if (s1[j] == v && s2[j] != s1[j]) {               s1[j] += mn;             }           }           if (mn < 0) y = 1;           if (mn == 1e9)             break;           else             sum++;         }       }       if (!y)         cout << sum << endl;       else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   const int INF = 0x3f3f3f3f;   int a[MAXN];   int book[MAXN * 2];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int tmp;       scanf( %d , &tmp);       a[tmp] = 1;     }     queue<int> Q;     memset(book, 0x3f, sizeof(book));     for (int i = 0; i <= 1000; i++) {       if (a[i]) {         book[i - n + MAXN] = 1;         Q.push(i - n + MAXN);       }     }     while (!Q.empty()) {       if (book[MAXN] != INF) {         return 0 * printf( %d n , book[MAXN]);       }       int now = Q.front();       Q.pop();       for (int i = 0; i <= 1000; i++) {         if (!a[i]) continue;         int co = i - n;         int nxt = now + co;         if (nxt < 0 || nxt > 2005) continue;         if (book[nxt] > book[now] + 1) {           Q.push(nxt);           book[nxt] = book[now] + 1;         }       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ring {     int inside, outside, height;   } rings[200000];   long long all, tot;   bool cmp(ring a, ring b) {     if (a.outside != b.outside) return a.outside < b.outside;     return a.inside < b.inside;   }   int main() {     int n;     while (cin >> n) {       all = 0;       tot = 0;       for (int i = 0; i < n; i++) {         scanf( %d%d%d , &rings[i].inside, &rings[i].outside, &rings[i].height);       }       sort(rings, rings + n, cmp);       stack<ring> keys;       for (int i = n - 1; i >= 0; i--) {         while (1) {           if (keys.empty()) break;           ring key = keys.top();           if (key.outside >= rings[i].outside && key.inside < rings[i].outside)             break;           all -= key.height;           keys.pop();         }         keys.push(rings[i]);         all += rings[i].height;         tot = max(tot, all);       }       cout << tot << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   int dp[maxn][40];   long long pw[maxn][40];   long long n;   int dfs(int a, int b) {     if (dp[a][b]) return dp[a][b];     if (pw[a][b] >= n) return dp[a][b] = 1;     if (pw[a][2] >= n) {       if ((n - a) % 2 == 0)         return dp[a][b] = 1;       else         return dp[a][b] = 2;     }     if (dfs(a + 1, b) == 2 || dfs(a, b + 1) == 2) return dp[a][b] = 1;     return dp[a][b] = 2;   }   long long a, b;   int main() {     scanf( %lld%lld%lld , &a, &b, &n);     for (int i = 1; i < maxn; i++) {       pw[i][0] = 1;       for (int j = 1; j <= 35; j++) {         pw[i][j] = pw[i][j - 1] * i;         if (pw[i][j] >= n) {           for (int k = j; k <= 35; k++) pw[i][k] = n;           break;         }       }     }     dfs(a, b);     if (a == 1) {       for (int i = b; i <= 36; i++) {         if (i > 35) {           printf( Missing n );           break;         }         if (dp[2][i] == 2) {           if ((i - b) % 2 == 0)             printf( Masha n );           else             printf( Stas n );           break;         }       }     } else {       if (dp[a][b] == 1)         printf( Masha n );       else         printf( Stas n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod(long long int x) {     return (((x) % 1000000007) + 1000000007) % 1000000007;   }   long long int mod1(long long int x, long long int m) {     return (((x) % m) + m) % m;   }   long long int solve() {     string s;     cin >> s;     long long int d = count(s.begin(), s.end(),  D );     long long int l = count(s.begin(), s.end(),  L );     long long int u = count(s.begin(), s.end(),  U );     long long int r = count(s.begin(), s.end(),  R );     if (s.size() % 2 == 0)       cout << (abs(d - u) + abs(l - r)) / 2;     else       cout <<  -1 ;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXn = 1e5 + 100;   const long long INF = 1e9 + 100;   long long l, r = -INF, n, k, a[MAXn], p, ans, dp[MAXn], anss;   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     cin >> a[1];     for (long long i = 2; i < n + 1; ++i) {       cin >> a[i];       r = max(r, abs(a[i] - a[i - 1]));     }     while (l <= r) {       long long p = (l + r) / 2;       long long ans = -1;       for (long long i = 1; i <= n; ++i) {         dp[i] = 1;         for (long long j = 1; j <= i - 1; ++j) {           if (abs(a[i] - a[j]) <= p * abs(i - j)) {             dp[i] = max(dp[i], dp[j] + 1);           }         }         ans = max(ans, dp[i]);       }       if (ans < n - k)         l = p + 1;       else         r = p - 1, anss = p;     }     return cout << anss << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 1e6 + 233;   struct node {     ll x, y;     node(ll x = 0, ll y = 0) : x(x), y(y) {}   };   ll dist(node a, node b) {     ll L = a.x - b.x;     ll R = a.y - b.y;     return L * L + R * R;   }   vector<node> v;   vector<ll> ans;   ll cnt[3][3];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       ll x, y;       scanf( %lld%lld , &x, &y);       v.emplace_back(x, y + N);     }     for (;;) {       for (int i = 0; i < 2; ++i)         for (int j = 0; j < 2; ++j) cnt[i][j] = 0;       for (int i = 0; i < n; ++i) ++cnt[v[i].x & 1][v[i].y & 1];       if (cnt[0][0] + cnt[1][1] && cnt[1][0] + cnt[0][1]) {         for (int i = 0; i < n; ++i)           if ((v[i].x + v[i].y) & 1) ans.push_back(i + 1);         break;       } else if (cnt[0][0] + cnt[0][1] && cnt[1][0] + cnt[1][1]) {         for (int i = 0; i < n; ++i)           if (v[i].x & 1) ans.push_back(i + 1);         break;       } else {         int x, y;         for (int i = 0; i < 2; ++i)           for (int j = 0; j < 2; ++j)             if (cnt[i][j]) {               x = i;               y = j;             }         for (int i = 0; i < n; ++i) {           v[i].x = (v[i].x - x) >> 1;           v[i].y = (v[i].y - y) >> 1;         }       }     }     printf( %d n , ans.size());     for (auto i : ans) printf( %d  , i);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[200005];   long long dp[200005][3];   long long f[200005];   long long g[200005];   const int mod = 998244353;   void dfs(int p, int u) {     for (auto x : v[u]) {       if (x != p) {         dfs(u, x);       }     }     int l = v[u].size() - (p ? 1 : 0);     if (l == 0) {       dp[u][0] = 0;       dp[u][1] = 1;       dp[u][2] = 1;       return;     }     int k = 0;     while (k < v[u].size() && v[u][k] != p) k++;     int cnt = 1;     f[0] = 1;     for (int i = 0; i < v[u].size(); i++) {       int tmp = v[u][i];       if (tmp == p) continue;       f[cnt] = f[cnt - 1] * (dp[tmp][0] + dp[tmp][1]) % mod;       cnt++;     }     cnt = l;     g[l + 1] = 1;     for (int i = v[u].size() - 1; i >= 0; i--) {       int tmp = v[u][i];       if (tmp == p) continue;       g[cnt] = g[cnt + 1] * (dp[tmp][0] + dp[tmp][2]) % mod;       cnt--;     }     for (int i = 1; i <= k; i++) {       dp[u][0] =           (dp[u][0] + f[i - 1] * g[i + 1] % mod * dp[v[u][i - 1]][2]) % mod;     }     dp[u][1] = f[k] * g[k + 1] % mod;     for (int i = k + 1; i <= l; i++) {       dp[u][2] = (dp[u][2] + f[i - 1] * g[i + 1] % mod * dp[v[u][i]][2]) % mod;     }     dp[u][2] = (dp[u][2] + f[l]) % mod;   }   void work() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     dfs(0, 1);     printf( %lld n , (dp[1][0] + dp[1][1]) % mod);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     T = 1;     while (T--) {       work();     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) w = -1;     for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48);     return s * w;   }   inline void print(long long x, int op = 10) {     if (!x) {       putchar( 0 );       if (op) putchar(op);       return;     }     char F[40];     long long tmp = x > 0 ? x : -x;     if (x < 0) putchar( - );     int cnt = 0;     while (tmp > 0) {       F[cnt++] = tmp % 10 +  0 ;       tmp /= 10;     }     while (cnt > 0) putchar(F[--cnt]);     if (op) putchar(op);   }   inline long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a;       b >>= 1;       a *= a;     }     return ans;   }   long long qpow(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) (ans *= a) %= mod;       b >>= 1;       (a *= a) %= mod;     }     return ans % mod;   }   const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},                         {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const int N = 1e6 + 7;   long long n, m;   struct Node {     long long x, y;     int id;     bool operator<(const Node& opt) const { return x - y < opt.x - opt.y; }   } p[N];   long long pre[N], suf[N];   long long ans[N];   int pos[N];   void solve() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) {       p[i].x = read(), p[i].y = read();       p[i].id = i;     }     sort(p + 1, p + 1 + n);     for (int i = 1; i <= n; ++i) pos[p[i].id] = i;     for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + p[i].x;     for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] + p[i].y;     for (int i = 1; i <= n; ++i) {       int id = p[i].id;       long long tmp =           p[i].x * (n - i) + p[i].y * (i - 1) + pre[i - 1] + suf[i + 1];       ans[id] = tmp;     }     while (m--) {       int u = read(), v = read();       long long tmp = min(p[pos[u]].x + p[pos[v]].y, p[pos[u]].y + p[pos[v]].x);       ans[u] -= tmp;       ans[v] -= tmp;     }     for (int i = 1; i <= n; ++i) printf( %lld%c , ans[i],    n [i == n]);   }   int main() {     solve();     return 0;   }