malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long HASH = 1e16 + 7;   const long long INF = 1e9;   long long tavan(long long a, long long b) {     return b ? (tavan(a * a, b >> 1) * (b & 1 ? a : 1)) : 1;   }   long long gcd(long long a, long long b) {     return (a < b) ? gcd(b, a) : ((a % b == 0) ? b : gcd(b, a % b));   }   bool isprime(long long x) {     for (long long i = 2; i <= sqrt(x); i++)       if (!(x % i)) return false;     return true;   }   ifstream fin( input.txt );   ofstream fout( output.txt );   long long n, a[1100];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int t = 0; t < n + 1000; t++) {       bool ex = 1;       for (int i = 0; i < n; i++) {         if (i % 2 == 0)           a[i]++;         else           a[i]--;         if (a[i] == n) a[i] = 0;         if (a[i] == -1) a[i] = n - 1;         if (a[i] != i) ex = 0;       }       if (ex) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxl = 26;   const int Maxn = 30005;   const int Maxstr = 200005;   const int Inf = 2000000007;   char str[Maxstr];   int t;   int n, m, k;   int freq[Maxl];   bool dp[Maxn];   int res;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       scanf( %s , str);       fill(freq, freq + Maxl, 0);       for (int i = 0; i < k; i++) freq[str[i] -  A ]++;       res = Inf;       int mx = max(n, m);       for (int i = 0; i < Maxl; i++) {         int tot = 0;         for (int j = 0; j < Maxl; j++)           if (j != i) tot += freq[j];         int mn = tot;         fill(dp, dp + mx + 1, false);         dp[0] = true;         for (int j = 0; j < Maxl; j++)           if (j != i)             for (int l = mx; l >= 0; l--)               if (dp[l])                 if (l + freq[j] > mx)                   mn = min(mn, l + freq[j]);                 else                   dp[l + freq[j]] = true;         for (int l = 0; l <= mx; l++)           if (dp[l]) {             int a = l, b = tot - l;             int mya = max(0, n - a), myb = max(0, m - b);             if (mya + myb <= freq[i]) res = min(res, mya * myb);             mya = max(0, n - b), myb = max(0, m - a);             if (mya + myb <= freq[i]) res = min(res, mya * myb);           }         int a = mn, b = tot - mn;         int mya = max(0, n - a), myb = max(0, m - b);         if (mya + myb <= freq[i]) res = min(res, mya * myb);         mya = max(0, n - b), myb = max(0, m - a);         if (mya + myb <= freq[i]) res = min(res, mya * myb);       }       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace {   void Solve(int) {     const set<string> bins = { AND ,  OR ,  XOR };     int n;     cin >> n;     vector<string> type(n);     vector<int> lef(n, -1), rig(n, -1);     for (int i = 0, __i = n; i < __i; ++i) {       cin >> type[i] >> lef[i];       if (type[i] !=  IN ) --lef[i];       if (bins.count(type[i])) {         cin >> rig[i];         --rig[i];       }     }     auto eval = [](const string& t, bool a, bool b) {       if (t ==  AND )         return a and b;       else if (t ==  OR )         return a or b;       else         return (bool)(a ^ b);     };     vector<bool> val(n), flip(n);     function<void(int)> dfs1 = [&](int at) {       if (type[at] ==  IN ) {         val[at] = lef[at];       } else {         dfs1(lef[at]);         if (bins.count(type[at])) {           dfs1(rig[at]);           val[at] = eval(type[at], val[lef[at]], val[rig[at]]);         } else {           val[at] = !val[lef[at]];         }       }     };     dfs1(0);     function<void(int)> dfs2 = [&](int at) {       if (type[at] ==  IN )         flip[at] = true;       else if (type[at] ==  NOT ) {         flip[at] = true;         dfs2(lef[at]);       } else {         if (val[at] != eval(type[at], val[lef[at]] ^ 1, val[rig[at]])) {           flip[at] = true;           dfs2(lef[at]);         }         if (val[at] != eval(type[at], val[lef[at]], val[rig[at]] ^ 1)) {           flip[at] = true;           dfs2(rig[at]);         }       }     };     dfs2(0);     for (int i = 0, __i = n; i < __i; ++i)       if (type[i] ==  IN ) cout << (val[0] ^ flip[i]);     cout <<   n ;   }   void Init() {     ios::sync_with_stdio(false);     cin.tie(nullptr);   }   }  // namespace   int32_t main() {     Init();     int tests = 1;     for (int test = 1, __test = tests + 1; test < __test; ++test) Solve(test);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000 + 1;   const int INF = numeric_limits<int>::max() / 2;   pair<int, int> P[MAX_N];   pair<int, int> prefix[MAX_N], suffix[MAX_N];   int N;   long long square(int first) { return 1LL * first * first; }   bool valid(long long M) {     long long bestY, bestXY;     int i = 1, j = 1;     while (i <= N) {       while (square(P[i].first - P[j].first) > M) j++;       assert(j <= i);       assert(square(P[i].first - P[j].first) <= M);       int maxY = -INF;       int minY = INF;       bool changed = false;       if (j > 1) {         changed = true;         minY = min(minY, prefix[j - 1].first);         maxY = max(maxY, prefix[j - 1].second);       }       if (i < N) {         changed = true;         minY = min(minY, suffix[i + 1].first);         maxY = max(maxY, suffix[i + 1].second);       }       if (changed) {         bestY = square(maxY - minY);         bestXY = max(square(maxY), square(minY)) +                  max(square(P[i].first), square(P[j].first));       } else         bestY = 0, bestXY = 0;       if (bestY <= M && bestXY <= M) return true;       i++;     }     return false;   }   void makePrefixSuffix() {     pair<int, int> p = {INF, -INF};     for (int i = 1; i <= N; ++i) {       p.first = min(p.first, P[i].second);       p.second = max(p.second, P[i].second);       prefix[i] = p;     }     p = {INF, -INF};     for (int i = N; i >= 1; i--) {       p.first = min(p.first, P[i].second);       p.second = max(p.second, P[i].second);       suffix[i] = p;     }   }   long long binarySearch() {     long long l = 0;     long long r = 1LL * INF * INF >> 1;     long long sol = -1;     while (l <= r) {       long long m = (l + r) / 2;       if (valid(m)) {         sol = m;         r = m - 1;       } else         l = m + 1;     }     return sol;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N;     for (int i = 1; i <= N; ++i) cin >> P[i].first >> P[i].second;     sort(P + 1, P + N + 1);     makePrefixSuffix();     long long sol1 = binarySearch();     for (int i = 1; i <= N; ++i) swap(P[i].first, P[i].second);     sort(P + 1, P + N + 1);     makePrefixSuffix();     long long sol2 = binarySearch();     cout << min(sol1, sol2) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a[100010];   int y[100010], res[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int num;       scanf( %d%d , &num, &y[i]);       res[i] = 0;       for (int k = 1; k * k <= num; k++)         if (num % k == 0) {           a[k].push_back(i);           res[i]++;           if (k * k != num) {             a[num / k].push_back(i);             res[i]++;           }         }     }     for (int i = 1; i <= 100000; i++)       for (int j = 1; j < a[i].size(); j++)         if (a[i][j] - a[i][j - 1] <= y[a[i][j]]) res[a[i][j]]--;     for (int i = 0; i < n; i++) printf( %d n , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Inf = 1e9 + 7;   int dp[107][107];   int par[107][107];   string t =  .,!?  ;   bool check(char c) { return t.find(c) == string::npos; }   void solve() {     int t;     cin >> t;     for (int k = 0; k < t; k++) {       int n;       cin >> n;       vector<string> users;       for (int i = 0; i < n; i++) {         string p;         cin >> p;         users.push_back(p);       }       sort(users.begin(), users.end());       map<string, int> id;       for (int i = 0; i < n; i++) id[users[i]] = i;       memset(dp, 0, sizeof(dp));       for (int i = 0; i < n; i++) dp[0][i] = 1;       memset(par, -1, sizeof(par));       int m;       cin >> m;       string buf;       getline(cin, buf);       vector<string> message;       for (int i = 0; i < m; i++) {         string buf;         getline(cin, buf);         int pos = buf.find( : );         string user = buf.substr(0, pos);         string msg = buf.substr(pos + 1);         message.push_back(msg);         vector<string> w;         int p = 0, l = msg.size();         while (p < l) {           while (p < l && !check(msg[p])) p++;           int q = p;           while (q < l && check(msg[q])) q++;           string word = msg.substr(p, q - p);           if (word !=   ) w.push_back(word);           p = q;         }         int uid = id.count(user) == 0 ? -1 : id[user];         if (uid == -1) {           for (int j = 0; j < n; j++) {             if (find(w.begin(), w.end(), users[j]) != w.end()) continue;             for (int jj = 0; jj < n; jj++) {               if (dp[i][jj] == 1 && (i == 0 || j != jj)) {                 dp[i + 1][j] = 1;                 par[i + 1][j] = jj;               }             }           }         } else {           for (int jj = 0; jj < n; jj++) {             if (dp[i][jj] == 1 && (i == 0 || uid != jj)) {               dp[i + 1][uid] = 1;               par[i + 1][uid] = jj;             }           }         }       }       vector<string> res;       for (int i = 0; i < n; i++)         if (dp[m][i] == 1) {           int p = i, q = m;           while (q > 0) {             res.push_back(users[p]);             p = par[q][p];             q--;           }         }       if (res.empty()) {         cout <<  Impossible  <<   n ;       } else {         reverse(message.begin(), message.end());         for (int i = m - 1; i >= 0; --i) {           ostringstream oss;           oss << res[i];           oss <<  : ;           oss << message[i];           cout << oss.str() <<   n ;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(9);     cout << fixed;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long f = 1;     for (long long i = 0; i < 100000; i++) {       n += (n % m);       if (n % m == 0) {         f = 0;         break;       }     }     if (!f)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 2e5;   const long long inf = 1e18;   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   template <typename... T>   void writeline(T&&... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   long long add(long long a, long long b) {     long long res = (a + b) % mod;     return (res < 0) ? res + mod : res;   }   long long mul(long long a, long long b) {     long long res = (a * 1LL * b) % mod;     return (res < 0) ? res + mod : res;   }   string binary(long long x) {     string res =   ;     for (long long i = 0; i < 32; i++) res += (1 << i & x) ?  1  :  0 ;     return res;   }   long long in(long long x, long long y, long long z) {     if (y > z) swap(y, z);     return (x >= y && x <= z);   }   long long valid(long long x, long long sum) {     long long s = 0;     while (x) {       s += x % 10;       x /= 10;     }     return s == sum;   }   void solve() {     long long n;     cin >> n;     if (n == 1) {       cout << -1;       return;     }     writeline(n, n + 1, n * (n + 1));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long data = 0, w = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + ch -  0 , ch = getchar();     return data * w;   }   long long n, c, p[1000005], a[1000005];   int main() {     n = read(), c = read();     for (long long i = 1; i <= n; i++) p[i] = read();     long long sum = 0, ans = 0;     for (long long i = 1; i <= n; i++) {       long long s = read();       a[i] = s - p[i] + c * (n - i);       sum += p[i];     }     ans = sum;     sort(a + 1, a + n + 1);     for (long long i = 1; i <= n; i++)       sum += a[i] - (i - 1) * c, ans = min(ans, sum);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, used[100003], m[100003];   string s, ans =  INFINITE ;   void DFS(int v) {     if (used[v] == 1) {       ans =  INFINITE ;       return;     }     used[v] = 1;     if (s[v] ==  < ) {       if (v - m[v] > 0)         DFS(v - m[v]);       else {         ans =  FINITE ;         return;       }     } else {       if (v + m[v] <= n)         DFS(v + m[v]);       else {         ans =  FINITE ;         return;       }     }   }   int main() {     cin >> n >> s;     s =     + s;     for (int k = 1; k <= n; k++) cin >> m[k];     DFS(1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ll t;     cin >> t;     while (t--) {       ll n, m, k;       cin >> n >> m >> k;       k--;       k--;       if (m > n * (n - 1) / 2 || m < n - 1) {         cout <<  nO  <<   n ;         continue;       }       if (k > 1) {         if (m > n - 2) {           cout <<  yEs  <<   n ;         } else           cout <<  nO  <<   n ;       } else if (k == 1) {         if (m == n * (n - 1) / 2) {           cout <<  yEs  <<   n ;         } else           cout <<  nO  <<   n ;       } else if (k == 0) {         if (n == 1)           cout <<  yEs  <<   n ;         else           cout <<  nO  <<   n ;       } else         cout <<  nO  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 10005;   vector<int> g[M];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         int v = g[i][j];         ans += ((int)g[v].size()) - 1;       }     }     cout << ans / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fac[1000001];   int main() {     long long n, ans = 0, c = 0, mx = 0, tmp, tmp2, lg;     cin >> n;     for (long long i = 2; i < n; i++) {       tmp = n / i;       tmp = tmp * (tmp + 1) / 2 - 1;       ans += (tmp * 4);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int N;   char c[2000000];   int numWays() {     if (N == 1) {       if (c[0] ==  * )         return 1;       else if (c[0] ==  0 )         return 1;       else if (c[0] ==  ? )         return 2;       else         return 0;     }     if (c[0] ==  2 ) return 0;     if (c[N - 1] ==  2 ) return 0;     for (int i = 0; i < N; i++) {       if (c[i] ==  0 ) {         if (i > 0) {           if (c[i - 1] ==  ? )             c[i - 1] =  - ;           else if (c[i - 1] ==  * )             return 0;         }         if (i + 1 < N) {           if (c[i + 1] ==  ? )             c[i + 1] =  - ;           else if (c[i + 1] ==  * )             return 0;         }       }     }     for (int i = 0; i < N; i++) {       int max = (i > 0) + ((i + 1) < N);       if (c[i] ==  0  + max) {         if (i > 0) {           if (c[i - 1] ==  ? )             c[i - 1] =  * ;           else if (c[i - 1] !=  * )             return 0;         }         if (i + 1 < N) {           if (c[i + 1] ==  ? )             c[i + 1] =  * ;           else if (c[i + 1] !=  * )             return 0;         }       }     }     for (int i = 1; i + 1 < N; i++) {       if (c[i] ==  1 ) {         int numq = (c[i - 1] ==  ? ) + (c[i + 1] ==  ? );         int numm = (c[i - 1] ==  * ) + (c[i + 1] ==  * );         int numf = 2 - numm - numq;         if (numq == 0) {           if (numf != 1) return 0;         } else if (numq == 1) {           if (numm == 0) {             if (c[i - 1] ==  ? )               c[i - 1] =  * ;             else if (c[i + 1] ==  ? )               c[i + 1] =  * ;             else               assert(false);           } else if (numm == 1) {             if (c[i - 1] ==  ? )               c[i - 1] =  - ;             else if (c[i + 1] ==  ? )               c[i + 1] =  - ;             else               assert(false);           } else             assert(false);         }       }     }     for (int i = N - 2; i > 0; i--) {       if (c[i] ==  1 ) {         int numq = (c[i - 1] ==  ? ) + (c[i + 1] ==  ? );         int numm = (c[i - 1] ==  * ) + (c[i + 1] ==  * );         int numf = 2 - numm - numq;         if (numq == 0) {           if (numf != 1) return 0;         } else if (numq == 1) {           if (numm == 0) {             if (c[i - 1] ==  ? )               c[i - 1] =  * ;             else if (c[i + 1] ==  ? )               c[i + 1] =  * ;             else               assert(false);           } else if (numm == 1) {             if (c[i - 1] ==  ? )               c[i - 1] =  - ;             else if (c[i + 1] ==  ? )               c[i + 1] =  - ;             else               assert(false);           } else             assert(false);         }       }     }     int res = 1;     for (int i = 0; i < N; i++) {       if (c[i] ==  ?  && (i == 0 || c[i - 1] !=  1 )) {         res *= 2;         if (res >= MOD) res -= MOD;       }     }     return res;   }   int main() {     cin >> c;     N = strlen(c);     cout << numWays() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int Mod = 998244353;   int n, x, y;   int gr[200005];   long long sol;   int main() {     cin >> n;     sol = n;     for (int i = 1; i < n; ++i) {       cin >> x >> y;       gr[x]++;       gr[y]++;       sol = 1LL * sol * gr[x] % Mod * gr[y] % Mod;     }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int n, x, trie[2][31 * maxn], cnt[31 * maxn], a[maxn], tot = 1;   inline void insert(int x) {     int p = 1, t;     for (int i = 31; i >= 0; i--) {       t = (1 << i) & x ? 1 : 0;       if (!trie[t][p]) trie[t][p] = ++tot;       p = trie[t][p];       cnt[p]++;     }   }   inline int get_max(int x) {     int p = 1, t, res = 0;     for (int i = 31; i >= 0; i--) {       t = (1 << i) & x ? 1 : 0;       if (trie[t][p] && cnt[trie[t][p]]) {         p = trie[t][p];       } else {         p = trie[t ^ 1][p];         res |= (1 << i);       }       cnt[p]--;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       insert(x);     }     for (int i = 1; i <= n; i++) {       printf( %d%c , get_max(a[i]), i == n ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, s;     cin >> s;     vector<string> g;     for (long long i = 0; i < s.length(); i++) {       a += s[i];       if (s[i] !=  a ) {         b += s[i];       }       if (a.length() + b.length() == s.length()) {         break;       }     }     if (s == a + b) {       cout << a;     } else {       cout <<  :(  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     return w ? -X : X;   }   int n, m;   int dx[4][5] = {       {2, 1, 0, 0, 0}, {1, 0, 0, 0, -1}, {0, 0, 0, -1, -2}, {1, 0, 0, 0, -1}};   int dy[4][5] = {       {0, 0, -1, 0, 1}, {0, 0, 1, 2, 0}, {-1, 0, 1, 0, 0}, {0, -2, -1, 0, 0}};   char maze[9][9];   int ans = -1;   char as[9][9];   bool check(int x, int y, int dir, char c) {     for (int i = 0; i < 5; i++) {       int nx = x + dx[dir][i];       int ny = y + dy[dir][i];       if (nx < 0 or nx >= n or ny < 0 or ny >= m) {         return 0;       }       if (!(c ==  .  or maze[nx][ny] ==  . )) {         return 0;       }     }     for (int i = 0; i < 5; i++) {       int nx = x + dx[dir][i];       int ny = y + dy[dir][i];       maze[nx][ny] = c;     }     return 1;   }   void dfs(int x, int y, char c) {     if (x == n) {       if (c -  A  > ans) {         ans = c -  A ;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             as[i][j] = maze[i][j];           }         }       }       return;     }     if ((n - x) * m / 5 + c -  A  <= ans) {       return;     }     if (y == m) {       dfs(x + 1, 0, c);       return;     }     for (int i = 0; i < 4; i++) {       if (check(x, y, i, c)) {         dfs(x, y + 1, c + 1);         check(x, y, i,  . );       }     }     dfs(x, y + 1, c);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         maze[i][j] =  . ;       }     }     dfs(0, 0,  A );     printf( %d n , ans);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         printf( %c , as[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const double EPS = 1e-4;   void solve() {     int n;     cin >> n;     vector<long long> a(n);     vector<pair<long long, long long>> diff(n);     for (long long i = 0; i < int(n); i++) cin >> a[i];     for (long long i = 0; i < int(n); i++) diff[i] = {a[i] - i, i};     sort(diff.begin(), diff.end());     long long curr_sum = 0, res = 0;     for (long long i = 1; i < n; ++i) {       if (curr_sum == 0LL && diff[i].first == diff[i - 1].first) {         curr_sum += (a[diff[i].second] + a[diff[i - 1].second]);       } else if (diff[i].first == diff[i - 1].first) {         curr_sum += a[diff[i].second];       } else {         curr_sum = 0;       }       res = max(res, curr_sum);     }     for (long long i = 0; i < int(n); i++) res = max(res, a[i]);     cout << res;     debug() <<   [              <<  diff                  :               << (diff) <<  ]  ;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }