malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int matrix[n][n], sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> matrix[i][j];       }     }     int j = 0;     for (int i = 0; i < n; i++) {       sum += matrix[i][i];     }     for (int i = n - 1; i >= 0; i--) {       sum += matrix[i][j];       j++;     }     int ind = (n - 1) / 2;     for (auto it : matrix) sum += it[ind];     for (int i = 0; i < n; i++) sum += matrix[ind][i];     cout << sum - (3 * matrix[ind][ind]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[3][3];   int main() {     int p = 1;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) cin >> a[i][j];     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         if (a[0][0] != a[2][2] || a[0][1] != a[2][1] || a[0][2] != a[2][0] ||             a[1][0] != a[1][2])           p = 0;       }     if (p)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[123000];   int n, m;   long long d, k, a, b, t;   void input() {}   void solve() {     long long ans = 0;     if (d <= k) {       ans = (long long)a * (long long)d;       printf( %lld n , ans);       return;     }     d -= k;     ans += (long long)a * (long long)k;     long long i = (long long)(a - b) * (long long)k + (long long)t;     if (i >= 0) {       ans += (long long)b * (long long)d;     } else {       long long x = d / k;       long long s = (long long)d - x * (long long)k;       long long j1 = x * i + (long long)b * (long long)d;       long long j2 = ((long long)a * (long long)k + (long long)t) * x +                      (long long)t + (long long)a * s;       ans += j1 < j2 ? j1 : j2;     }     printf( %lld n , ans);   }   int main() {     while (scanf( %lld %lld %lld %lld %lld , &d, &k, &a, &b, &t) != EOF) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   #define LL long long   #define PII pair<int, int>   #define PLL pair<LL, LL>   #define all_of(v) (v).begin(), (v).end()   #define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))   #define fi first   #define se second   const int MAXN = 401;   //const LL INF = (LL) 1e9 + 8763;   //const LL MOD = (LL) 1e9 + 7;   using namespace std;   const LL MOD = 998244353;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      LL n, cnt[26], dall[MAXN], dp1[MAXN][MAXN][2], dp2[2][MAXN][MAXN][3], have[MAXN];      void solve() {    cin >> n;    for (int i = 0; i < 26; i++) {     cin >> cnt[i];    }        int a = n / 2, b = n - a;    for (int i = 1; i <= n; i++) {     have[i] = 1;    }    have[a] = have[n] = 0;        // [pos][used 0][used 1][last]    dall[1] = 1;    dp1[1][1][0] = 1;    dp1[1][0][1] = 1;    dp2[1][0][0][2] = 1;    dp2[1][0][1][1] = 1;    dp2[1][1][0][0] = 1;        // 2    for (int i = 2; i <= n; i++) {     for (int u0 = 0; u0 <= i; u0++) {      for (int u1 = 0; u1 <= i; u1++) {       for (int last = 0; last < 3; last++) {        LL &now = dp2[i % 2][u0][u1][last];        now = 0;        if (last == 0 && u0 == 0) continue;        if (last == 1 && u1 == 0) continue;        if (!have[i - 1] || last != 0) {         now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][0]) % MOD;        }        if (!have[i - 1] || last != 1) {         now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][1]) % MOD;        }        LL coe = 23 + (!have[i - 1] || last != 2);        now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][2] * coe) % MOD;       }      }     }    }    // 1    for (int i = 2; i <= n; i++) {     for (int u0 = 0; u0 <= i; u0++) {      for (int last = 0; last < 2; last++) {       if (last == 0 && u0 == 0) continue;       LL &now = dp1[i][u0][last];       if (!have[i - 1] || last != 0) {        now = (now + dp1[i - 1][u0 - (last == 0)][0]) % MOD;       }       LL coe = 24 + (!have[i - 1] || last != 1);       now = (now + dp1[i - 1][u0 - (last == 0)][1] * coe) % MOD;      }     }    }    // 0    for (int i = 2; i <= n; i++) {     LL coe = 25 + !have[i - 1];     dall[i] = (dall[i - 1] * coe) % MOD;    }        LL tot = dall[n] * 26 % MOD;    for (int t0 = 0; t0 < 26; t0++) {     for (int u0 = cnt[t0] + 1; u0 <= n; u0++) {      tot = (tot - dp1[n][u0][0] - dp1[n][u0][1] * 25) % MOD;     }    }    for (int t0 = 0; t0 < 26; t0++) {     for (int t1 = t0 + 1; t1 < 26; t1++) {      for (int u0 = cnt[t0] + 1; u0 <= n; u0++) {       for (int u1 = cnt[t1] + 1; u1 <= n; u1++) {        tot = (tot + dp2[n % 2][u0][u1][0] + dp2[n % 2][u0][u1][1] + dp2[n % 2][u0][u1][2] * 24) % MOD;       }      }     }    }        cout << (tot % MOD + MOD) % MOD <<   n ;   }      int main() {    ios_base::sync_with_stdio(0); cin.tie(0);       int tc = 1;   // cin >> tc;    for (int i = 1; i <= tc; i++) {     solve();    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string a, b, c;       cin >> a >> b >> c;       int i = 0, flag = 0;       for (; i < a.size(); i++) {         if ((a[i] == c[i] || b[i] == c[i]) || (a[i] == c[i] && b[i] == c[i])) {           flag = 0;         } else {           flag = 1;           break;         }       }       if (flag == 0) {         cout <<  YES n ;       } else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long A[100000 + 8], mark[20 + 8];   long long result = 0;   long long getC(int n, int k) {     if (n < k) return 0;     if (n == k) return 1;     long long result = 1;     for (long long i = max(k, n - k) + 1; i <= n; i++) result *= i;     return result / min(k, n - k);   }   int main() {     memset(mark, 0, sizeof mark);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       mark[A[i] + 10]++;     }     for (int i = 0; i <= 9; i++) result += mark[i] * mark[20 - i];     result += getC(mark[10], 2);     cout << result << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, ans, kiri, kanan, sum, i, pos;   long long a[300007], dua[300007];   int main() {     scanf( %lld , &n);     dua[0] = 1;     for (i = 1; i <= 300000; i++) dua[i] = (dua[i - 1] * 2) % 1000000007;     x = 1;     scanf( %lld , &a[0]);     pos = -1;     for (i = 1; i < n; i++) {       scanf( %lld , &a[i]);       sum = (sum + x) % 1000000007;       x = (x * 2) % 1000000007;       pos++;     }     sort(a, a + n);     kiri = 0;     kanan = n - 1;     x = 1;     while (kiri <= kanan) {       ans = (ans + sum * (a[kanan] - a[kiri])) % 1000000007;       kiri++;       kanan--;       sum = ((sum - x) % 1000000007 + 1000000007) % 1000000007;       sum = ((sum - dua[pos]) % 1000000007 + 1000000007) % 1000000007;       pos--;       x = (x * 2) % 1000000007;     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int middle(int a, int b, int c) {     if ((a <= b && b <= c) || (c <= b && b <= a))       return b;     else if ((b <= a && a <= c) || (c <= a && a <= b))       return a;     else       return c;   }   template <typename KeyType, typename ValueType>   std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) {     using pairtype = std::pair<KeyType, ValueType>;     return *std::max_element(x.begin(), x.end(),                              [](const pairtype &p1, const pairtype &p2) {                                return p1.second < p2.second;                              });   }   static inline bool isvowel(char ch) {     static const std::string vowels( aeiouEAIOU );     return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);   }   template <typename Map>   bool map_compare(Map const &lhs, Map const &rhs) {     return lhs.size() == rhs.size() &&            std::equal(lhs.begin(), lhs.end(), rhs.begin());   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, g, b;       cin >> n >> g >> b;       long long mid = (n + 1) / 2;       long long ans = ((mid - 1) / g) * (g + b);       if (mid % g == 0)         ans += g;       else         ans += (mid % g);       cout << max(ans, n) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     for (int z = 1; z <= t; z++) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       int res = n;       for (int i = 1; i < n; i++) {         if (a[i] != a[i + 1]) {           res = 1;           break;         }       }       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   pair<int, int> best;   map<pair<int, int>, int> visited, mark;   void dfs(int i, int x, int y) {     if (i == n) {       return;     }     if (mark[make_pair(x, y)] == 0) {       mark[make_pair(x, y)] = 1;       visited[make_pair(x, y)] = i;       pair<int, int> move;       if (s[i] ==  L ) {         dfs(i + 1, x, y - 1);         move = {0, -1};       } else if (s[i] ==  R ) {         dfs(i + 1, x, y + 1);         move = {0, 1};       } else if (s[i] ==  U ) {         dfs(i + 1, x - 1, y);         move = {-1, 0};       } else if (s[i] ==  D ) {         dfs(i + 1, x + 1, y);         move = {1, 0};       }       if (visited.count({x + move.first, y + move.second})) {         auto val = visited[make_pair(x + move.first, y + move.second)];         cerr <<  found cycle   << val << endl;         if (i - val < best.second) {           best.first = val;           best.second = i - val;         }       }     }     visited.erase(visited.find(make_pair(x, y)));   }   void solve() {     cin >> n >> s;     best = {-1, 1e9};     map<pair<int, int>, int> seen;     pair<int, int> was = {0, 0};     seen[was] = 0;     for (int i = 1; i <= n; ++i) {       if (s[i - 1] ==  L )         was.second--;       else if (s[i - 1] ==  R )         was.second++;       else if (s[i - 1] ==  U )         was.first--;       else if (s[i - 1] ==  D )         was.first++;       if (seen.count(was)) {         auto index = seen[was];         int length = i - index;         if (best.second > length) {           best.first = index;           best.second = length;         }       }       seen[was] = i;     }     if (best.first == -1) {       cout << -1 << endl;     } else {       cout << best.first + 1 <<     << best.first + best.second << endl;     }   }   int main() {     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, t;     cin >> n;     vector<long long> adj[n + 1];     vector<long long> par(n + 1, 0);     for (i = 2; i <= n; i++) {       cin >> k;       par[i] = k;       adj[k].push_back(i);     }     vector<long long> level(n + 1, 0);     level[1] = 0;     queue<long long> q;     q.push(1);     vector<bool> vis;     long long maxim = INT_MIN;     while (!q.empty()) {       long long u = q.front();       q.pop();       for (j = 0; j < adj[u].size(); j++) {         level[adj[u][j]] = level[u] + 1;         maxim = max(level[u] + 1, maxim);         q.push(adj[u][j]);       }     }     vector<long long> maxiy[maxim + 1];     for (j = 1; j <= n; j++) {       k = level[j];       maxiy[k].push_back(j);     }     vector<long long> ans(maxim + 1, 1);     k = 0;     for (j = maxim; j >= 0; j--) {       k += maxiy[j].size() % 2;     }     cout << k << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A, D, C;   vector<int> atk, def, ciel;   bool used[110];   int partial(void) {     int N = min(A, C), i, ans = 0;     for ((i) = 0; (i) < (int)(N); (i)++)       if (atk[i] < ciel[C - 1 - i]) ans += ciel[C - 1 - i] - atk[i];     return ans;   }   int search(int x) {     int i;     for ((i) = 0; (i) < (int)(C); (i)++)       if (ciel[i] >= x && !used[i]) {         used[i] = true;         return i;       }     return -1;   }   int all(void) {     int i, defsum = 0;     for ((i) = 0; (i) < (int)(D); (i)++) {       int x = search(def[i] + 1);       if (x == -1) return 0;       defsum += ciel[x];     }     for ((i) = 0; (i) < (int)(A); (i)++) {       int x = search(atk[i]);       if (x == -1) return 0;     }     int ans = 0;     for ((i) = 0; (i) < (int)(C); (i)++) ans += ciel[i];     for ((i) = 0; (i) < (int)(A); (i)++) ans -= atk[i];     ans -= defsum;     return ans;   }   int main(void) {     int N, i, x;     cin >> N >> C;     for ((i) = 0; (i) < (int)(N); (i)++) {       string type;       cin >> type >> x;       if (type ==  ATK )         atk.push_back(x);       else         def.push_back(x);     }     for ((i) = 0; (i) < (int)(C); (i)++) {       cin >> x;       ciel.push_back(x);     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(ciel.begin(), ciel.end());     A = atk.size();     D = def.size();     int ans1 = partial();     int ans2 = all();     cout << max(ans1, ans2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, i, j, a[2 * 100010];   vector<char> ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long l = 1, r = n, f = -1e18;     while (l <= r) {       if (f >= a[l] && f >= a[r]) break;       if (a[l] <= f && f < a[r]) {         ans.push_back( R );         f = a[r];         r--;         continue;       }       if (a[l] > f && f >= a[r]) {         ans.push_back( L );         f = a[l];         l++;         continue;       }       if (a[l] < a[r]) {         ans.push_back( L );         f = a[l];         l++;       } else {         if (a[l] > a[r]) {           ans.push_back( R );           f = a[r];           r--;         } else {           int k1 = 0, k2 = 0;           for (int j = l + 1; j <= r; j++) {             if (a[j] > a[j - 1])               k1++;             else               break;           }           for (int j = r - 1; j >= l; j--) {             if (a[j] > a[j + 1])               k2++;             else               break;           }           if (k1 > k2) {             ans.push_back( L );             for (int j = l + 1; j <= r; j++) {               if (a[j] > a[j - 1])                 ans.push_back( L );               else                 break;             }           } else {             ans.push_back( R );             for (int j = r - 1; j >= l; j--) {               if (a[j] > a[j + 1])                 ans.push_back( R );               else                 break;             }           }           break;         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i];     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> d[256];   int mask[256];   vector<int> q;   bool b[256];   bool good[256];   int kd[256];   vector<int> g;   vector<pair<pair<int, int>, pair<int, int> > > res;   int n;   int need;   void Debug(vector<int> A) {     for (int i = 0; i < A.size(); i++) {       printf( %d  , A[i]);     }     puts(  );   }   int read() {     char ch =    ;     int x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x;   }   void Init() {     n = read();     for (int i = 0; i < n; i++) {       int x = read();       need = need | (1 << x);       b[x] = true;     }     if (n > 6) {       puts( 0 );       exit(0);     }     for (int i = 255; i >= 0; i--) {       good[i] = true;       int x = i;       mask[i] = 0;       while (x > 0) {         mask[i] = mask[i] | (1 << (x % 10));         if (!b[x % 10]) good[i] = false;         d[i].push_back(x % 10);         x = x / 10;       }       if (i == 0 and !b[i]) good[i] = false;       if (i == 0) {         d[i].push_back(0);         mask[i] = mask[i] | 1;       }       if (good[i]) g.push_back(i);     }   }   void Solve() {     for (int x = 0; x < 256; x++) {       if (good[x]) {         for (int y = 0; y < 256; y++) {           if (good[y]) {             for (int w = 0; w < 256; w++) {               if (good[w]) {                 if ((mask[x] | mask[y] | mask[w]) != need) continue;                 for (int z = 0; z < 256; z++) {                   if (good[z]) {                     q.clear();                     for (int i = d[x].size() - 1; i >= 0; i--)                       q.push_back(d[x][i]);                     for (int i = d[y].size() - 1; i >= 0; i--)                       q.push_back(d[y][i]);                     for (int i = d[w].size() - 1; i >= 0; i--)                       q.push_back(d[w][i]);                     for (int i = d[z].size() - 1; i >= 0; i--)                       q.push_back(d[z][i]);                     bool ok = true;                     for (int i = 0; i < q.size(); i++) {                       if (q[i] != q[q.size() - 1 - i]) {                         ok = false;                         break;                       }                     }                     if (ok)                       res.push_back(make_pair(make_pair(x, y), make_pair(w, z)));                   }                 }               }             }           }         }       }     }   }   void Print() {     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++) {       printf( %d.%d.%d.%d n , res[i].first.first, res[i].first.second,              res[i].second.first, res[i].second.second);     }   }   int main() {     Init();     Solve();     Print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct SUBS {     string _s;     int l, r;     SUBS() {}     SUBS(string s, int l, int r) : _s(s), l(l), r(r) {}     bool operator<(const SUBS& subs) const { return _s > subs._s; }   };   priority_queue<SUBS> pq;   string s;   long long n, k;   int main() {     cin >> s;     cin >> k;     n = s.length();     if (2 * k > n * (n + 1)) {       cout <<  No such line.  << endl;       return 0;     }     for (int i = 0; i < n; i++) pq.push(SUBS(s.substr(i, 1), i, i + 1));     SUBS subs;     for (int i = 0; i < k; i++) {       subs = pq.top();       pq.pop();       if (subs.r < n) {         int len = subs.r - subs.l;         pq.push(SUBS(s.substr(subs.l, len + 1), subs.l, subs.r + 1));       }     }     cout << subs._s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   bool use[26];   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     string s;     getline(cin, s);     bool ok = 1;     for (int i = int(0); i < int(((int)(s).size())); ++i) {       int idx = s[i] -  a ;       if (idx > 0) {         if (!use[idx - 1]) {           ok = 0;         }       }       use[idx] = 1;     }     if (!ok) {       puts( NO );     } else {       puts( YES );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     long long zero = 0;     cin >> n >> m >> k;     long long x, s;     cin >> x >> s;     long long a[m], b[m], c[k], d[k];     long long i, j;     long long ans = n * x;     for (i = 0; i < m; i++) {       cin >> a[i];     }     for (i = 0; i < m; i++) {       cin >> b[i];       if (b[i] <= s) {         ans = min(ans, n * a[i]);       }     }     for (i = 0; i < k; i++) {       cin >> c[i];     }     for (i = 0; i < k; i++) {       cin >> d[i];       if (d[i] <= s) {         ans = min(ans, x * max(zero, n - c[i]));       }     }     for (i = 0; i < m; i++) {       if (b[i] <= s) {         long long p = s - b[i];         auto it = upper_bound(d, d + k, p);         if (it != d) {           it--;         } else {           continue;         }         long long reduce = c[it - d];         reduce = min(n, reduce);         long long temp = (n - reduce) * a[i];         ans = min(ans, temp);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     getline(cin, x);     sort(x.begin(), x.end());     int res = unique(x.begin(), x.end()) - x.begin();     if (res % 2 == 0) {       cout <<  CHAT WITH HER! ;     } else {       cout <<  IGNORE HIM! ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Min(int aa, int bb) { return aa < bb ? aa : bb; }   int Max(int aa, int bb) { return aa > bb ? aa : bb; }   struct hh {     int aaa, bbb;   } cc[200005];   char ss[200005];   bool cmp(hh xa, hh ya) { return xa.aaa < ya.aaa; };   int main() {     int n, a[200005], cnt = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %s , ss);     for (int i = 1; i <= n; i++)       if (a[i] != i) {         cc[++cnt].aaa = Min(i, a[i]);         cc[cnt].bbb = Max(i, a[i]);       }     int lst = 0;     sort(cc + 1, cc + 1 + cnt, cmp);     for (int i = 1; i <= cnt; i++) {       lst = Max(lst, cc[i].aaa);       for (; lst < cc[i].bbb; lst++) {         if (ss[lst - 1] ==  0 ) {           printf( NO );           return 0;         }       }     }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int sum = 0;       vector<long long> a(n + 1, 0);       long long odd = -1;       for (int i = 1; i <= n; i++) {         cin >> a[i];         sum += a[i];         if (a[i] & 1) odd = i;       }       if (isPrime(sum)) {         cout << n - 1 << endl;         for (int i = 1; i <= n; i++) {           if (i == odd) continue;           cout << i <<    ;         }         cout << endl;       } else {         cout << n << endl;         for (int i = 1; i <= n; i++) {           cout << i <<    ;         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, i;     cin >> r >> c;     string s;     int R[11] = {0}, C[11] = {0};     for (i = 0; i < r; ++i) {       cin >> s;       for (int j = 0; j < c; ++j) {         if (s[j] ==  S ) {           R[i] = 1;           C[j] = 1;         }       }     }     int count = 0;     for (i = 0; i < r; ++i) {       for (int j = 0; j < c; ++j) {         if (R[i] == 0 || C[j] == 0) {           count += 1;         }       }     }     cout << count;     return 0;   }