malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7, M = 1e9 + 7;   vector<int> primes;   bool isp[N];   void sieve() {     fill(isp, isp + N, 1);     isp[0] = isp[1] = 0;     for (int i = 2; i * i < N; i++)       if (isp[i])         for (int j = i * i; j < N; j += i) isp[j] = 0;     for (int i = 2; i < N; i++)       if (isp[i]) primes.push_back(i);   }   vector<pair<int, int> > factorize(int x) {     vector<pair<int, int> > ans;     for (int i : primes) {       if (i * i > x) break;       int cnt = 0;       while (x % i == 0) cnt++, x /= i;       if (cnt) ans.push_back(make_pair(i, cnt));     }     if (x > 1) ans.push_back(make_pair(x, 1));     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     sieve();     int n;     cin >> n;     long long ans = 1;     map<int, int> fac;     map<int, int> cnt;     vector<vector<pair<int, int> > > factors;     int pp[n];     for (int i = 0; i < n; i++) cin >> pp[i];     sort(pp, pp + n);     reverse(pp, pp + n);     for (int i = 1; i <= n; i++) {       int p = pp[i - 1];       if (fac.count(p) == 0) {         ans = (ans * p) % M;         fac[p] = 1;         cnt[p] = 1;         vector<pair<int, int> > v;         v.push_back(make_pair(p, 1));         factors.push_back(v);       } else {         vector<pair<int, int> > pf = factorize(p - 1);         factors.push_back(pf);         for (auto pr : pf) {           int p = pr.first;           int e = pr.second;           int dif = e - fac[p];           if (dif < 0) continue;           if (dif == 0) {             cnt[p]++;             continue;           }           fac[p] += dif;           cnt[p] = 1;           for (int i = 0; i < dif; i++) ans = (ans * p) % M;         }       }     }     for (auto pf : factors) {       bool found = true;       for (auto pr : pf) {         int p = pr.first;         int e = pr.second;         int mx = fac[p];         assert(e <= mx);         if (e == mx && cnt[p] == 1) {           found = false;           break;         }       }       if (found) {         ans++;         break;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[26];   int A[26], m;   void solve() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) v[s[i] -  a ].push_back(i);     for (int i = 0; i < 26; i++) {       if (s.find(i +  a ) != string::npos) {         m = v[i][0] + 1;         for (int j = 1; j < (int)v[i].size(); j++)           m = max(m, v[i][j] - v[i][j - 1]);         m = max(m, (int)s.length() - v[i][(int)v[i].size() - 1]);         A[i] = m;       }     }     m = INT_MAX;     for (int i = 0; i < 26; i++) {       if (A[i] != 0) m = min(m, A[i]);     }     cout << m <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010, mod = 1LL * 1000 * 1000 * 1000 + 7;   long long dp[N][N], inv_fact[N], fact[N], n, k;   long long Pow(long long a, long long b) {     return b ? (b & 1 ? a : 1) % mod * Pow(a * a % mod, b >> 1) % mod : 1;   }   int C(int r, int n) {     if (r > n) return 0;     int num = 1;     for (int i = n; i >= n - r + 1; i--) num = 1LL * num * i % mod;     num = 1LL * num * inv_fact[r] % mod;     return num;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     fact[0] = 1;     for (int i = 1; i < N; i++) fact[i] = 1LL * fact[i - 1] * i % mod;     inv_fact[N - 1] = Pow(fact[N - 1], mod - 2);     for (int i = N - 2; i >= 0; i--)       inv_fact[i] = 1LL * inv_fact[i + 1] * (i + 1) % mod;     for (int i = 1; i < N; i++) dp[1][i] = 1;     for (int i = 2; i < N; i++)       for (int j = i; j < N; j++)         dp[i][j] = 1LL * (dp[i - 1][j - 1] + dp[i][j - 1]) % mod * i % mod;     cin >> n >> k;     long long ans = 0;     for (int r = 1; r <= min(k, n); r++) {       long long t = Pow(2, n - r);       t = 1LL * t * dp[r][k] % mod;       t = 1LL * t * C(r, n) % mod;       ans = (1LL * ans + t) % mod;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int haha[105];   int ans = 0;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &haha[i]);       if (haha[i] == 0)         break;       else if (i < k)         ans++;       else if (haha[i] == haha[k - 1])         ans++;       else         break;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long int, int> > pq;   vector<pair<int, int> > vp;   map<long long int, int> mp, m;   const int N = 1e5 + 6;   long long int ans[N];   vector<int> v, v1;   set<long long int> s, s1;   int visit[N];   struct domingo {     int val, left, right;   } o[N];   bool used[102];   int main() {     int a, b, c, ct = 1;     cin >> a >> b >> c;     a = a % b;     a *= 10;     for (int i = 0; i < 1e5 + 5; i++) {       int x = a / b;       a %= b;       if (x == c) return cout << ct, 0;       a *= 10;       ct++;     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int MN = 1e6 + 6;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     long long n;     cin >> n;     long long p_x = 0, p_y = 0;     long long res = 1;     for (long long i = 0; i < n; ++i) {       long long n_x, n_y;       cin >> n_x >> n_y;       if (p_x == n_x && p_y == n_y) continue;       long long a = max(p_x, p_y);       long long b = min(n_x, n_y);       if (p_x == p_y) {         a++;       }       if (a <= b) res += b - a + 1;       p_x = n_x;       p_y = n_y;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, i, j, mid, cnt = 0;     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> a;         if (i == j) cnt = cnt + a;         if (i + j == n - 1) cnt = cnt + a;         if (i == n / 2) cnt = cnt + a;         if (j == n / 2) cnt = cnt + a;         if (i == n / 2 && j == n / 2) mid = a;       }     }     cout << cnt - (3 * mid) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int i = n, j = n;     vector<int> a(2 * n + 1), b(2 * n + 1);     long long s = 0, x = 1, y = a[n] = b[n] = 1;     while (n--) {       int v;       cin >> v;       if (v < m)         x += a[++i]++, y += b[++j]++;       else if (v == m)         x += a[++i]++, y -= b[j], ++b[--j];       else         x -= a[i], ++a[--i], y -= b[j], ++b[--j];       s += x - y;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int mask[500][500][17];   int x[500], y[500], X[500], Y[500];   double xx[500], yy[500], XX[500], YY[500];   double vect(double x1, double y8687969, double x2, double y2) {     return x1 * y2 - x2 * y8687969;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 0; i < m; i++) scanf( %d%d , &X[i], &Y[i]);     double *cx, *cy, *CX, *CY;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         xx[j] = x[j] - x[i], yy[j] = y[j] - y[i];       }       for (int j = 0; j < m; j++) {         XX[j] = X[j] - x[i];         YY[j] = Y[j] - y[i];       }       cx = xx + i;       cy = yy + i;       for (int j = i + 1; j < n; j++) {         cx++;         cy++;         CX = XX;         CY = YY;         int *ap = mask[i][j], *ar = mask[j][i];         int b = 0;         for (int k = 0; k < m; k++, CX++, CY++) {           if ((*cx) * (*CY) - (*cy) * (*CX) > 0)             (*ap) |= (1 << b);           else             (*ar) |= (1 << b);           b++;           if (b == 30) {             ap++;             ar++;             b = 0;           }         }       }     }     int ans = 0;     double *jx, *jy, *kx, *ky;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         xx[j] = x[j] - x[i];         yy[j] = y[j] - y[i];       }       jx = xx + i;       jy = yy + i;       for (int j = i + 1; j < n; j++) {         jx++;         jy++;         kx = jx;         ky = jy;         for (int k = j + 1; k < n; k++) {           kx++;           ky++;           if ((*jx) * (*ky) - (*jy) * (*kx) > 0) {             ans++;             for (int l = 0; l < 17; l++)               if (mask[i][j][l] & mask[j][k][l] & mask[k][i][l]) {                 ans--;                 break;               }           } else {             ans++;             for (int l = 0; l < 17; l++)               if (mask[i][k][l] & mask[k][j][l] & mask[j][i][l]) {                 ans--;                 break;               }           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x;     int A[200010] = {0}, L[200010] = {0}, R[200010] = {0};     scanf( %d%d%d , &n, &k, &x);     for (int i = 1; i <= n; i++) {       scanf( %d , A + i);     }     sort(A + 1, A + 1 + n);     for (int i = 1; i <= n; i++) {       L[i] = A[i] | L[i - 1];     }     for (int i = n; i >= 1; i--) {       R[i] = A[i] | R[i + 1];     }     long long ret = 0, m = 1;     for (int i = 1; i <= k; i++) {       m *= x;     }     for (int i = 1; i <= n; i++) {       long long ans = A[i] * m | L[i - 1] | R[i + 1];       if (ans > ret) {         ret = ans;       }     }     printf( %I64d n , ret);   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int main() {     cin >> n >> k >> s;     int del = (n - k) / 2;     stack<int> st;     for (char ch : s) {       if (ch ==  ( ) {         if (del) {           st.push(1);           del--;         } else {           st.push(0);           putchar( ( );         }       } else {         int v = st.top();         st.pop();         if (v == 0) putchar( ) );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 4;   int n, ans, ar[maxn], flag[maxn], dp[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     for (int i = 0; i < maxn; i++) dp[i] = 1;     for (int i = n - 1; i >= 0; i--) {       int mx = 0;       for (int j = 2 * ar[i]; j < maxn; j += ar[i]) {         if (flag[j]) mx = max(dp[j], mx);       }       dp[ar[i]] = mx + 1;       flag[ar[i]] = 1;       ans = max(ans, mx + 1);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   int ult, casas;   string s;   int solve(int k) {     int u = -1;     int acc = k;     for (int i = 0; i < n; i++)       if (s[i] ==  S ) {         acc++;         if (acc >= casas) {           u = i;           break;         }       }     if (u == -1) return 2000000000;     u = max(u, ult);     acc = k;     int last = 2000000000;     int t = 1, need = 0;     int ans = 2000000000;     for (int i = 0; i < n; i++) {       if (s[i] ==  H ) {         if (acc) {           acc--;           if (i == ult && need == 0) ans = min(ans, t);         } else {           last = min(last, i);           need++;         }         t++;       } else if (s[i] ==  S ) {         acc++;         if (need && acc >= need) {           ans = min(ans, t + 2 * (u - i) + (i - last));           acc -= need;           need = 0;           if (i >= ult) {             t += (i - last);             ans = min(ans, t);             return ans;           } else             t += (2 * (i - last)) + 1;           last = 2000000000;         } else           t++;       } else         t++;     }     return ans;   }   int main() {     cin >> n >> t;     cin >> s;     casas = 0;     ult = -1;     for (int i = 0; i < n; i++)       if (s[i] ==  H ) casas++, ult = max(ult, i);     int ini = 0, fim = casas;     if (solve(fim) > t) {       printf( -1 n );       return 0;     }     while (ini < fim) {       int mid = (ini + fim) / 2;       if (solve(mid) <= t)         fim = mid;       else         ini = mid + 1;     }     cout << ini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool ready = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(12);     return true;   }();   const double PI = acos(-1);   using ll = long long;   using pii = pair<ll, ll>;   using pdd = pair<double, double>;   using vd = vector<double>;   using vb = vector<bool>;   using vi = vector<ll>;   using vvi = vector<vi>;   using vs = vector<string>;   void solve() {     ll n;     cin >> n;     ;     ll m;     cin >> m;     ;     vb sx(n + 1);     vb sy(n + 1);     for (ll i = 0; i < m; i++) {       ll x;       cin >> x;       ;       ll y;       cin >> y;       ;       sx[x] = true;       sy[y] = true;     }     ll ans = 0;     for (ll i = 2; i < n / 2 + 1; i++) {       if (!sy[n - i + 1]) ans++;       if (!sy[i]) ans++;       if (!sx[n - i + 1]) ans++;       if (!sx[i]) ans++;     }     if (n & 1) {       if ((!sx[n / 2 + 1]) || (!sy[n / 2 + 1])) ans++;     }     cout << ans << endl;   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T id(T b) {     return b;   };   template <class It>   bool all(It f, It l) {     return std::all_of(f, l, id<bool>);   }   template <class It>   bool any(It f, It l) {     return std::any_of(f, l, id<bool>);   }   const int MAX_N = 2000, MAX_A = 1000000;   int n, k, s;   int a[MAX_N];   int main() {     cin >> k;     s = a[0] = -1;     n = 1;     while (s - n + 1 != k) {       a[n] = min(k - (s - n), MAX_A);       s += a[n];       n++;     }     cout << n << endl;     for (int i = 0; i < n; i++) cout << a[i] <<    n [i + 1 == n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1007];   int main() {     char c;     int t = 3;     while (t--) {       scanf(  %c , &c);       char temp;       scanf( %c , &temp);       char d;       scanf( %c , &d);       if (temp ==  > ) {         arr[c]++;         arr[d]--;       } else {         arr[c]--;         arr[d]++;       }     }     int flag1 = 0;     char x, y, z;     int flag2 = 0;     int flag3 = 0;     for (int i =  A ; i <=  C ; i++) {       if (arr[i] == 2) {         flag1 = 1;         x = (char)i;       }       if (arr[i] == 0) {         flag2 = 1;         y = (char)i;       }       if (arr[i] == -2) {         flag3 = 1;         z = (char)i;       }     }     if (flag1 && flag2 && flag3) {       cout << z << y << x << endl;     } else       puts( Impossible );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> q(3 * n + 1);     for (int i = 0; i < 3 * n; i++) {       int a;       cin >> a;       q[a] = i;     }     vector<vector<int>> v(n, vector<int>(3));     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> v[i][j];       }     }     int is;     cin >> is;     int team;     int ind;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         if (v[i][j] == is) {           team = i;           ind = j;         }       }     }     int m = 1e9;     for (int i = 0; i < 3; i++) {       m = min(m, q[v[team][i]]);     }     if (q[is] == m) {       vector<int> ans;       vector<int> dop;       int mi = 1e9;       for (int i = 0; i < 3; i++) {         if (v[team][i] < mi && i != ind) mi = v[team][i];       }       ans.push_back(mi);       mi = 0;       for (int i = 0; i < 3; i++) {         if (v[team][i] > mi && i != ind) mi = v[team][i];       }       ans.push_back(mi);       for (int i = 0; i < team; i++) {         for (int j = 0; j < 3; j++) {           if (v[i][j] < mi)             ans.push_back(v[i][j]);           else             dop.push_back(v[i][j]);         }       }       sort(ans.begin(), ans.end());       for (int i = team + 1; i < n; i++) {         for (int j = 0; j < 3; j++) {           dop.push_back(v[i][j]);         }       }       sort(dop.begin(), dop.end());       for (int i = 0; i < ans.size(); i++) {         cout << ans[i] <<    ;       }       for (int i = 0; i < dop.size(); i++) {         cout << dop[i] <<    ;       }     } else {       for (int i = 1; i <= 3 * n; i++) {         if (i != is) {           cout << i <<    ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long max(long long a, long long b) { return (a > b ? a : b); }   void printa(long long arr[], long long n) {     for (long long i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   void printv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void printset(set<long long> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   void printmset(multiset<long long> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   void printmgset(multiset<long long, greater<long long>> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   const long long inf = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long fact(long long n) { return (n == 1 || n == 0) ? 1 : n * fact(n - 1); }   const long long N = 1e5 + 1;   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < (n); ++i) {       cin >> v[i];     }     long long x, f;     cin >> x >> f;     long long c = 0;     long long idk = 0;     for (long long i = 0; i < (n); ++i) {       if (v[i] > x) {         idk += ((v[i] - x) / (x + f) + ((v[i] - x) % (x + f) > 0));       }     }     cout << idk * f <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, x[N], y[N], num[N], val[N], dp[2][N], cnt;   vector<int> adj[N];   bool vis[N];   void DFS(int u) {     vis[u] = true;     for (int i = 0; i < (int)adj[u].size(); ++i) {       int v = adj[u][i];       if (vis[v] == false) DFS(v);     }     num[u] = cnt;     val[cnt--] = u;   }   bool Check(int k) {     for (int i = 1; i <= n; ++i) adj[i].clear();     for (int i = 1; i <= k; ++i) adj[x[i]].push_back(y[i]);     for (int i = 1; i <= n; ++i) num[i] = 0, vis[i] = false;     cnt = n;     for (int i = 1; i <= n; ++i)       if (vis[i] == false) DFS(i);     memset(dp, 0, sizeof dp);     for (int u = 1; u <= n; ++u) {       for (int i = 0; i < (int)adj[val[u]].size(); ++i) {         int v = adj[val[u]][i];         dp[0][v] = max(dp[0][v], dp[0][val[u]] + 1);       }     }     for (int u = n; u >= 1; --u) {       for (int i = 0; i < (int)adj[val[u]].size(); ++i) {         int v = adj[val[u]][i];         dp[1][val[u]] = max(dp[1][val[u]], dp[1][v] + 1);       }     }     for (int i = 1; i <= n; ++i)       if (dp[0][i] + 1 + dp[1][i] != n) return false;     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &y[i]);     int l = 1, r = m, res = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (Check(mid)) {         res = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<vector<int>> x(m + 1, vector<int>(n + 1));     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       for (int j = 1; j <= m; j++) {         x[j][i] = x[j][i - 1];         if (j == k) {           x[j][i] += 1;         }       }     }     vector<int> y(m + 1);     for (int i = 1; i <= m; i++) {       scanf( %d , &y[i]);     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         for (int k = 1; k <= m; k++) {           if (x[k][j] - x[k][i - 1] != y[k]) {             break;           }           if (k == m) {             printf( YES n );             return 0;           }         }       }     }     printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 1000000005;   long long INFF = 1000000000000000005ll;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   long long MOD = 1000000007;   template <typename T_vector>   void output_vector(const T_vector &v, bool line_break = false,                      bool add_one = false, int start = -1, int end = -1) {     if (start < 0) start = 0;     if (end < 0) end = int(v.size());     for (int i = start; i < end; i++) {       cout << v[i] + (add_one ? 1 : 0)            << (line_break    ?   n                 : i < end - 1 ?                                  :   n );     }   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (auto &(z) : a) cin >> z;     ;     int ans = 0;     for (int(i) = (0); (i) < (n); ++(i)) {       int j = i;       while (j + 1 < n && a[j + 1] <= a[j] * 2) j++;       ans = max(ans, j - i + 1);       i = j;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   ;   const int inf = 1e9 + 5;   const int mod = 1e9 + 7;   const int logN = 17;   int x, y, n, m, a[N], b[N], w[N], p[N], score[N];   vector<int> v[N];   long long ans[N], upsum[N], downsum[N];   bool cmp(int x, int y) { return score[x] < score[y]; }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &a[i], &b[i]);       score[i] = a[i] - b[i];       p[i] = i;     }     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; i++) {       w[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) upsum[i] = upsum[i - 1] + a[p[i]];     for (int i = n; i >= 1; i--) downsum[i] = downsum[i + 1] + b[p[i]];     for (int i = 1; i <= n; i++) {       int up = i - 1;       int down = n - i;       long long ups = upsum[i - 1];       long long dws = downsum[i + 1];       int cur = p[i];       for (auto go : v[cur]) {         if (w[go] > i) {           down--;           dws -= b[go];         } else {           up--;           ups -= a[go];         }       }       ans[cur] = ups + dws + up * (long long)b[cur] + down * (long long)a[cur];     }     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, potezi = 1, bodovi = 0;     scanf( %d , &n);     pair<int, int> a[n];     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i].second, &a[i].first);     }     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       if (!potezi) break;       potezi += a[i].first - 1;       bodovi += a[i].second;     }     printf( %d n , bodovi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b;   int pas = 0;   int main() {     cin >> a >> b;     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[a.size() - 1 - i]) {         pas++;       }     }     if (pas > 0) {       cout <<  NO ;     } else {       cout <<  YES ;     }   }