malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > getfac(long long int n) {     vector<pair<long long int, long long int> > ret;     for (long long int i = 1; i < sqrt(n) + 1; i++) {       if (n % i == 0) {         ret.push_back({min({i, n / i}), max({i, n / i})});       }     }     return ret;   }   bool fun1(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     return a.first + a.second < b.first + b.second;   }   bool isin(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     return b.first <= a.first && a.second >= b.second;   }   long long int max(long long int a, long long int b) {     if (a <= b) return a;     return b;   }   long long int min(long long int a, long long int b) {     if (a <= b) return b;     return a;   }   int main() {     long long int a, b, c, d, ans = 1e17;     cin >> a >> b;     c = a;     d = b;     a = min({c, d});     b = max({c, d});     vector<pair<long long int, long long int> > af = getfac(a), bf = getfac(b),                                                 cf = getfac(a + b);     sort(cf.begin(), cf.end(), fun1);     for (int i = 0; i < cf.size(); i += 1) {       long long int p = cf[i].first, q = cf[i].second;       for (int j = 0; j < af.size(); j++) {         if (isin(cf[i], af[j])) {           ans = min({ans, 2 * (p + q)});         }       }       for (int j = 0; j < bf.size(); j++) {         if (isin(cf[i], bf[j])) {           ans = min({ans, 2 * (p + q)});         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (2e5 + 42);   const int MAXLOG = 20;   const int64_t inf = (int64_t)1e18;   int n, m, S;   vector<pair<int, int> > G[MAXN];   void read() {     cin >> n >> m >> S;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       G[u].push_back({v, w});       G[v].push_back({u, w});     }   }   bool in_queue[MAXN];   vector<int> pars[MAXN], adj[MAXN];   int64_t dist[MAXN];   int par[MAXN][MAXLOG], d[MAXN];   int lca(int u, int v) {     if (d[u] < d[v]) swap(u, v);     for (int lg = MAXLOG - 1; lg >= 0; lg--)       if (d[par[u][lg]] >= d[v]) u = par[u][lg];     if (u == v) return u;     for (int lg = MAXLOG - 1; lg >= 0; lg--)       if (par[u][lg] != par[v][lg]) u = par[u][lg], v = par[v][lg];     return par[u][0];   }   void spfa(int st) {     for (int i = 0; i <= n; i++) dist[i] = inf, adj[i].clear(), in_queue[i] = 0;     queue<int> Q;     in_queue[st] = 1;     dist[st] = 0;     Q.push(st);     while (!Q.empty()) {       int u = Q.front();       in_queue[u] = 0;       Q.pop();       for (auto e : G[u]) {         int v = e.first, w = e.second;         if (dist[v] > dist[u] + w) {           dist[v] = dist[u] + w;           if (!in_queue[v]) Q.push(v);           in_queue[v] = 1;         }       }     }     for (int i = 1; i <= n; i++)       for (auto e : G[i])         if (dist[e.first] == dist[i] + e.second) pars[e.first].push_back(i);   }   int tr_sz[MAXN];   void dfs(int u) {     tr_sz[u] = 1;     for (int v : adj[u]) {       dfs(v);       tr_sz[u] += tr_sz[v];     }   }   void solve() {     spfa(S);     int ans = 0;     vector<pair<int64_t, int> > order;     for (int i = 1; i <= n; i++)       if (dist[i] < inf) order.push_back({dist[i], i});     sort(order.begin(), order.end());     for (int i = 0; i < MAXLOG; i++) par[S][i] = S;     for (pair<int64_t, int> e : order) {       if (e.second == S) continue;       int u = e.second;       int l = pars[u][0];       for (int anc : pars[u]) l = lca(l, anc);       par[u][0] = l;       d[u] = d[l] + 1;       adj[l].push_back(u);       for (int lg = 1; lg < MAXLOG; lg++)         par[u][lg] = par[par[u][lg - 1]][lg - 1];     }     dfs(S);     for (int i = 1; i <= n; i++)       if (dist[i] < inf && i != S) ans = max(ans, tr_sz[i]);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, ce = 0, co = 0, A[100], i, o = 0, e = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &A[i]);     for (i = 0; i < n; i++) {       if (A[i] % 2 == 0) ce++;       if (A[i] % 2 != 0) co++;     }     if (co == 1) {       for (i = 0; i < n; i++) {         if (A[i] % 2 != 0) {           o++;           break;         } else           o++;       }       printf( %d , o);     }     if (ce == 1) {       for (i = 0; i < n; i++) {         if (A[i] % 2 == 0) {           e++;           break;         } else           e++;       }       printf( %d , e);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long c[(1 << 20)];   struct SuffixTree {     int s[(1 << 20)];     map<int, int> to[(1 << 20)];     int len[(1 << 20)] = {(1 << 30)}, fpos[(1 << 20)], link[(1 << 20)],                   id[(1 << 20)];     int node, pos, sz = 1, n = 0;     int make_node(int p, int l, int k) {       fpos[sz] = p;       len[sz] = l;       id[sz] = k;       return sz++;     }     void go_edge() {       while (pos > len[to[node][s[n - pos]]]) {         node = to[node][s[n - pos]];         pos -= len[node];       }     }     void add(int c, int k) {       s[n++] = c;       pos++;       int last = 0;       while (pos > 0) {         go_edge();         int edge = s[n - pos];         int& v = to[node][edge];         int t = s[fpos[v] + pos - 1];         if (v == 0) {           v = make_node(n - pos, (1 << 30), k);           link[last] = node;           last = 0;         } else if (t == c) {           link[last] = node;           return;         } else {           int u = make_node(fpos[v], pos - 1, k);           to[u][c] = make_node(n - 1, (1 << 30), k);           to[u][t] = v;           fpos[v] += pos - 1;           len[v] -= pos - 1;           v = u;           link[last] = u;           last = u;         }         if (node == 0)           pos--;         else           node = link[node];       }     }     long long rr;     int asd[(1 << 20)];     long long dfs(int x, int d) {       long long r = 0;       d += len[x];       if (!((int)(to[x]).size()))         r = c[id[x]];       else {         for (auto p : to[x]) r += dfs(p.second, d);       }       if (len[x]) rr = max(rr, r * d);       return r;     }     long long doit() {       for (int i = n - 1; i >= 0; --i) {         if (s[i] <= 0)           asd[i] = 0;         else           asd[i] = asd[i + 1] + 1;       }       for (int i = 1, ThxDem = sz; i < ThxDem; ++i)         len[i] = min(len[i], asd[fpos[i]]);       len[0] = 0;       rr = 0;       dfs(0, 0);       return rr;     }   };   int n;   SuffixTree t;   char _s[(1 << 20)];   int main() {     scanf( %d , &n);     for (int i = 0, ThxDem = n; i < ThxDem; ++i) {       scanf( %s , _s);       for (int j = 0; _s[j]; ++j) {         t.add(_s[j], i);       }       t.add(-i, i);     }     for (int i = 0, ThxDem = n; i < ThxDem; ++i) scanf( %lld , c + i);     printf( %lld n , t.doit());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[100000], b[100000];   vector<pair<int, long long>> connections[100000];   pair<long long, long long> needed(int node) {     long long temp = a[node] - b[node];     long long temp2 = temp / 1000000007;     temp %= 1000000007;     for (const pair<int, int> edge : connections[node]) {       pair<long long, long long> curr = needed(edge.first);       if (curr.first > 0 || curr.first == 0 && curr.second >= 0) {         curr.first *= edge.second;         curr.second *= edge.second;       }       temp += curr.second;       temp2 += temp / 1000000007;       temp %= 1000000007;       temp2 += curr.first;     }     return make_pair(temp2, temp);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < (n); i++) cin >> b[i];     for (int i = 0; i < (n); i++) cin >> a[i];     for (int i = 0; i < (n - 1); i++) {       int x;       long long k;       cin >> x >> k;       connections[--x].push_back(make_pair(i + 1, k));     }     pair<long long, long long> res = needed(0);     if (res.first <= 0 && res.second <= 0)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0};   int dy[] = {0, 0, 1, -1, 0, 0, 0, 0};   const int inf = 1000000000;   const double eps = 0.000000009;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 7;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int diff = 0;         for (int k = 0; k < 6; k++) {           if (a[i][k] != a[j][k]) diff++;         }         ans = min(ans, (long long)ceil(diff / 2.0));       }     }     cout << ans - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     multiset<long long> s;     long long now = 0;     for (int i = 1; i <= n; i++) {       long long a;       cin >> a;       a -= i;       s.insert(a);       s.insert(a);       now -= a;       long long x = (*s.rbegin());       s.erase(s.find(x));       now += x;     }     cout << now <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;   int n, m;   int u[N], v[N];   vector<int> G[N];   bool check(int m) {     for (int i = 1; i <= n; ++i) G[i].clear();     vector<int> in(n + 1, 0);     for (int i = 1; i <= m; ++i) {       G[u[i]].push_back(v[i]);       ++in[v[i]];     }     queue<int> q;     for (int i = 1; i <= n; ++i)       if (!in[i]) q.push(i);     while (q.size()) {       int u = q.front();       q.pop();       if (q.size()) return false;       for (int v : G[u])         if (--in[v] == 0) q.push(v);     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , u + i, v + i);     int l = 1, r = m;     while (l <= r) {       int m = l + r >> 1;       if (check(m))         r = m - 1;       else         l = m + 1;     }     if (l == m + 1) l = -1;     printf( %d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int MOD = 1e9 + 7;   const int INF = 1e9;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int a[n][m], b[n][m];     vector<int> col[n + m], col2[n + m];     int i, j;     bool ans = true;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> b[i][j];       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         col[i + j].push_back(a[i][j]);         col2[i + j].push_back(b[i][j]);       }     }     for (i = 0; i < (n + m - 1); i++) {       sort(col[i].begin(), col[i].end());       sort(col2[i].begin(), col2[i].end());       if (col[i] != col2[i]) {         ans = false;       }     }     if (ans) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n;   int p[N];   pair<int, int> v[N];   void solve(int nx, int nnx) {     int curr = 1;     for (int i = 1; i <= n; i++) p[i] = 0;     p[curr] = nx;     p[nx] = nnx;     curr = nx;     bool okay = true;     for (int i = 2; i <= n; i++) {       if (v[curr].first == nnx) {         if (!p[nnx]) p[nnx] = v[curr].second;         nx = nnx;         nnx = v[curr].second;         curr = nx;       } else if (v[curr].second == nnx) {         if (!p[nnx]) p[nnx] = v[curr].first;         nx = nnx;         nnx = v[curr].first;         curr = nx;       } else {         okay = false;         break;       }     }     curr = 1;     for (int i = 1; i <= n; i++) {       curr = p[curr];     }     if (curr != 1) okay = false;     if (okay) {       curr = 1;       for (int i = 1; i <= n; i++) {         printf( %d  , curr);         curr = p[curr];       }       exit(0);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[i].first = x;       v[i].second = y;     }     solve(v[1].first, v[1].second);     solve(v[1].second, v[1].first);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tmp = 3;     int x = 1, y = 2;     int n;     cin >> n;     bool flag = true;     for (int i = 1; i <= n; i++) {       int q;       cin >> q;       if (q == tmp) {         flag = false;       }       if (q == x)         swap(tmp, y);       else         swap(tmp, x);     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[1000005];   int fnd(int x) { return p[x] = p[x] == x ? x : fnd(p[x]); }   void unn(int x, int y) { p[fnd(y)] = fnd(x); }   int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; }   int pq[5144];   vector<int> pr;   int net[100005];   int a[100005];   int main() {     int n;     scanf( %d , &n);     if (n == 1) return printf( 1 n ), 0;     for (int i = 2; i <= 10000; i++) {       if (net[i]) continue;       pr.push_back(i);       for (int j = i * i; j <= 100000; j += i) net[j] = 1;     }     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       int mx = 0;       for (int j = 0; j < pr.size(); j++) {         if (a[i] % pr[j] == 0) {           mx = max(mx, pq[j]);         }       }       for (int j = 0; j < pr.size(); j++) {         if (a[i] % pr[j] == 0) {           pq[j] = max(mx + 1, pq[j]);         }       }     }     int mx = 1;     for (int i = 0; i < pr.size(); i++) mx = max(mx, pq[i]);     printf( %d , mx);   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 305;   const long long mode = 1e9 + 7;   const long long maxm = 1e5 + 10;   long long n, q, t, w[maxn], fa[maxn], nw[maxn], dp[maxm], son[maxn], z[maxn],       cur, ww[maxn];   long long u, v;   signed main() {     cin >> n >> q >> t;     for (long long i = 1; i <= n; ++i) cin >> w[i];     bool juge = true;     while (q--) {       cin >> u >> v;       if (fa[u] == v) {         juge = false;       }       fa[v] = u;       son[u] = v;     }     if (!juge) {       cout << 0;       return 0;     }     for (long long i = 1; i <= n; ++i) {       if (fa[i] == 0 && son[i]) {         long long sum = 0;         long long now = i;         while (now) {           ww[now] = sum + w[now];           nw[now] = nw[fa[now]] + sum + w[now];           sum += w[now];           now = son[now];         }       }       if (fa[i] == 0 && son[i] == 0) nw[i] = ww[i] = w[i];       if (son[i] == 0 && fa[i]) {         z[++cur] = i;       }     }     long long sum = 0;     for (long long i = 1; i <= n; ++i) {       if (son[i] == 0 && fa[i]) {         long long temp = 0, now = i;         while (now) {           temp += w[now];           now = fa[now];         }         sum += nw[i] - temp;       }     }     if (sum > t) {       cout << 0;       return 0;     } else if (sum == t) {       cout << 1;       return 0;     }     dp[sum] = 1;     for (long long i = 1; i <= n; ++i) {       for (long long j = ww[i]; j <= t; ++j) {         if (dp[j - ww[i]]) dp[j] += dp[j - ww[i]];         dp[j] %= mode;       }     }     cout << dp[t];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   int N, M, S;   vector<pair<int, int> > b;   vector<pair<pair<int, int>, int> > s;   vector<pair<int, int> > b2;   vector<pair<pair<int, int>, int> > s2;   int ans[MAX_N + 1];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   bool chk(int x) {     long long cost = 0;     while (!b.empty()) b.pop_back();     while (!s.empty()) s.pop_back();     for (int i = 0; i < b2.size(); i++) {       b.push_back(b2[i]);     }     for (int i = 0; i < s2.size(); i++) {       s.push_back(s2[i]);     }     while (!pq.empty()) pq.pop();     while (!b.empty()) {       while (!s.empty() && s.back().first.first >= b.back().first) {         pq.push({s.back().first.second, s.back().second});         s.pop_back();       }       if (pq.empty()) {         return false;       }       pair<int, int> now = pq.top();       pq.pop();       cost += (long long)now.first;       for (int i = 0; i < x; i++) {         if (b.empty()) break;         pair<int, int> p = b.back();         b.pop_back();         ans[p.second] = now.second;       }     }     return cost <= (long long)S;   }   int main() {     scanf( %d%d%d , &N, &M, &S);     for (int i = 0; i < M; i++) {       int x;       scanf( %d , &x);       b2.push_back({x, i});     }     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       s2.push_back({{x, 0}, i});     }     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       s2[i].first.second = x;     }     sort(b2.begin(), b2.end());     sort(s2.begin(), s2.end());     int st = 0, ed = 100000, m;     while (st < ed) {       m = (st + ed) / 2;       if (chk(m))         ed = m;       else         st = m + 1;     }     if (chk(st)) {       printf( YES n );       for (int i = 0; i < M; i++) {         printf( %d  , ans[i] + 1);       }     } else {       printf( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool yes;   int t, n, m, len, l, sender[105];   map<string, int> msi;   map<int, string> mis;   string str, user[105], text[105];   set<int> mention[105];   int ans[105];   int dp[105][105];   char c;   bool solve(int pos, int idx) {     if (pos == m) return 1;     if (dp[pos][idx] != -1) return dp[pos][idx];     if (mention[pos].find(idx) != mention[pos].end()) return 0;     dp[pos][idx] = 0;     if (pos + 1 < m && sender[pos + 1] != -1) {       if (idx == sender[pos + 1]) return 0;       dp[pos][idx] = solve(pos + 1, sender[pos + 1]);     } else {       for (int i = 0; i < n; ++i) {         if (i != idx) {           dp[pos][idx] |= solve(pos + 1, i);           if (dp[pos][idx]) break;         } else if (pos == m - 1)           dp[pos][idx] = true;       }     }     if (dp[pos][idx]) ans[pos] = idx;     return dp[pos][idx];   }   int main() {     scanf( %d%c , &t, &c);     while (t--) {       scanf( %d%c , &n, &c);       memset(sender, -1, sizeof sender);       memset(dp, -1, sizeof dp);       for (int i = 0; i < n; ++i) {         cin >> user[i];         msi[user[i]] = i;         mis[i] = user[i];       }       scanf( %d%c , &m, &c);       for (int i = 0; i < m; ++i) {         getline(cin, str,  : );         if (str.compare( ? ) == 0)           sender[i] = -1;         else           sender[i] = msi[str];         getline(cin, text[i]);       }       for (int i = 0; i < m; ++i) {         len = text[i].size();         for (int j = 0; j < n; ++j) {           l = user[j].size();           yes = false;           for (int k = 0; k < len; ++k) {             if (text[i][k] == user[j][0] && k + l - 1 < len &&                 text[i].compare(k, l, user[j]) == 0) {               if (((k - 1 >= 0 && text[i][k - 1] !=  .  &&                     text[i][k - 1] !=  ,  && text[i][k - 1] !=  !  &&                     text[i][k - 1] !=  ?  && text[i][k - 1] !=    ) ||                    (k + l < len && text[i][k + l] !=  .  &&                     text[i][k + l] !=  ,  && text[i][k + l] !=  !  &&                     text[i][k + l] !=  ?  && text[i][k + l] !=    ))) {               } else {                 yes = true;                 break;               }             }           }           if (yes) mention[i].insert(msi[user[j]]);         }       }       l = 0;       if (sender[0] != -1)         l |= solve(0, sender[0]);       else {         for (int i = 0; i < n; ++i) {           l |= solve(0, i);           if (l) break;         }       }       if (!l)         cout <<  Impossible  << endl;       else {         for (int i = 0; i < m; ++i) {           cout << user[ans[i]] <<  :  << text[i] << endl;         }       }       msi.clear(), mis.clear();       for (int i = 0; i < m; ++i) mention[i].clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), b(n);       for (auto &it : a) cin >> it;       for (auto &it : b) cin >> it;       int mna = *min_element(a.begin(), a.end());       int mnb = *min_element(b.begin(), b.end());       long long ans = 0;       for (int i = 0; i < n; ++i) {         ans += max(a[i] - mna, b[i] - mnb);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1050;   int s[maxn][maxn];   int main(int argc, char const *argv[]) {     int n, a, b;     cin >> n >> a >> b;     if (a != 1 && b != 1) {       printf( NO n );       return 0;     }     if (n == 1) {       printf( YES n0 n );       return 0;     }     if (a == 1 && b == 1 && n <= 3) {       printf( NO n );       return 0;     }     printf( YES n );     if (a == 1 && b == 1) {       for (int i = 1; i < n; ++i) {         s[i][i + 1] = s[i + 1][i] = 1;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           printf( %d , s[i][j]);         }         printf(  n );       }     } else if (a == 1) {       for (int i = b; i <= n; ++i) {         for (int j = b; j <= n; ++j) {           s[i][j] = 1;         }       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           s[i][j] = 1 - s[i][j];         }         s[i][i] = 0;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           printf( %d , s[i][j]);         }         printf(  n );       }     } else {       for (int i = a; i <= n; ++i) {         for (int j = a; j <= n; ++j) {           s[i][j] = 1;         }       }       for (int i = 1; i <= n; ++i) s[i][i] = 0;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           printf( %d , s[i][j]);         }         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   template <typename T>   T power(T x, T y, T mod) {     T res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y /= 2;       x = (x * x) % mod;     }     return res;   }   using namespace std;   long long int a[2005][2005];   long long int d1[4005];   long long int d2[4005];   long long int ele[2005][2005];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++)       for (long long int j = 0; j < n; j++) cin >> a[i][j];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) {         long long int b = a[i][j];         d1[j - i + n] += b;         d2[n + n - i - j - 1] += b;       }     }     long long int max1 = 0;     long long int max2 = 0;     long long int x1, y1, x2, y2;     x1 = 1;     x2 = 1;     y1 = 1;     y2 = 2;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) {         ele[i][j] = d1[j - i + n] + d2[2 * n - i - j - 1] - a[i][j];         if ((i + j) % 2) {           if (max1 < ele[i][j]) {             max1 = ele[i][j];             x1 = i + 1;             y1 = j + 1;           }         } else {           if (max2 < ele[i][j]) {             max2 = ele[i][j];             x2 = i + 1;             y2 = j + 1;           }         }       }     }     cout << max1 + max2 <<   n ;     cout << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1005], b[1005];   int main() {     bool same = 1;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , a + i, b + i);       same &= a[i] == b[i];     }     if (!same) {       puts( rated );       return 0;     }     for (int i = 2; i <= n; ++i) {       if (a[i] > a[i - 1]) {         puts( unrated );         return 0;       }     }     puts( maybe );     return 0;   }