malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int maxn = 1e6 + 10;   struct Edge {     int to, nxt;     long long cost;     Edge() {}     Edge(int to, int nxt, long long cost) : to(to), nxt(nxt), cost(cost) {}   } edge[maxn << 1];   int head[maxn], tot;   long long dp[maxn];   void Init(int n) {     tot = 0;     for (int i = 1; i <= n; ++i) head[i] = -1;   }   void addedge(int u, int v, long long cost) {     edge[tot] = Edge(v, head[u], cost);     head[u] = tot++;     edge[tot] = Edge(u, head[v], cost);     head[v] = tot++;   }   int n;   long long val[maxn];   long long ans;   void DFS(int u, int pre) {     dp[u] = val[u];     long long max1 = 0, max2 = 0;     for (int i = head[u]; ~i; i = edge[i].nxt) {       int v = edge[i].to;       long long cost = edge[i].cost;       if (v == pre) continue;       DFS(v, u);       long long tmp = dp[v] - cost;       if (tmp > max1) swap(max1, tmp);       max2 = max(tmp, max2);       dp[u] = max(dp[u], dp[v] - cost + val[u]);     }     ans = max(ans, max(dp[u], max1 + max2 + val[u]));   }   void RUN() {     while (~scanf( %d , &n)) {       Init(n);       for (int i = 1; i <= n; ++i) scanf( %lld , val + i);       long long w;       for (int i = 1, u, v; i < n; ++i) {         scanf( %d %d %lld , &u, &v, &w);         addedge(u, v, w);       }       ans = 0;       DFS(1, -1);       printf( %lld n , ans);     }   }   int main() {     RUN();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400000 + 1000;   struct node {     int l, r, dir;     long long w;   } temp;   vector<node> v;   long long vis[N];   bool cmp(node a, node b) {     if (a.l == b.l) return a.dir < b.dir;     return a.l < b.l;   }   int main() {     int n, x, i, l, w, r, time;     long long ans;     memset(vis, 0, sizeof(vis));     ans = 1e11;     scanf( %d%d , &n, &x);     for (i = 0; i < n; i++) {       scanf( %d%d%d , &l, &r, &w);       temp.w = w;       temp.l = l;       temp.r = r;       temp.dir = -1;       v.push_back(temp);       temp.l = r;       temp.r = l;       temp.dir = 1;       v.push_back(temp);     }     sort(v.begin(), v.end(), cmp);     for (i = 0; i < v.size(); i++) {       time = abs(v[i].r - v[i].l) + 1;       if (time >= x) continue;       if (v[i].dir == -1) {         if (vis[x - time] != 0) ans = min(ans, vis[x - time] + v[i].w);       } else {         if (!vis[time])           vis[time] = v[i].w;         else           vis[time] = min(vis[time], v[i].w);       }     }     if (ans == 1e11)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, k, u, v, c[200005] = {}, d[200005] = {}, z = 0;     vector<int> g[200005] = {};     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 0; i < m; i++)       cin >> u >> v, g[u].push_back(v), g[v].push_back(u);     for (int i = 1; i <= n; i++) {       if (d[i]) continue;       d[i] = 1;       queue<int> q;       vector<int> w = {i};       q.push(i);       while (!q.empty()) {         int x = q.front();         q.pop();         for (int j = 0; j < g[x].size(); j++) {           if (!d[g[x][j]]) d[g[x][j]] = 1, q.push(g[x][j]), w.push_back(g[x][j]);         }       }       unordered_map<int, int> p;       int o = 0;       for (int j = 0; j < w.size(); j++) p[c[w[j]]]++, o = max(o, p[c[w[j]]]);       z += w.size() - o;     }     cout << z;   }
#include <bits/stdc++.h>   using namespace std;   int p = 0, cnt = 0, cplus, cminus, val[10005], Child[10005];   pair<int, int> F[10005][105], FF[105];   string s;   vector<int> g[10005];   void DFS(int u) {     while (p < s.size()) {       p++;       if (s[p - 1] ==  ( ) {         g[u].push_back(++cnt);         DFS(cnt);       } else if ( 0  <= s[p - 1] && s[p - 1] <=  9 ) {         val[++cnt] = s[p - 1] -  0 ;         g[u].push_back(cnt);       } else if (s[p - 1] ==  ) )         break;     }   }   void FinalDFS(int u, int root) {     for (int i = 0; i <= 100; i++) F[u][i] = pair<int, int>(1e9, -1e9);     if (g[u].size() == 0) {       F[u][0] = pair<int, int>(val[u], val[u]);       return;     }     for (int i = 0; i < g[u].size(); i++)       if (g[u][i] != root) FinalDFS(g[u][i], u);     for (int i = 0; i <= 100; i++) F[u][i] = F[g[u][0]][i];     for (int i = 1; i < g[u].size(); i++) {       int v = g[u][i];       for (int j = 0; j <= 100; j++) FF[j] = pair<int, int>(1e9, -1e9);       for (int j = 0; j <= 100; j++)         for (int jj = 0; jj <= j; jj++) {           if (jj < j) {             if (cplus <= 100) {               FF[j].first =                   min(FF[j].first, F[u][j - jj - 1].first + F[v][jj].first);               FF[j].second =                   max(FF[j].second, F[u][j - jj - 1].second + F[v][jj].second);             } else {               FF[j].first =                   min(FF[j].first, F[u][j - jj - 1].first - F[v][jj].second);               FF[j].second =                   max(FF[j].second, F[u][j - jj - 1].second - F[v][jj].first);             }           }           if (cplus <= 100) {             FF[j].first = min(FF[j].first, F[u][j - jj].first - F[v][jj].second);             FF[j].second =                 max(FF[j].second, F[u][j - jj].second - F[v][jj].first);           } else {             FF[j].first = min(FF[j].first, F[u][j - jj].first + F[v][jj].first);             FF[j].second =                 max(FF[j].second, F[u][j - jj].second + F[v][jj].second);           }         }       for (int j = 0; j <= 100; j++) F[u][j] = FF[j];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> s >> cplus >> cminus;     DFS(0);     FinalDFS(1, 1);     if (cplus <= 100)       cout << F[1][cplus].second;     else       cout << F[1][cminus].second;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   vector<pair<char, int> > v;   map<int, int> mp1, mp2;   int arr[105][105];   int main() {     int x, y, z, n = 0, m = 0, c = 0, lo = 2, mn = 1e9, mx = 0;     char ch;     cin >> x >> y;     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         cin >> arr[i][j];       }     }     if (y > x) {       for (int i = 0; i < x; i++) {         for (int j = 0; j < y; j++) {           mn = min(mn, arr[i][j]);         }         if (mn != 0) {           for (int k = 0; k < y; k++) {             arr[i][k] -= mn;           }           while (mn--) {             v.push_back(make_pair( r , i + 1));           }         }         mn = 1e9;       }       mn = 1e9;       for (int i = 0; i < y; i++) {         mn = 1e9;         for (int j = 0; j < x; j++) {           mn = min(mn, arr[j][i]);         }         if (mn != 0) {           for (int k = 0; k < x; k++) {             arr[k][i] -= mn;           }           while (mn--) {             v.push_back(make_pair( c , i + 1));           }         }         mn = 1e9;       }     } else {       mn = 1e9;       for (int i = 0; i < y; i++) {         mn = 1e9;         for (int j = 0; j < x; j++) {           mn = min(mn, arr[j][i]);         }         if (mn != 0) {           for (int k = 0; k < x; k++) {             arr[k][i] -= mn;           }           while (mn--) {             v.push_back(make_pair( c , i + 1));           }         }         mn = 1e9;       }       for (int i = 0; i < x; i++) {         for (int j = 0; j < y; j++) {           mn = min(mn, arr[i][j]);         }         if (mn != 0) {           for (int k = 0; k < y; k++) {             arr[i][k] -= mn;           }           while (mn--) {             v.push_back(make_pair( r , i + 1));           }         }         mn = 1e9;       }     }     bool f = 0;     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         if (arr[i][j] != 0) {           f = 1;           i = x;           break;         }       }     }     if (f == 1) {       cout << -1 << endl;     } else {       cout << v.size() << endl;       for (int i = 0; i < v.size(); i++) {         if (v[i].first ==  r ) {           cout <<  row  ;         } else {           cout <<  col  ;         }         cout << v[i].second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[400001], b[400001];   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     unsigned n;     cin >> n;     for (unsigned i = 1; i <= n / 2; ++i) cin >> b[i];     a[1] = 0;     a[n] = b[1];     for (unsigned i = 2; i <= n / 2; ++i) {       if (b[i] - a[i - 1] <= a[n - i + 2]) {         a[i] = a[i - 1];         a[n - i + 1] = b[i] - a[i];       } else {         a[n - i + 1] = a[n - i + 2];         a[i] = b[i] - a[n - i + 1];       }     }     for (unsigned i = 1; i <= n; ++i) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j = 0, k, l, T, c = 0, t = 0;   long long a[10010], d[10010], e[10010];   string s;   int main() {     getline(cin, s);     a[0] = s[0] - 48;     d[0] = a[0];     e[0] = 0;     for (i = 1; i < s.length() - 1; i += 2) {       if (s[i] ==  * ) {         a[i + 1] = a[i - 1] - d[i - 1] + d[i - 1] * (s[i + 1] - 48);         d[i + 1] = d[i - 1] * (s[i + 1] - 48);         e[i + 1] = i + 1;         for (k = j; k < i; k += 2) {           e[k] = i + 1;           d[k] = d[i + 1];         }       } else if (s[i] ==  + ) {         a[i + 1] = a[i - 1] + s[i + 1] - 48;         d[i + 1] = s[i + 1] - 48;         e[i + 1] = i + 1;         j = i + 1;       }     }     for (i = 1; i < s.length() - 1; i += 2) {       if (s[i] ==  * ) {         t = 1;         c = max(c, a[i - 1] * (d[i + 1] / (s[i - 1] - 48)) + a[s.length() - 1] -                        a[e[i + 1]]);         if (i > 1) {           if (s[i - 2] ==  + ) {             c = max(c, a[i - 3] + (d[e[i + 1]] / (s[e[i + 1]] - 48)) *                                       (a[s.length() - 1] - a[e[i + 1]] +                                        (s[e[i + 1]] - 48)));           }         } else {           c = max(c, (d[e[i + 1]] / (s[e[i + 1]] - 48)) *                          (a[s.length() - 1] - a[e[i + 1]] + (s[e[i + 1]] - 48)));         }         for (j = e[i + 1] + 1; j < s.length() - 1; j += 2) {           if (s[j] ==  *  and s[j - 2] ==  + ) {             c = max(c, a[i - 3] +                            (d[i + 1] / (s[e[i + 1]] - 48)) *                                (d[j + 1] / (s[j - 1] - 48)) *                                (a[j - 1] - a[e[i + 1]] + s[e[i + 1]] - 48) +                            a[s.length() - 1] - a[e[j + 1]]);           }         }         i = e[i + 1] - 1;       }     }     if (t == 0) {       c = a[s.length() - 1];     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int edge[1005];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> edge[i];     }     int sum = 0;     int tmp1, tmp2;     for (int i = 0; i < m; i++) {       cin >> tmp1 >> tmp2;       sum += min(edge[tmp1], edge[tmp2]);     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     scanf( %lld%lld , &n, &k);     if (k > (long long)1e8) {       printf( -1 n );       return 0;     }     long long b = n / (k * (k + 1) / 2);     if (b == 0) {       printf( -1 n );       return 0;     }     long long r = 1;     for (long long x = 1; x * x <= n; x++) {       if (n % x != 0) continue;       if (x <= b && x > r) r = x;       if (n / x <= b && n / x > r) r = n / x;     }     for (int i = 1; i < k; i++) printf( %lld  , r * i);     n -= r * k * (k - 1) / 2;     printf( %lld n , n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 123;   int n, p[MAXN], s[MAXN], a[MAXN];   vector<int> c[MAXN];   void inp();   void dfs(int);   int main() {     inp();     a[0] = s[0];     dfs(0);     for (int i = 0; i < n; i++)       if (a[i] < 0) return cout << -1, 0;     cout << accumulate(a, a + n, 0ll);     return 0;   }   void inp() {     cin >> n;     p[0] = -1;     for (int i = 1; i < n; i++) cin >> p[i], c[--p[i]].push_back(i);     for (int i = 0; i < n; i++) cin >> s[i];   }   void dfs(int v) {     if (c[v].empty()) return;     if (~s[v])       for (int u : c[v]) dfs(u);     else {       int kam = INT_MAX;       for (int u : c[v]) kam = min(kam, s[u]);       a[v] = kam - s[p[v]];       s[v] = s[p[v]] + a[v];       for (int u : c[v]) {         a[u] = s[u] - s[v];         dfs(u);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double c = 0, l = 0, i, j;     string x;     cin >> x;     if (x.size() == 1) {       cout << x[0] << x[0];       return 0;     }     if (x.size() % 2 == 0)       c = x.size() / 2 + 1;     else       c = x.size() / 2;     string a, b, m;     for (i = x.size() / 2; i >= 0; i--) {       a.clear();       b.clear();       m.clear();       for (j = l + c; j < x.size(); j++) {         if (x[i] != x[j]) {           a = x;           m = x;           a.insert(x.size() - i, 1, x[i]);           m.insert(x.size() - j - 1, 1, x[j]);         }         break;       }       l++;       b = a;       reverse(b.begin(), b.end());       if (a == b and a.size() != 0 and b.size() != 0) {         cout << a;         return 0;       }       b.clear();       b = m;       reverse(b.begin(), b.end());       if (m == b and m.size() != 0 and b.size() != 0) {         cout << m;         return 0;       }     }     l = 0;     for (i = x.size() - 1 / 2; i >= 0; i--) {       a.clear();       b.clear();       m.clear();       for (j = l + c; j < x.size(); j++) {         if (x[i] != x[j]) {           a = x;           m = x;           a.insert(x.size() - i, 1, x[i]);           m.insert(x.size() - j - 1, 1, x[j]);         }         break;       }       l++;       b = a;       reverse(b.begin(), b.end());       if (a == b and a.size() != 0 and b.size() != 0) {         cout << a;         return 0;       }       b.clear();       b = m;       reverse(b.begin(), b.end());       if (m == b and m.size() != 0 and b.size() != 0) {         cout << m;         return 0;       }     }     a.clear();     b.clear();     if (x.size() % 2 == 0)       x += x[0];     else       x = x[x.size() - 1] + x;     a = x;     reverse(a.begin(), a.end());     if (a == x)       cout << a;     else       cout <<  NA ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     int arr[14] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};     int i;     for (i = 0; i < 14; i++) {       if (a % arr[i] == 0) break;     }     if (i < 14) cout <<  YES ;     if (i == 14) cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   char s[500010];   long long ans, n, i, sum, fac[500010], a[500010], f[500010][2];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (i = 1; i <= n / 2; i++) swap(s[i], s[n - i + 1]);     f[1][0] = 10;     f[1][1] = 1;     fac[0] = 1;     for (i = 1; i <= n; i++) fac[i] = fac[i - 1] * 10 % p, a[i] = s[i] -  0 ;     sum = a[1];     for (i = 2; i <= n; i++) {       ans = (ans + (f[i - 1][0] - fac[i - 1] + p + f[i - 1][1]) % p * a[i]) % p;       f[i][0] = (f[i - 1][0] * 10 + f[i - 1][1] * 10) % p;       f[i][1] = (f[i - 1][1] + fac[i - 1]) % p;       ans = (ans + sum * (n - i + 1)) % p;       sum = (sum + a[i] * fac[i - 1]) % p;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3fll;   const int MAXN = 2e5 + 5;   const int mod = 1e9 + 7;   int a[MAXN], b[MAXN];   long long fastpow(long long a, int n) {     long long base = a, ret = 1;     while (n) {       if (n & 1) ret = ret * base % MOD;       base = base * base % MOD;       n >>= 1;     }     return ret;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     long long prob = 1, ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0) {         if (b[i] == 0)           ans = (ans + prob * (1 - fastpow(m, MOD - 2) + MOD) % MOD *                            fastpow(2, MOD - 2) % MOD) %                 MOD;         else           ans = (ans + prob * (m - b[i]) % MOD * fastpow(m, MOD - 2) % MOD) % MOD;         prob = prob * fastpow(m, MOD - 2) % MOD;       } else {         if (b[i] == 0) {           ans = (ans + prob * (a[i] - 1) % MOD * fastpow(m, MOD - 2) % MOD) % MOD;           prob = prob * fastpow(m, MOD - 2) % MOD;         } else {           if (b[i] > a[i])             break;           else if (b[i] < a[i]) {             ans = (ans + prob) % MOD;             break;           }         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   string A[6][3];   int B[6][4], p[4][3];   string name[4], s;   bool C[4][4];   bool foo() {     int i, j;     for (i = 0; i < 4; i++) {       for (j = 0; j < 3; j++) p[i][j] = 0;       for (j = 0; j < 6; j++) {         if (B[j][0] == i && B[j][2] > B[j][3]) p[i][0] += 3;         if (B[j][1] == i && B[j][2] < B[j][3]) p[i][0] += 3;         if (B[j][0] == i && B[j][2] == B[j][3]) p[i][0] += 1;         if (B[j][1] == i && B[j][2] == B[j][3]) p[i][0] += 1;         if (B[j][0] == i) {           p[i][1] += B[j][2];           p[i][2] += B[j][3];         }         if (B[j][1] == i) {           p[i][1] += B[j][3];           p[i][2] += B[j][2];         }       }     }     for (i = 0; i < 4; i++) {       C[i][i] = false;       for (j = 0; j < 4; j++)         if (i != j) {           if (p[i][0] != p[j][0])             C[i][j] = (p[i][0] > p[j][0]);           else {             if ((p[i][1] - p[i][2]) != (p[j][1] - p[j][2]))               C[i][j] = ((p[i][1] - p[i][2]) > (p[j][1] - p[j][2]));             else {               if (p[i][1] != p[j][1])                 C[i][j] = (p[i][1] > p[j][1]);               else                 C[i][j] = (name[i] < name[j]);             }           }         }     }     if (C[0][1] && C[0][2]) return true;     if (C[0][1] && C[0][3]) return true;     if (C[0][2] && C[0][3]) return true;     return false;   }   int main() {     int i, j;     for (i = 0; i < 5; i++)       for (j = 0; j < 3; j++) cin >> A[i][j];     k = 0;     name[0] =  BERLAND ;     name[1] =   ;     name[2] =   ;     name[3] =   ;     for (i = 0; i < 5; i++)       for (j = 0; j < 2; j++)         if (name[0] != A[i][j] && name[1] != A[i][j] && name[2] != A[i][j] &&             name[3] != A[i][j]) {           k++;           name[k] = A[i][j];         }     for (i = 0; i < 5; i++) {       j = 0;       while (name[j] != A[i][0]) j++;       B[i][0] = j;       j = 0;       while (name[j] != A[i][1]) j++;       B[i][1] = j;       B[i][2] = (int)((char)A[i][2][0] -  0 );       B[i][3] = (int)((char)A[i][2][2] -  0 );     }     for (i = 1; i < 4; i++) {       k = 0;       for (j = 0; j < 5; j++)         if (name[i] == A[j][0] || name[i] == A[j][1]) k++;       if (k == 2) break;     }     B[5][0] = 0;     B[5][1] = i;     for (int d = 1; d <= 50; d++) {       for (int y = 0; y <= 50; y++) {         B[5][2] = y + d;         B[5][3] = y;         if (foo()) {           cout << y + d <<  :  << y << endl;           return 0;         }       }     }     cout <<  IMPOSSIBLE n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int temp[100012], arr[100012], t[100012];     for (int i = 0; i < n; i++) {       cin >> arr[i];       t[i] = arr[i];     }     sort(t, t + n);     int v = 0;     for (int i = 0; i < n; i++) {       if (t[i] != arr[i]) {         v = 1;         break;       }     }     if (v == 0) {       cout << n << endl;       return 0;     }     int c = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == i)         c++;       else {         temp[i] = arr[i];       }     }     int f = 0;     for (int i = 0; i < n; i++) {       if (arr[i] != i) {         if (i == temp[temp[i]]) {           c += 2;           f = 1;           break;         }       }     }     if (f == 0) c += 1;     if (c > n) c = n;     cout << c << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[100005], tree[100005], used[100005], l[100005], r[100005],       d[100005], b[100005], query[100005], x, y, n, m, k;   template <class T>   inline T lowbit(T n) {     return (n & -n);   }   void update(long long s[], int index, long long val) {     while (index <= 100005) {       s[index] += val;       index += (index & (-index));     }   }   long long getS(long long s[], int l, int r) {     if (l > r)       return 0;     else if (l == 1) {       long long res = 0;       for (; r > 0; r -= lowbit(r)) res += s[r];       return res;     } else {       return getS(s, 1, r) - getS(s, 1, l - 1);     }   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < m; i++) {       cin >> l[i] >> r[i] >> d[i];     }     for (int i = 0; i < k; i++) {       cin >> x >> y;       update(tree, x, 1);       update(tree, y + 1, -1);     }     for (int i = 1; i <= m; i++) {       used[i] = getS(tree, 1, i);     }     for (int i = 0; i < m; i++) {       update(b, l[i], d[i] * used[i + 1]);       update(b, r[i] + 1, -d[i] * used[i + 1]);     }     for (int i = 0; i < n; i++) {       query[i + 1] = getS(b, 1, i + 1);     }     for (int i = 1; i <= n; i++) {       cout << arr[i - 1] + query[i];       if (i != n) {         cout <<    ;       } else {         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     char t, w;     cin >> n;     cin >> t >> w;     bool ok = true;     if (t == w) ok = false;     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         if (i == 0 && j < 2) continue;         char x;         cin >> x;         if ((i == j || i + j == n - 1) && x != t) ok = false;         if (!(i == j || i + j == n - 1) && x != w) ok = false;       }     if (ok)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int prime(int n) {     int i;     for (i = 3; i * i <= n; i += 2) {       if (n % i == 0) return 0;     }     return 1;   }   int m, i;   int main() {     scanf( %d , &m);     if (m < 9) {       printf( 1 n%d , m);       return 0;     }     printf( 3 n3  );     m -= 3;     if (m == 4) {       printf( 2 2 );       return 0;     }     for (i = 3;; i += 2) {       if (!prime(i)) continue;       if (!prime(m - i)) continue;       printf( %d %d , i, m - i);       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Order {     char d;     int p;     int q;   };   int main() {     int n, s;     Order a[1001];     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> a[i].d >> a[i].p >> a[i].q;     }     map<int, int> bmp, smp;     for (int i = 0; i < n; i++) {       if (a[i].d ==  B ) {         bmp[a[i].p] += a[i].q;       } else {         smp[a[i].p] += a[i].q;       }     }     vector<pair<int, int> > bv;     for (map<int, int>::iterator it = bmp.begin(); it != bmp.end(); it++) {       bv.push_back(make_pair(it->first, it->second));     }     vector<pair<int, int> > sv;     for (map<int, int>::iterator it = smp.begin(); it != smp.end(); it++) {       sv.push_back(make_pair(it->first, it->second));     }     sort(bv.begin(), bv.end());     sort(sv.begin(), sv.end());     reverse(bv.begin(), bv.end());     int n1 = min(s, (int)bv.size());     int n2 = min(s, (int)sv.size());     vector<pair<int, int> > resv;     for (int i = 0; i < n2; i++) {       resv.push_back(sv[i]);     }     reverse(resv.begin(), resv.end());     for (int i = 0; i < n2; i++) {       cout <<  S   << resv[i].first <<     << resv[i].second <<   n ;     }     for (int i = 0; i < n1; i++) {       cout <<  B   << bv[i].first <<     << bv[i].second <<   n ;     }     return 0;   }