malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   clock_t timeStart, timeFinish;   void timeBegin() { timeStart = clock(); }   void timeEnd() { timeFinish = clock(); }   void timeDuration() {     double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);     cout <<  Time taken by program is :   << fixed << time_taken          << setprecision(5);     cout <<   sec   << endl;   }   long long int n, h, a[105];   bool fun(long long int x) {     long long int val = 0;     for (int i = 0; i < n - 1; i++) {       val += min(a[i + 1] - a[i], x);     }     val += x;     if (val >= h) {       return true;     }     return false;   }   void solve() {     cin >> n >> h;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long int l = 1, r = 1000000000000000000;     long long int ans = r;     while (l <= r) {       long long int mid = l + (r - l) / 2;       if (fun(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     for (int i = 0; i < t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 1e9 + 7;   const int N = 2e5 + 7;   const int M = 1e6 + 7;   long long a[N], b[N];   long long dp[N][2];   signed main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i > 1) b[i - 1] = abs(a[i] - a[i - 1]);     }     for (int i = 1; i <= n; i++) {       dp[i][0] = max(dp[i - 1][1] + b[i], b[i]);       dp[i][1] = max(dp[i - 1][0] - b[i], 0ll);     }     long long ans = 0;     for (int i = 1; i < n; i++) ans = max(ans, max(dp[i][0], dp[i][1]));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int INF = 0x3f3f3f3f;   int n, w[N], h[N];   int maxx;   int sum, sum1, ans = INF;   inline void fuck(int id, int tot) {     sum1 = sum;     priority_queue<int> q;     int tall;     if (tot == 1)       tall = w[id], sum1 = sum1 - w[id] + h[id];     else       tall = h[id];     for (int i = 1; i <= n; ++i) {       if (i == id) continue;       if (w[i] > tall && h[i] > tall) return;       if (w[i] > tall || h[i] > tall) {         if (h[i] > tall) sum1 = sum1 - w[i] + h[i], tot++;       } else if (w[i] <= tall && h[i] <= tall) {         q.push(w[i] - h[i]);       }     }     if (tot > n / 2) return;     while (!q.empty()) {       tot++;       if (tot > n / 2) break;       int now = q.top();       q.pop();       if (now <= 0) break;       sum1 -= now;     }     ans = min(ans, sum1 * tall);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &w[i], &h[i]), sum += w[i];     for (int i = 1; i <= n; ++i) {       fuck(i, 0);       fuck(i, 1);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 5;   struct Node {     long long ls, rs, val, key, cnt, tag, add;   };   Node t[maxn];   long long pol;   void newnode(long long vv) {     t[++pol].val = vv;     t[pol].cnt = 0;     t[pol].key = rand();     t[pol].ls = t[pol].rs = 0;     t[pol].tag = t[pol].add = 0;     return;   }   void lazy1(long long p, long long k) {     t[p].val += k;     return;   }   void lazy2(long long p, long long k) {     t[p].cnt += k;     return;   }   void pushdown(long long p) {     t[t[p].ls].tag += t[p].tag;     t[t[p].rs].tag += t[p].tag;     lazy1(t[p].ls, t[p].tag);     lazy1(t[p].rs, t[p].tag);     t[p].tag = 0;     t[t[p].ls].add += t[p].add;     t[t[p].rs].add += t[p].add;     lazy2(t[p].ls, t[p].add);     lazy2(t[p].rs, t[p].add);     t[p].add = 0;     return;   }   long long merge(long long x, long long y) {     if (!x || !y) return x + y;     if (t[x].key < t[y].key) {       pushdown(x);       t[x].rs = merge(t[x].rs, y);       return x;     } else {       pushdown(y);       t[y].ls = merge(x, t[y].ls);       return y;     }     return 0;   }   void split(long long now, long long &rx, long long &ry, long long k) {     if (!now) {       rx = ry = 0;       return;     }     pushdown(now);     if (t[now].val <= k) {       rx = now;       split(t[now].rs, t[rx].rs, ry, k);     } else {       ry = now;       split(t[now].ls, rx, t[ry].ls, k);     }     return;   }   long long rt, rx, ry, rz;   void ins(long long nd) {     split(rt, rx, rz, t[nd].val);     rt = merge(merge(rx, nd), rz);     return;   }   void dfs(long long now, long long cc) {     if (!now) return;     pushdown(now);     t[now].val -= cc;     t[now].cnt++;     dfs(t[now].ls, cc);     dfs(t[now].rs, cc);     t[now].ls = t[now].rs = 0;     ins(now);     return;   }   void out(long long now) {     if (!now) return;     pushdown(now);     out(t[now].ls);     cout << t[now].val <<    ;     out(t[now].rs);     return;   }   void costv(long long cc) {     split(rt, rx, ry, cc - 1);     split(ry, ry, rz, 2 * cc);     t[rz].tag -= cc;     lazy1(rz, -cc);     t[rz].add++;     lazy2(rz, 1);     rt = merge(rx, rz);     dfs(ry, cc);     return;   }   struct tshirts {     long long c, q;     bool friend operator<(tshirts t1, tshirts t2) {       return t1.q == t2.q ? t1.c < t2.c : t1.q > t2.q;     }   };   tshirts st[maxn];   long long n, k;   long long v[maxn];   void dfsans(long long now) {     if (!now) return;     pushdown(now);     dfsans(t[now].ls);     dfsans(t[now].rs);     return;   }   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &st[i].c, &st[i].q);     }     sort(st + 1, st + n + 1);     scanf( %lld , &k);     for (int i = 1; i <= k; i++) {       scanf( %lld , &v[i]);       newnode(v[i]);       ins(i);     }     for (int i = 1; i <= n; i++) {       costv(st[i].c);     }     dfsans(rt);     for (int i = 1; i <= k; i++) {       printf( %lld  , t[i].cnt);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mas[1010];   unordered_map<long long, int> sootv;   long long num[100100];   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   int main() {     int n;     long long k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> mas[i];     }     if (k == 1) {       cout << 1 << endl;       int minidx = 1;       for (int i = 0; i < n; i++) {         if (mas[i] < mas[minidx]) minidx = i;       }       cout << minidx + 1;       return 0;     }     vector<long long> divs;     vector<long long> rdivs;     for (long long i = 1; i * i <= k; i++) {       if (k % i == 0) {         divs.push_back(i);         if (i * i != k) {           rdivs.push_back(k / i);         }       }     }     for (auto it = rdivs.rbegin(); it != rdivs.rend(); it++) {       divs.push_back(*it);     }     int cnt = 1;     sootv.rehash((int)(divs).size() * 5);     for (int i = 0; i < (int)(divs).size(); i++) {       sootv.emplace(divs[i], cnt);       num[cnt] = divs[i];       cnt++;     }     int oo = 1e9;     vector<vector<int> > dp(n + 3);     vector<vector<long long> > sum(n + 3);     vector<vector<int> > lst(n + 3);     for (int i = 0; i < (int)(dp).size(); i++) {       dp[i].resize(cnt + 3);       lst[i].resize(cnt + 3);       sum[i].resize(cnt + 3);       for (int j = 0; j < (int)(dp[i]).size(); j++) {         dp[i][j] = oo;       }       for (int j = 0; j < (int)(lst[i]).size(); j++) {         lst[i][j] = -1;       }       for (int j = 0; j < (int)(sum[i]).size(); j++) {         sum[i][j] = (long long)oo * (long long)oo;       }     }     dp[0][sootv[k]] = 0;     sum[0][sootv[k]] = 0;     int res = oo;     for (int i = 0; i < n; i++) {       for (int divi = 1; divi < cnt; divi++) {         if (dp[i][divi] >= oo) continue;         if (dp[i + 1][divi] > dp[i][divi] ||             dp[i + 1][divi] == dp[i][divi] && sum[i + 1][divi] > sum[i][divi]) {           lst[i + 1][divi] = divi;           dp[i + 1][divi] = dp[i][divi];           sum[i + 1][divi] = sum[i][divi];         }         long long nxt = num[divi] / gcd(num[divi], mas[i]);         if (nxt == num[divi]) continue;         int idx = sootv[nxt];         if (dp[i + 1][idx] > dp[i][divi] + 1 ||             dp[i + 1][idx] == dp[i][divi] + 1 &&                 sum[i + 1][idx] > sum[i][divi] + mas[i]) {           lst[i + 1][idx] = divi;           dp[i + 1][idx] = dp[i][divi] + 1;           sum[i + 1][idx] = sum[i][divi] + mas[i];         }       }     }     res = dp[n][sootv[1]];     if (res == oo) {       res = -1;       cout << res << endl;       return 0;     }     cout << res << endl;     vector<int> path;     int cur = sootv[1];     for (int i = n; i >= 1; i--) {       int l = lst[i][cur];       if (l != cur) {         path.push_back(i);       }       cur = l;       if ((int)(path).size() == res) break;     }     for (int i = (int)(path).size() - 1; i >= 0; i--) printf( %d  , path[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   int aa[N];   map<int, int> mp;   set<int> s;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> aa[i];     for (int i = 0; i < n; i++) {       mp[aa[i]]++;       if (mp[aa[i]] == 1)         s.insert(aa[i]);       else         s.erase(aa[i]);       int j = i - k;       if (j >= 0) {         mp[aa[j]]--;         if (mp[aa[j]] == 1)           s.insert(aa[j]);         else           s.erase(aa[j]);       }       if (i >= k - 1)         if (!s.empty())           cout << *--s.end() <<   n ;         else           cout <<  Nothing n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   class DSU {    public:     vector<int> parent;     vector<int> sizes;     int noOfComponenents;     DSU(int N) {       parent.resize(N);       sizes.resize(N);       noOfComponenents = N;       for (int i = 0; i < N; ++i) {         parent[i] = i;         sizes[i] = 1;       }     }     int find(int x) {       if (parent[x] != x) parent[x] = find(parent[x]);       return parent[x];     }     void unify(int x, int y) {       x = find(x);       y = find(y);       if (isConnected(x, y)) {         return;       }       --noOfComponenents;       sizes[y] += sizes[x];       parent[x] = y;     }     bool isConnected(int p, int q) { return find(p) == find(q); }     int componentSize(int p) { return sizes[p]; }   };   void solve() {     int n;     cin >> n;     string s, t;     cin >> s >> t;     DSU dsu(20);     for (int i = 0; i < n; ++i) {       if (s[i] == t[i]) {         continue;       }       if (s[i] > t[i]) {         cout << -1 <<   n ;         return;       }       dsu.unify(s[i] -  a , t[i] -  a );     }     cout << 20 - dsu.noOfComponenents <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C(long long n, long long m) {     long long res = 1;     for (long long i = n; i > n - m; i--) res *= i;     for (long long i = m; i >= 1; i--) res /= i;     return res;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     long long n, k, res = 1;     cin >> n >> k;     if (k >= 2) res += C(n, 2);     if (k >= 3) res += C(n, 3) * 2;     if (k >= 4) res += C(n, 4) * 9;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int M = 205;   long long n, m, k, cnt, ans;   long long g[N], h[N], dp[N][M];   struct redpocket {     long long s, t, d, w;     bool operator<(const redpocket &x) const {       if (w == x.w) return d < x.d;       return w < x.w;     }   } a[N];   priority_queue<redpocket> q;   bool cmp(redpocket x, redpocket y) { return x.s < y.s; }   signed main() {     scanf( %lld %lld %lld , &n, &m, &k);     for (long long i = 1; i <= k; i++)       scanf( %lld %lld %lld %lld , &a[i].s, &a[i].t, &a[i].d, &a[i].w);     sort(a + 1, a + k + 1, cmp);     g[0] = 1;     cnt = 1;     for (long long i = 1; i <= n; i++) {       while (i >= a[cnt].s && cnt <= k) q.push(a[cnt++]);       if (q.empty())         g[i] = i + 1;       else {         if (q.top().t < i) {           i--;           q.pop();           continue;         }         g[i] = q.top().d + 1;         h[i] = q.top().w;       }     }     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (long long i = 0; i <= n; i++) {       for (long long j = 0; j <= m; j++) {         dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);         dp[g[i]][j] = min(dp[g[i]][j], dp[i][j] + h[i]);       }     }     ans = 0x3f3f3f3f3f3f3f3f;     for (long long i = 0; i <= m; i++) ans = min(ans, dp[n + 1][i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void PT(long long a);   void PT1(long long a);   const long long M = 2010, mod = 1e9 + 7;   long long n, m, x, y, a, b, dp[M][M], mp[M][M], mp1[M][M];   vector<string> v;   void bfs(long long r, long long c, long long l, long long ri) {     queue<pair<long long, long long>> q;     q.push({r, c});     mp[r][c] = l;     mp1[r][c] = ri;     while (!q.empty()) {       r = (q.front()).first;       c = (q.front()).second;       q.pop();       l = mp[r][c];       ri = mp1[r][c];       if (l <= a && ri <= b) dp[r][c] = 1;       if (c - 1 >= 0 && v[r][c - 1] !=  * ) {         if (l + 1 <= a && ri <= b &&             (mp[r][c - 1] > l + 1 || mp1[r][c - 1] > ri)) {           q.push({r, c - 1});           mp[r][c - 1] = l + 1;           mp1[r][c - 1] = ri;         }       }       if (c + 1 < m && v[r][c + 1] !=  * ) {         if (l <= a && ri + 1 <= b &&             (mp[r][c + 1] > l || mp1[r][c + 1] > ri + 1)) {           q.push({r, c + 1});           mp[r][c + 1] = l;           mp1[r][c + 1] = ri + 1;         }       }       if (r - 1 >= 0 && v[r - 1][c] !=  * ) {         if (l <= a && ri <= b && (mp[r - 1][c] > l || mp1[r - 1][c] > ri)) {           q.push({r - 1, c});           mp[r - 1][c] = l;           mp1[r - 1][c] = ri;         }       }       if (r + 1 < n && v[r + 1][c] !=  * ) {         if (l <= a && ri <= b && (mp[r + 1][c] > l || mp1[r + 1][c] > ri)) {           q.push({r + 1, c});           mp[r + 1][c] = l;           mp1[r + 1][c] = ri;         }       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     {       cin >> n >> m >> x >> y >> a >> b;       for (long long i = 0; i < n; i++) {         string s;         cin >> s;         v.push_back(s);       }       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           mp[i][j] = INT_MAX;           mp1[i][j] = INT_MAX;         }       }       bfs(x - 1, y - 1, 0, 0);       long long ans = 0;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           if (dp[i][j] == 1) ans++;         }       }       cout << ans;     }     return 0;   }   void PT(long long a) { cout << a <<   n ; }   void PT1(long long a) { cout << a <<    ; }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int i, j, d, m, n, a[100000];     while (cin >> n) {       for (i = 1; i <= n; i++) {         cin >> a[i];       }       i = 1;       j = n;       int A = a[i], B = a[j];       int ca = 0, cb = 0;       while (1) {         if (A > B) {           B += a[--j];           cb++;         } else if (B >= A) {           A += a[++i];           ca++;         }         if (i > j) break;       }       cout << ca <<     << cb << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<long long> sc(n);     for (typeof(n) i = (0); i < (n); i++) cin >> sc[i];     int m;     cin >> m;     for (typeof(m) i = (0); i < (m); i++) {       long long w, h;       cin >> w >> h;       long long b = max(sc[0], sc[w - 1]);       sc[0] = max(sc[0], b + h);       cout << b << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wformat    template <typename T>   void printContainer(T& a) {     auto it = a.begin();     cout <<  {  << *(it++);     for (; it != a.end(); ++it) cout <<  ,   << (*it);     cout <<  } n ;   }   map<long long, int> A1, A2;   int sol;   long long solarea;   void dfs1(long long area, int opsSoFar) {     A1[area] = opsSoFar;     if (area % 3 == 0) {       if (!A1.count(area / 3 * 2)) {         dfs1(area / 3 * 2, opsSoFar + 1);       }     }     if (area % 2 == 0) {       if (!A1.count(area / 2)) dfs1(area / 2, opsSoFar + 1);     }   }   void dfs2(long long area, int opsSoFar) {     A2[area] = opsSoFar;     if (A1.count(area)) {       if (opsSoFar + A1[area] < sol) {         sol = opsSoFar + A1[area];         solarea = area;       }       return;     }     if (area % 3 == 0) {       if (!A2.count(area / 3 * 2)) {         dfs2(area / 3 * 2, opsSoFar + 1);       }     }     if (area % 2 == 0) {       if (!A2.count(area / 2)) dfs2(area / 2, opsSoFar + 1);     }   }   int threeFactors(long long num) {     int cnt = 0;     while (num % 3 == 0) num /= 3, cnt++;     return cnt;   }   int main() {     long long a1, b1, a2, b2;     cin >> a1 >> b1 >> a2 >> b2;     long long S1 = a1 * b1, S2 = a2 * b2;     dfs1(S1, 0);     sol = 1e9;     dfs2(S2, 0);     if (sol == 1e9) {       cout <<  -1  << endl;       return 0;     }     int T = 0, D = 0;     cout << sol << endl;     T = threeFactors(S1) - threeFactors(solarea);     long long tmp = S1;     for (int i = 0; i < (int)(T); ++i) tmp = (tmp / 3 * 2);     while (tmp != solarea) ++D, tmp /= 2;     while (a1 % 3 == 0 && T > 0) a1 = (a1 / 3 * 2), --T;     while (b1 % 3 == 0 && T > 0) b1 = (b1 / 3 * 2), --T;     while (a1 % 2 == 0 && D > 0) a1 = (a1 / 2), --D;     while (b1 % 2 == 0 && D > 0) b1 = (b1 / 2), --D;     cout << a1 <<     << b1 << endl;     T = 0, D = 0;     T = threeFactors(S2) - threeFactors(solarea);     tmp = S2;     for (int i = 0; i < (int)(T); ++i) tmp = (tmp / 3 * 2);     while (tmp != solarea) ++D, tmp /= 2;     while (a2 % 3 == 0 && T > 0) a2 = (a2 / 3 * 2), --T;     while (b2 % 3 == 0 && T > 0) b2 = (b2 / 3 * 2), --T;     while (a2 % 2 == 0 && D > 0) a2 = (a2 / 2), --D;     while (b2 % 2 == 0 && D > 0) b2 = (b2 / 2), --D;     cout << a2 <<     << b2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 17;   int l1[N], r1[N], a[N], use[N];   map<int, bool> mt;   void dfs(int v, int l, int r) {     if (a[v] > l && a[v] < r) mt[a[v]] = 1;     if (l1[v] != -1) dfs(l1[v], l, min(r, a[v]));     if (r1[v] != -1) dfs(r1[v], max(l, a[v]), r);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> l1[i] >> r1[i];       if (l1[i] != -1) use[l1[i]] = 1;       if (r1[i] != -1) use[r1[i]] = 1;     }     for (int i = 1; i <= n; i++)       if (use[i] == 0) dfs(i, -1, 1e9 + 1);     int ans = 0;     for (int i = 1; i <= n; i++)       if (mt[a[i]] == 0) ans++;     cout << ans << endl;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n;   int ar[100005];   int main() {     scanf( %d , &n);     if (n == 2) {       printf( 2 1 );       return 0;     }     for (int i = 1; i <= n; i++) ar[i] = i;     for (int i = 1; i <= n; i++) {       for (int j = i + i; j <= n; j += i) {         if (j % i == 0 && ar[j] % i == 0) swap(ar[i], ar[j]);       }     }     for (int i = 1; i <= n; i++) printf( %d  , ar[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double error = 1e-15;   const double pi = 2 * acos(0);   const int maxn = (int)1e5 + 10;   const int mod = (int)1e9;   int dx[] = {0, -1, 0, +1, -1, -1, +1, +1};   int dy[] = {-1, 0, +1, 0, -1, +1, +1, -1};   long A[205][200], B[200];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     long i, j, n, m;     cin >> n;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) {         cin >> A[i][j];         if (A[i][j] == 1) {           B[i] = 1;         } else if (A[i][j] == 2) {           B[j] = 1;         } else if (A[i][j] == 3) {           B[i] = 1;           B[j] = 1;         }       }     m = 0;     for (i = 1; i <= n; i++)       if (B[i] == 0) {         m++;         v.push_back(i);       }     cout << m << endl;     for (i = 0; i < m; i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 1 << endl;     } else if (n % 2 == 0) {       cout << n / 2 << endl;     } else if (n % 2 != 0) {       cout << n / 2 + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int n, k;   long long f[100009], g[100009];   vector<int> p;   string s1, s2;   int main() {     cin >> s1 >> s2 >> k;     int i;     n = s1.size();     p.clear();     for (i = 1; i <= n; ++i) {       if (s1 == s2) p.push_back(i - 1);       s1.push_back(s1[0]);       s1.erase(0, 1);     }     f[0] = 1LL;     g[0] = 0LL;     for (i = 1; i <= k; ++i) {       f[i] = (g[i - 1] * (n - 1)) % MOD;       g[i] = (f[i - 1] + g[i - 1] * (n - 2)) % MOD;     }     long long ans = 0LL;     if (!p.empty()) {       for (i = 0; i < p.size(); ++i) {         if (p[i] == 0)           ans = (ans + f[k]) % MOD;         else           ans = (ans + g[k]) % MOD;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[100005];   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     long long n;     long long i;     cin >> n;     for (i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     long long g, s, num;     s = num = 0;     for (i = 0; i < n; i++) {       s += A[i] * i - num;       num += A[i];     }     s = s * 2;     s += num;     g = gcd(s, n);     cout << s / g <<     << n / g << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 2, M = 1e6 + 2;   int n, m, X[N << 1], Y[N << 1], C[N][N];   void Merge(vector<pair<int, pair<int, int> > > &v) {     sort(v.begin(), v.end());     int q = 0;     for (int i = 1; i < (int)(v.size()); i++) {       if (v[i].first != v[q].first || v[i].second.first > v[q].second.second)         v[++q] = v[i];       else         v[q].second.second = v[i].second.second;     }     v.resize(q + 1);   }   bool Check(int t) {     vector<pair<int, pair<int, int> > > hor, ver;     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) C[i][j] = 0;     for (int i = 0; i < n; i++)       hor.push_back(make_pair(Y[i], make_pair(X[i] - 2 * t, X[i] + 2 * t)));     for (int i = n; i < n + m; i++)       ver.push_back(make_pair(X[i], make_pair(Y[i] - 2 * t, Y[i] + 2 * t)));     Merge(hor), Merge(ver);     for (pair<int, pair<int, int> > a : hor) {       vector<int> adj;       for (int i = 0; i < (int)(ver.size()); i++) {         pair<int, pair<int, int> > b = ver[i];         if (b.second.first <= a.first && a.first <= b.second.second &&             a.second.first <= b.first && b.first <= a.second.second) {           for (int j : adj)             if (C[i][j]++) return true;           adj.push_back(i);         }       }     }     return false;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n + m; i++) {       cin >> X[i] >> Y[i];       int x = X[i] - Y[i], y = X[i] + Y[i];       X[i] = x, Y[i] = y;     }     int dw = 0, up = M;     while (up - dw > 1) {       int md = (dw + up) >> 1;       if (Check(md))         up = md;       else         dw = md;     }     if (up == M)       cout <<  Poor Sereja!  << endl;     else       cout << up << endl;     return 0;   }
#include <iostream>      using namespace std;         int main()   {       int n,q, l,r;       cin>>n>>q;       string s;       cin>>s;       int arr[n];       arr[0]=s[0]- a +1;       for(int i=1;i<n;i++){           arr[i]=arr[i-1]+s[i]- a +1;       }       while(q--){           cin>>l>>r;           cout<<(arr[r-1]-((l==1)?0:arr[l-2]))<<  n ;       }       return 0;   }