malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct par {     int x, y, label;     par(int _x, int _y, int _label) {       x = _x;       y = _y;       label = _label;     }     par() {}   };   bool operator<(par p1, par p2) {     if (p1.x != p2.x) return p1.x < p2.x;     return p1.y < p2.y;   }   int main() {     int n;     while (cin >> n) {       vector<par> V;       int x, y;       for (int i = 0; i < n; i++) {         cin >> x >> y;         V.push_back(par(x, y, i + 1));       }       sort((V).begin(), (V).end());       vector<int> sol;       for (int i = 0; i < n; i++) {         bool ok = 1;         vector<par> aux;         for (int j = 0; j < n; j++)           if (j != i) aux.push_back(V[j]);         for (int j = 1; j < aux.size(); j++) {           if (aux[j - 1].y > aux[j].x) {             ok = 0;             break;           }         }         if (ok) sol.push_back(V[i].label);       }       sort((sol).begin(), (sol).end());       cout << sol.size() << endl;       for (int i = 0; i < sol.size(); i++) {         if (i == 0)           printf( %d , sol[i]);         else           printf(  %d , sol[i]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline int read() {     int w = 1, s = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (isdigit(ch)) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return w * s;   }   int n, k, fac[1001000], Ifac[1001000], f[1000010], Sum[1010010];   inline long long ksm(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   inline int add(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   inline int A(int a, int b) { return 1ll * fac[a] * Ifac[a - b] % mod; }   inline void Init() {     fac[0] = Ifac[0] = 1;     for (register int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     Ifac[n] = ksm(fac[n], mod - 2);     for (register int i = n - 1; i; --i)       Ifac[i] = 1ll * Ifac[i + 1] * (i + 1) % mod;   }   int main() {     n = read(), k = read();     Init();     for (register int i = k + 1; i <= n; ++i) {       int tmp = 1ll * max(i - k - 1, 0) * fac[i - 2] % mod;       f[i] = add(f[i], tmp);       int l = max(i - k, 1);       f[i] =           add(f[i], 1ll * fac[i - 2] * add(Sum[i - 1], mod - Sum[l - 1]) % mod);       Sum[i] = add(Sum[i - 1], 1ll * f[i] * Ifac[i - 1] % mod);     }     cout << 1ll * Sum[n] * fac[n - 1] % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e5 + 10;   int n, m, k, t;   bool vis[MAXN], ans[MAXN];   int v[MAXN];   set<int> p[MAXN];   priority_queue<pair<int, int> > pq;   int main() {     cin >> n >> m;     memset(vis, false, sizeof(vis));     memset(ans, false, sizeof(ans));     for (int i = 0; i <= 2 * m + 2; i++) v[i] = -1;     for (int i = 1; i <= n; i++) {       cin >> k;       for (int j = 0; j < k; j++) {         cin >> t;         v[t + m] = i;         p[i].insert(t + m);       }       pq.push({-p[i].size(), i});     }     bool flag = true;     while (!pq.empty()) {       int top = pq.top().second;       pq.pop();       if (vis[top]) continue;       if (p[top].empty()) {         flag = false;         break;       }       int x = *p[top].begin();       vis[top] = true;       ans[x] = true;       int y = m + m - x;       if (v[y] != -1 && !vis[v[y]]) {         p[v[y]].erase(y);         pq.push({-p[v[y]].size(), v[y]});       }     }     if (flag) {       cout <<  YES  << endl;       for (int i = m + 1; i < m + 1 + m; i++) {         if (!ans[i])           cout << 0;         else           cout << 1;       }       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int gi() {     int w = 0, q = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && (c !=  - )) c = getchar();     if (c ==  - ) q = 1, c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return q ? -w : w;   }   int n, k;   long long a[500000], d[500000];   int main() {     n = gi(), k = gi();     long long ans = 0, sum = 0;     for (int i = 1; i <= n; ++i) a[i] = gi();     for (int i = 1; i <= n; ++i) d[i] = gi();     for (int i = n; i; --i) {       sum += 1ll * a[i];       if ((i == 1) && (k == 1)) continue;       ans = max(ans, sum - d[i]);     }     if (!k) printf( %I64d n , ans), exit(0);     sum -= d[1];     for (int i = 2; i < n; ++i)       ans = max(ans, sum - a[i] + max(0ll, a[i] - d[i]));     long long mn = 5000000, mn1 = 5000000;     sum = 0;     for (int i = 1; i < n; ++i) {       sum += 1ll * a[i];       if (d[i] < mn)         mn1 = mn, mn = d[i];       else if (d[i] == mn)         mn1 = d[i];       else         mn1 = min(mn1, d[i]);     }     ans = max(ans, sum + 1ll * (max(0ll, a[n] - d[n]) - mn));     if (k == 1)       ans = max(ans, sum + 1ll * (a[n] - mn - mn1));     else       ans = max(ans, sum + 1ll * (a[n] - mn));     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> b[5001];     for (int i = 0; i < n; i++) {       string s;       int a, b1, c;       cin >> s >> a >> b1;       if (s[0] ==  M )         c = 0;       else         c = 1;       b[i].push_back(c);       b[i].push_back(a);       b[i].push_back(b1);     }     int ans = 0;     for (int i = 1; i <= 366; i++) {       int m[2] = {};       for (int j = 0; j < n; j++) {         if (b[j][1] <= i && b[j][2] >= i) m[b[j][0]]++;       }       ans = max(ans, 2 * min(m[0], m[1]));     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, ar[1000005], sum, t, ar2[1000005];   vector<int> ans;   vector<pair<int, char> > res;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> ar[i];     cin >> m;     for (long long int i = 1; i <= m; i++) cin >> ar2[i];     long long int top = 0;     long long int l = 1;     for (long long int i = 1; i <= n + 1; i++) {       if (l > m) return cout <<  NO , 0;       if (top < ar2[l]) {         top += ar[i];         continue;       }       if (top > ar2[l]) return cout <<  NO , 0;       ans.push_back(i - 1);       l++;       top = ar[i];     }     if (top || l <= m) return cout <<  NO , 0;     cout <<   n ;     int last = 1;     long long int cnt = 0;     for (int h = 0; h < ans.size(); h++) {       long long int y = ans[h];       long long int mk = 0, mn = INT_MAX;       for (int i = last; i <= y; i++) {         mk = max(mk, ar[i]);         mn = min(mn, ar[i]);       }       if (last == y) {         last++;         cnt = y - h - 1;         continue;       }       if (mn == mk) {         return cout <<  NO , 0;       }       long long int mki = 0;       char mki2;       long long int z = y - last + 1;       for (long long int i = last; i <= y; i++) {         if (ar[i] != mk) continue;         if (i != last && ar[i - 1] != ar[i]) {           mki = i;           mki2 =  L ;           res.push_back({mki - cnt, mki2});           mki--;           break;         }         if (i != y && ar[i] != ar[i + 1]) {           mki = i;           mki2 =  R ;           res.push_back({mki - cnt, mki2});           break;         }       }       z--;       z--;       while (mki > last) {         res.push_back({mki - cnt,  L });         mki--;         z--;       }       while (z--) {         res.push_back({mki - cnt,  R });       }       cnt = y - h - 1;       last = y + 1;     }     cout <<  YES           <<   n ;     for (int i = 0; i < res.size(); i++)       cout << res[i].first <<     << res[i].second <<   n ;   }
#include <bits/stdc++.h>   const int N = 100010;   const long long INF = 1ll << 60;   const int inf = 0x3f3f3f3f;   int t;   int n, m, k;   int a[N];   int b[N];   std::vector<int> row[N];   std::vector<int> col[N];   int cur;   int r, c;   long long ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; ++i) {       scanf( %d%d , &a[i], &b[i]);       row[a[i]].push_back(b[i]);       col[b[i]].push_back(a[i]);     }     for (int i = 1; i <= n; ++i) {       row[i].push_back(m + 1);       row[i].push_back(0);       std::sort(row[i].begin(), row[i].end());     }     for (int j = 1; j <= m; ++j) {       col[j].push_back(n + 1);       col[j].push_back(0);       std::sort(col[j].begin(), col[j].end());     }     r = 1;     c = 1;     ans = 1ll;     int r_max = inf;     int c_max = inf;     int r_min = 2;     int c_min = -inf;     for (int i = 1; i <= 2 * (n + m) + 1; ++i) {       if (!cur) {         auto x = std::lower_bound(row[r].begin(), row[r].end(), c);         int c_nxt = (*x) - 1;         c_nxt = std::min(c_nxt, c_max);         assert(c_nxt >= c);         ans += c_nxt - c;         if (c == c_nxt && i != 1) {           break;         }         c = c_nxt;         c_max = c - 1;       } else if (cur == 1) {         auto x = std::lower_bound(col[c].begin(), col[c].end(), r);         int r_nxt = (*x) - 1;         r_nxt = std::min(r_nxt, r_max);         assert(r_nxt >= r);         ans += r_nxt - r;         if (r == r_nxt && i != 1) {           break;         }         r = r_nxt;         r_max = r - 1;       } else if (cur == 2) {         auto x = std::lower_bound(row[r].begin(), row[r].end(), c);         --x;         int c_nxt = (*x) + 1;         c_nxt = std::max(c_nxt, c_min);         assert(c_nxt <= c);         ans += c - c_nxt;         if (c == c_nxt && i != 1) {           break;         }         c = c_nxt;         c_min = c + 1;       } else if (cur == 3) {         auto x = std::lower_bound(col[c].begin(), col[c].end(), r);         --x;         int r_nxt = (*x) + 1;         r_nxt = std::max(r_nxt, r_min);         assert(r_nxt <= r);         ans += r - r_nxt;         if (r == r_nxt && i != 1) {           break;         }         r = r_nxt;         r_min = r + 1;       }       cur = (cur + 1) % 4;     }     if (ans + k != 1ll * n * m) {       printf( NO n );     } else {       printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   int ans[maxn];   int lowbit(int x) { return x & -x; }   bool is_two(int x) { return x == lowbit(x); }   bool dfs(int n, int k, int id) {     if (k == 1) {       printf( %d %d %d n , n, k, id);       if (is_two(n)) {         return false;       }       ans[id] = max(id - 2, 0);       for (int i = 2; i <= n; ++i) {         ans[id + i - 1] = id + i / 2 - 1;       }       return true;     } else if (k == 0) {       if (is_two(n)) {         ans[1] = 0;         for (int i = 2; i <= n; ++i) {           ans[i] = i / 2;         }         return true;       } else         return false;     } else {       while (k >= 2) {         ans[id] = max(id - 2, 0);         ans[id + 1] = id;         n -= 2;         k -= 1;         id += 2;       }       return dfs(n, k, id);     }   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     int lim = max(0, (n - 3) / 2);     if (n % 2 == 0 || k > lim || (n == 9 && k == 2) ||         (!is_two(n + 1) && k == 0) || (is_two(n + 1) && k == 1)) {       printf( NO n );     } else {       int id = 1;       while (k >= 2) {         ans[id] = max(id - 2, 0);         ans[id + 1] = id;         n -= 2;         k -= 1;         id += 2;       }       ans[id] = max(id - 2, 0);       for (int i = 2; i <= n - 2; ++i) {         ans[id + i - 1] = id + i / 2 - 1;       }       if (is_two(n + 1)) {         if (k == 0)           ans[id + n - 2] = id + (n - 1) / 2 - 1,                        ans[id + n - 1] = id + n / 2 - 1;         else           ans[id + n - 2] = 2, ans[id + n - 1] = 2;       } else {         if (k == 0)           return printf( NO n ), 0;         else           ans[id + n - 2] = id + (n - 1) / 2 - 1,                        ans[id + n - 1] = id + n / 2 - 1;       }       printf( YES n );       for (int i = 1; i < id + n - 1; ++i) {         printf( %d  , ans[i]);       }       printf( %d n , ans[id + n - 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1, inf = 1e18;   vector<pair<long long, long long> > a, b;   vector<pair<pair<long long, long long>, long long> > z;   long long add[4 * N], t[4 * N];   void push(long long v, long long l, long long r) {     t[v] += add[v];     if (l != r - 1) {       add[2 * v] += add[v];       add[2 * v + 1] += add[v];     }     add[v] = 0;   }   void update(long long v, long long l, long long r, long long vl, long long vr,               long long val) {     push(v, l, r);     if (l >= vr || vl >= r) return;     if (l >= vl && r <= vr) {       add[v] += val;       push(v, l, r);       return;     }     long long m = (l + r) / 2;     update(2 * v, l, m, vl, vr, val);     update(2 * v + 1, m, r, vl, vr, val);     t[v] = max(t[2 * v + 1], t[2 * v]);   }   long long get(long long v, long long l, long long r, long long vl,                 long long vr) {     push(v, l, r);     if (l >= vr || vl >= r) return -inf;     if (l >= vl && r <= vr) {       return t[v];     }     long long m = (l + r) / 2;     return max(get(2 * v, l, m, vl, vr), get(2 * v + 1, m, r, vl, vr));   }   void fuckyou(long long v, long long l, long long r, long long pos,                long long val) {     if (l > pos || r <= pos) return;     if (l == r - 1) {       t[v] = max(t[v], val);       return;     }     long long m = (l + r) / 2;     fuckyou(2 * v, l, m, pos, val);     fuckyou(2 * v + 1, m, r, pos, val);     t[v] = max(t[2 * v], t[2 * v + 1]);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (long long i = 0; i < 4 * N; i++) t[i] = -inf;     long long n, m, p, ans = -inf;     cin >> n >> m >> p;     a.resize(n);     b.resize(m);     z.resize(p);     for (long long i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     for (long long i = 0; i < m; i++) {       cin >> b[i].first >> b[i].second;       fuckyou(1, 0, N, b[i].first, -b[i].second);     }     for (long long i = 0; i < p; i++) {       cin >> z[i].first.first >> z[i].first.second >> z[i].second;     }     sort((z).begin(), (z).end());     sort((a).begin(), (a).end());     cout << endl;     long long j = 0;     for (long long i = 0; i < n; i++) {       while (j < z.size() && a[i].first > z[j].first.first) {         update(1, 0, N, z[j].first.second + 1, N, z[j].second);         j++;       }       ans = max(ans, -a[i].second + get(1, 0, N, 0, N));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   string s;   string rev(string s) {     string p;     for (auto i : s) p.insert(0, 1, i);     return p;   }   int main() {     cin >> s;     int n = s.size();     for (int i = 0; i <= s.size(); i++)       for (int j = 0; j < 26; j++) {         string p = s;         p.insert(i, 1, j +  a );         if (p == rev(p)) return cout << p, 0;       }     cout <<  NA ;   }
#include <bits/stdc++.h>   struct PP {     int l, r, sum, lv, rv, cover;     int mid() { return (l + r) >> 1; }     void doit() { sum = lv = rv = cover ? 0 : dis(); }     int dis() { return r - l; }   } q[100005 * 3];   int max(int a, int b) { return a > b ? a : b; }   void Build(int l, int r, int x) {     q[x].l = l;     q[x].r = r;     q[x].sum = q[x].lv = q[x].rv = q[x].dis();     q[x].cover = -1;     if (l == r - 1) return;     int mid = q[x].mid();     Build(l, mid, (x << 1));     Build(mid, r, ((x << 1) | 1));   }   void pushdown(int x) {     q[(x << 1)].cover = q[((x << 1) | 1)].cover = q[x].cover;     q[(x << 1)].doit();     q[((x << 1) | 1)].doit();     q[x].cover = -1;   }   void Pushup(int x) {     q[x].sum = max(q[(x << 1)].rv + q[((x << 1) | 1)].lv,                    max(q[(x << 1)].sum, q[((x << 1) | 1)].sum));     q[x].lv = q[(x << 1)].lv;     q[x].rv = q[((x << 1) | 1)].rv;     if (q[(x << 1)].sum == q[(x << 1)].dis()) q[x].lv += q[((x << 1) | 1)].lv;     if (q[((x << 1) | 1)].sum == q[((x << 1) | 1)].dis())       q[x].rv += q[(x << 1)].rv;   }   void update(int l, int r, int c, int x) {     if (l <= q[x].l && q[x].r <= r) {       q[x].cover = c;       q[x].doit();       return;     }     if (q[x].cover != -1) pushdown(x);     int mid = q[x].mid();     if (l < mid) update(l, r, c, (x << 1));     if (mid < r) update(l, r, c, ((x << 1) | 1));     Pushup(x);   }   int query(int w, int x) {     if (q[x].sum >= w && q[x].cover == 0) return q[x].l;     if (q[x].cover != -1) pushdown(x);     if (q[(x << 1)].sum >= w)       return query(w, (x << 1));     else if (q[(x << 1)].rv + q[((x << 1) | 1)].lv >= w)       return q[(x << 1)].r - q[(x << 1)].rv;     else if (q[((x << 1) | 1)].sum >= w)       return query(w, ((x << 1) | 1));     else       return -1;   }   struct SS {     int l, r;   } cnt[100005];   int main() {     int i, m, op, a;     int L, B, F;     while (scanf( %d%d%d , &L, &B, &F) != EOF) {       scanf( %d , &m);       Build(0, B + L + F, 1);       for (i = 1; i <= m; i++) {         scanf( %d%d , &op, &a);         if (op == 1) {           int pos = query(B + a + F, 1);           if (pos == -1) {             printf( -1 n );             continue;           }           printf( %d n , pos);           update(pos + B, pos + B + a, 1, 1);           cnt[i].l = pos + B;           cnt[i].r = pos + B + a;         } else           update(cnt[a].l, cnt[a].r, 0, 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 200000;   int n, m, t, tin[mxN];   vector<int> adj[mxN], e[mxN];   vector<array<int, 3>> ans;   void dfs(int u, int p = -1) {     tin[u] = ++t;     if (p ^ -1) e[u].push_back(p);     for (int v : adj[u]) {       if (v == p) continue;       if (!tin[v]) {         dfs(v, u);       } else if (tin[v] < tin[u]) {         e[u].push_back(v);       }     }     while (e[u].size() >= 2) {       int v = e[u].back();       e[u].pop_back();       int w = e[u].back();       e[u].pop_back();       ans.push_back({v, u, w});     }     if (e[u].size() == 1 && p ^ -1) e[p].push_back(u);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v, --u, --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < n; ++i)       if (!tin[i]) dfs(i);     cout << ans.size() <<   n ;     for (array<int, 3> x : ans)       cout << x[0] + 1 <<     << x[1] + 1 <<     << x[2] + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     if (n == 47 || n == 74 || n == 477 || n == 477)       cout <<  YES ;     else if (n % 4 == 0 || n % 7 == 0 || n % 47 == 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, arr[105];     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int ans = arr[0];     for (int i = 1; i < n; i++) {       ans = gcd(ans, arr[i]);     }     cout << ans * n <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, r;     cin >> n >> m >> r;     vector<int> v(n);     vector<int> v1(m);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       cin >> v1[i];     }     sort(v.begin(), v.end());     sort(v1.rbegin(), v1.rend());     if (v[0] > v1[0]) {       cout << r << endl;       return 0;     }     int cnt = 0;     cnt += r % v[0];     cnt += (r / v[0]) * v1[0];     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   int ured() {     int re = 0, ch;     do {       ch = getchar();     } while ( 9  < ch || ch <  0 );     do {       re = re * 10 + (ch ^  0 );     } while ( 0  <= (ch = getchar()) && ch <=  9 );     return re;   }   void uwit(int da) {     int cn = 0, ch[21];     do {       ch[++cn] = da - da / 10 * 10;     } while (da /= 10);     do {       putchar( 0  ^ ch[cn]);     } while (--cn);   }   inline void dmax(int& fr, int to) {     if (fr < to) {       fr = to;     }   }   inline void dmin(int& fr, int to) {     if (fr > to) {       fr = to;     }   }   inline int mabs(int da) { return da >= 0 ? da : -da; }   const int _maxn = 200011, _mods = 1000000007;   int t, n, m, pdif;   char s[_maxn];   int main() {     t = ured();     while (t--) {       n = ured();       m = ured();       if (m >= 2 * n) {         uwit((m + 1) / 2 - 1);       } else {         uwit(m - n);       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, res = 1;   long long a[100005];   long long b[100005];   long long d = 1, ans;   int main() {     cin >> n >> k;     for (int i = 0; i < k; i++) d *= 10;     for (int i = 0; i < n / k; i++) cin >> a[i];     for (int i = 0; i < n / k; i++) cin >> b[i];     for (int i = 0; i < n / k; i++) {       ans = (d - 1) / a[i] + 1;       if (b[i] == 0)         ans -= ((d / 10) - 1) / a[i] + 1;       else         ans -=             ((b[i] + 1) * (d / 10) - 1) / a[i] - ((b[i]) * (d / 10) - 1) / a[i];       res = (res * ans) % (1000000007);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const long long _ = 1e18;   signed main() {     long long a = read(), q = (_ % a * 9 % a * 9 % a + 1) % a;     printf( %lld %lld n , a - q + 1, a - q + _);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first < b.first;     else       return (a.second > b.second);   }   bool cmp(pair<string, int> x, pair<string, int> y) {     return (x.second < y.second);   }   long long int bigmod(long long int a, long long int b, long long int m) {     if (b == 0) return 1 % m;     long long int x = bigmod(a, b / 2, m);     x = (x * x) % m;     if (b % 2 == 1) x = (x * a) % m;     return x;   }   void NA() {     printf( NO n );     exit(0);   }   void YA() {     printf( YES n );     exit(0);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long int mx = 0LL, mn = 0LL;     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       mx = (mx + bigmod(2, i, 1000000007) * a[i]) % 1000000007;       mn = (mn + bigmod(2, n - i - 1, 1000000007) * a[i]) % 1000000007;     }     cout << (mx - mn + 1000000007) % 1000000007 << endl;   }