malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     std::cin >> n;     bool letters[26];     bool d = false;     int extra = 0;     for (int i = 0; i < 26; i++) {       letters[i] = true;     }     char action;     string input =   ;     for (int i = 0; i < n; i++) {       cin >> action;       cin >> input;       if (action ==  ! ) {         for (int j = 0; j < 26; j++) {           if (strchr(input.c_str(), j +  a ) == NULL) {             letters[j] = false;           }         }         if (d == true) extra++;       }       if (action ==  . ) {         for (int j = 0; j < 26; j++) {           if (strchr(input.c_str(), j +  a ) != NULL) {             letters[j] = false;           }         }       }       if (action ==  ? ) {         letters[input[0] -  a ] = false;         if (d == true && i < n - 1) extra++;       }       if (d == false) {         int truec = 0;         for (int j = 0; j < 26; j++) {           if (letters[j] == true) {             truec++;           }         }         if (truec == 1) {           d = true;         }       }     }     cout << extra << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void solve(int tc) {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = k; i < s.size(); i++) {       if (s[i] ==  ? ) {         if (s[i - k] !=  ? ) {           s[i] = s[i - k];         }       } else {         if (s[i - k] ==  ? ) {           s[i - k] = s[i];         } else {           if (s[i] != s[i - k]) {             cout <<  NO  << endl;             return;           }         }       }     }     int count = 0;     int free = 0;     for (int i = 0; i < s.size(); i++) {       if (i >= k) {         if (s[i - k] ==  ? ) {           free--;         } else {           count -= ((s[i - k] ==  1 ) ? 1 : 0);         }       }       if (s[i] ==  ? ) {         free++;       } else {         count += ((s[i] ==  1 ) ? 1 : 0);       }       if (i >= k - 1) {         if (count > k / 2 || count + free < k / 2) {           cout <<  NO  << endl;           return;         }       }     }     cout <<  YES  << endl;   }   int main() {     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       solve(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265359;   inline long long add(long long a, long long b, long long m) {     if ((a + b) >= m) return (a + b) % m;     return a + b;   }   inline long long mul(long long a, long long b, long long m) {     if ((a * b) < m) return a * b;     return (a * b) % m;   }   long long power(long long x, long long y, long long m) {     long long res = 1;     x = x % m;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % m;       y = y >> 1;       x = (x * x) % m;     }     return res;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio;     cin.tie(0);     cout.tie(0);     int t = 1, n;     cin >> t;     while (t--) {       string s;       cin >> n;       cin >> s;       string ans;       int i = 0;       for (; i < s.length(); i++) {         if (s[i] ==  0 ) {           ans.push_back(s[i]);         } else {           break;         }       }       string ans2;       for (int i = s.length() - 1; i > -1; i--) {         if (s[i] ==  1 ) {           ans2.push_back(s[i]);         } else {           break;         }       }       if (ans.length() + ans2.length() == s.length()) {         cout << s << endl;       } else         cout << ans <<  0  << ans2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e2 + 5;   int ans[N][N][N];   bool was[N][N][N];   vector<pair<int, int> > adj[N];   bool calc(int x, int y, int pr) {     if (was[x][y][pr]) return ans[x][y][pr];     was[x][y][pr] = 1;     for (auto to : adj[x]) {       if (to.second >= pr && !calc(y, to.first, to.second)) {         ans[x][y][pr] = 1;         break;       }     }     return ans[x][y][pr];   }   int main() {     ios ::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v;       char c;       cin >> u >> v >> c;       adj[u].push_back({v, c -  a });     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (!calc(i, j, 0))           cout <<  B ;         else           cout <<  A ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[2000];   int a, b, n, res;   int main() {     scanf( %d %d %d , &n, &a, &b);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     sort(v, v + n);     int res = v[b] - v[b - 1];     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxsize = 100000 + 9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     T = 1;     while (T--) {       long long i, j, k, m, n, flag = 0;       vector<int> v;       string s;       cin >> n >> s;       for (i = 0; i < n; i++) {         if (s[i] ==  2 ) {           v.push_back(2);         }         if (s[i] ==  3 ) {           v.push_back(3);         }         if (s[i] ==  4 ) {           v.push_back(3);           v.push_back(2);           v.push_back(2);         }         if (s[i] ==  5 ) {           v.push_back(5);         }         if (s[i] ==  6 ) {           v.push_back(5);           v.push_back(3);         }         if (s[i] ==  7 ) {           v.push_back(7);         }         if (s[i] ==  8 ) {           v.push_back(7);           v.push_back(2);           v.push_back(2);           v.push_back(2);         }         if (s[i] ==  9 ) {           v.push_back(7);           v.push_back(3);           v.push_back(3);           v.push_back(2);         }       }       sort(v.begin(), v.end());       for (i = v.size() - 1; i >= 0; i--) {         cout << v[i];       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 0;     cin >> n;     if (n >= 1 && n <= 100) {       if (n == 1)         cout << 1;       else {         while (1) {           if (n == 2) {             s = s + 5;             break;           }           s = s + (n * 2) + (n - 2) * 2;           n = n - 1;         }         cout << s;       }     }   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   void change(map<long long, long long> &m, long long n) {     long long i;     for (long long i = 1; i < n + 1; i++) {       if (m[i] == 1)         m.erase(i);       else         m[i]--;     }     return;   }   void solve() {     long long n, i, l, t;     cin >> n >> t;     string ans =   ;     map<long long, long long> m;     for (long long i = 0; i < t; i++) {       cin >> l;       m[l]++;       if ((long long)m.size() == n) {         ans +=  1 ;         change(m, n);       } else {         ans +=  0 ;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a[101][101] = {0}, d = 0;     cin >> n;     for (long long int i = 1; i <= n; i++) {       long long int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       for (long long int j = x1; j <= x2; j++) {         for (long long int k = y1; k <= y2; k++) {           d++;         }       }     }     cout << d << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long getLL() {     long long ret = 0;     char c;     while (1) {       c = getchar();       if (c >=  0  && c <=  9 ) break;     }     while (1) {       ret = ret * 10 + c -  0 ;       c = getchar();       if (c <  0  || c >  9 ) break;     }     return ret;   }   int getInt() {     int ret = 0;     char c;     while (1) {       c = getchar();       if (c >=  0  && c <=  9 ) break;     }     while (1) {       ret = ret * 10 + c -  0 ;       c = getchar();       if (c <  0  || c >  9 ) break;     }     return ret;   }   const double eps = 1e-10;   int dcmp(double x) { return (x < -eps) ? -1 : (x > eps); }   struct Point {     double x, y;     int who;     Point() {}     Point(double _x, double _y, int _who) : x(_x), y(_y), who(_who){};     bool operator<(const Point &b) const {       if (dcmp(x - b.x) == 0) return y < b.y;       return x < b.x;     }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y, 0); }     double operator*(const Point &b) const { return x * b.y - y * b.x; }   } A[1020304];   int n, Stack[1020304], can[1020304], sameas[1020304];   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       double r, s;       scanf( %lf%lf , &r, &s);       A[i] = Point(10000.0 / r, 10000.0 / s, i);     }     sort(A + 1, A + n + 1);     int Top = 0;     vector<int> ans;     for (int i = 1; i <= n; ++i) {       if (i > 1 && dcmp(A[i].x - A[i - 1].x) == 0) continue;       while (Top > 1 &&              (dcmp((A[i] - A[Stack[Top]]) * (A[i] - A[Stack[Top - 1]])) > 0))         --Top;       Stack[++Top] = i;     }     for (int i = 1; i <= Top; ++i)       if (i == 1 || dcmp(A[Stack[i]].y - A[Stack[i - 1]].y) < 0)         can[Stack[i]] = true;     for (int i = 1; i <= n; ++i) {       if (dcmp(A[i].x - A[i - 1].x) == 0 && dcmp(A[i].y - A[i - 1].y) == 0)         can[i] |= can[i - 1];       if (can[i]) ans.push_back(A[i].who);     }     sort(ans.begin(), ans.end());     for (auto x : ans) printf( %d  , x);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 12;   int p[1 << N], q[1 << N], a[1 << N], pos[1 << N], ans[1 << N];   void do_swap(int x, int y) {     int val = (p[x] ^ q[x] ^ a[x]);     if (!val) {       return;     }     int idx = pos[a[x] ^ q[x]];     swap(pos[p[x]], pos[p[idx]]);     swap(p[x], p[idx]);     swap(q[y], q[idx]);     do_swap(idx, y);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, i, j, k, l = 0;     cin >> n;     n = (1 << n);     for (i = 0; i < n; i++) {       cin >> a[i];       l ^= a[i];       p[i] = q[i] = pos[i] = i;     }     if (l) {       cout <<  Fou ;       return 0;     }     for (i = 0; i + 1 < n; i++) {       do_swap(i, i + 1);     }     cout <<  Shi n ;     for (i = 0; i < n; i++) {       cout << p[i] <<    ;     }     cout <<   n ;     for (i = 0; i < n; i++) {       cout << q[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long r, d, n;   vector<vector<long long>> data;   const long double pi = 3.1415926535897932;   long long per(vector<long long> x, vector<long long> y) {     long long su = 0;     for (long long(i) = 0; (i) < (5); (i)++) {       su += x[i] * y[i];     }     return su;   }   long double pere(vector<long long> x, vector<long long> y) {     long double su = per(x, y);     su /= sqrt(per(x, x)) * sqrt(per(y, y));     su = acos(su);     return su;   }   int main() {     cin >> n;     data.resize(n);     for (long long(i) = 0; (i) < (n); (i)++) {       for (long long(j) = 0; (j) < (5); (j)++) {         data[i].resize(5);         cin >> data[i][j];       }     }     if (n > 32) {       cout << 0;       return 0;     }     vector<long long> result;     for (long long(i) = 0; (i) < (n); (i)++) {       bool mark = false;       for (long long(j) = 0; (j) < (n); (j)++) {         if (mark) {           break;         }         for (long long(l) = 0; (l) < (n); (l)++) {           if (i == j || j == l || i == l) {             continue;           }           vector<long long> x, y;           x.resize(5);           y.resize(5);           for (long long(h) = 0; (h) < (5); (h)++) {             x[h] = data[j][h] - data[i][h];             y[h] = data[l][h] - data[i][h];           }           if (pere(x, y) < pi / 2) {             mark = true;             break;           }         }       }       if (!mark) {         result.push_back(i);       }     }     cout << result.size() << endl;     for (long long(i) = 0; (i) < (result.size()); (i)++) {       cout << result[i] + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ans = 0, turn = 1;       while (n > 0) {         if (n % 2) {           n--;           if (turn % 2) {             ans++;           }         } else {           if ((n / 2) % 2 == 0 && (n / 2) != 2) {             n--;             if (turn % 2) {               ans++;             }           } else {             if (turn % 2) {               ans += (n / 2);             }             n /= 2;           }         }         turn++;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   const int infinity = (int)1e9 + 42;   const int64_t llInfinity = (int64_t)1e18 + 256;   const int module = (int)1e9 + 7;   const long double eps = 1e-8;   mt19937_64 randGen(system_clock().now().time_since_epoch().count());   inline void raiseError(string errorCode) {     cerr <<  Error :   << errorCode << endl;     exit(42);   }   inline basic_string<int64_t> arith(int64_t n, int64_t base, int64_t step) {     basic_string<int64_t> res;     for (int64_t i = 0; i < n; i++) {       res += base;       base += step;     }     return res;   }   inline int64_t ask(basic_string<int64_t> b) {     cout << b.size();     for (int64_t i : b) {       cout <<     << i;     }     cout << endl;     int64_t x;     cin >> x;     if (x == -2) {       exit(42);     }     if (x == -1) {       exit(0);     }     return x;   }   inline void simpleGuess(int64_t l, int64_t r, int64_t knt, int64_t att) {     for (int64_t i = 0; i < att; i++) {       if (r - l + 1 <= knt) {         ask(arith(r - l + 1, l, 1));         exit(42);       }       int64_t delta = (r - l + 1 - knt) / (knt + 1);       int64_t mod = (r - l + 1 - knt) % (knt + 1);       int64_t val = l;       basic_string<int64_t> bounds;       bounds += l - 1;       for (int64_t i = 1; i <= knt; i++) {         int64_t add = delta + (i <= mod);         val += add;         bounds += val;         val++;       }       bounds += r + 1;       int64_t q = ask(bounds.substr(1, knt));       l = bounds[q] + 1;       r = bounds[q + 1] - 1;     }     exit(42);   }   signed main() {     ios_base::sync_with_stdio(false);     if (ask({204761410474}) == 0) {       if (ask({2046}) == 0) {         if (ask({6}) == 0) {           if (ask({2}) == 0) {             ask({1});           } else {             ask(arith(3, 3, 1));           }         } else {           int64_t q = ask({14, 30, 62, 126, 254, 510, 1022});           int64_t w = (8 << q) - 1;           ask(arith(w, w, 1));         }       } else {         int64_t base1 = 20468427, step1 = 100020001;         int64_t w1 = ask(arith(2047, base1, step1));         if (w1 == 0) {           int64_t base2 = 16382, step2 = 10001;           int64_t w2 =               ask(basic_string<int64_t>{4094, 8190} + arith(2045, base2, step2));           if (w2 <= 2) {             int64_t abase = (2048 << w2) - 1;             ask(arith(abase, abase, 1));           } else {             ask(arith(10000, base2 + (w2 - 3) * step2 + 1, 1));           }         } else {           simpleGuess(base1 + (w1 - 1) * step1 + 1, base1 + w1 * step1 - 1, 10000,                       2);         }       }     } else {       simpleGuess(204761410475, 10004205361450474, 10000, 4);     }     return 42;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, f = 0, se = 0, so = 0, sume = 0, sumo = 0, c = 0, x, y;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       if (i % 2)         so += a[i];       else         se += a[i];     }     for (i = 0; i < n; i++) {       if (i % 2) {         x = so - sumo - a[i] + sume;         y = se - sume + sumo;         sumo += a[i];       } else {         x = so - sumo + sume;         y = se - sume + sumo - a[i];         sume += a[i];       }       if (x == y) c++;     }     cout << c <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int dividers[60];   int main() {     long long int n, k;     cin >> n >> k;     if (k == 1) {       cout <<  Yes ;       return 0;     }     if (k == 2 && n == 1) {       cout <<  Yes ;       return 0;     }     if (n <= k) {       cout <<  No ;       return 0;     }     if (k > 50) {       cout <<  No ;       return 0;     }     long long int c = n + 1;     for (int i = 2; i <= k; i++) {       if (c % i != 0) {         cout <<  No ;         return 0;       }     }     cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e3 + 5;   char a[MAX][MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j) cin >> a[i][j];     int ans = 0;     for (int i = (1); i <= (n); ++i) {       int cnt = 0;       for (int j = (1); j <= (m); ++j) {         if (a[i][j] ==  . )           ++cnt;         else {           if (cnt >= k) ans += cnt - k + 1;           cnt = 0;         }       }       if (cnt >= k) ans += cnt - k + 1;     }     if (k > 1) {       for (int i = (1); i <= (m); ++i) {         int cnt = 0;         for (int j = (1); j <= (n); ++j) {           if (a[j][i] ==  . )             ++cnt;           else {             if (cnt >= k) ans += cnt - k + 1;             cnt = 0;           }         }         if (cnt >= k) ans += cnt - k + 1;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 10000000;   int n, m, x, y, a, b;   int vabs(int t) { return (t > 0) ? t : (-t); }   int calc(int cx, int cy) {     int dx = vabs(cx - x);     int dy = vabs(cy - y);     if (dx == 0 && dy == 0) return 0;     if (dx % a != 0 || dy % b != 0) return oo;     int ca = dx / a, cb = dy / b;     if (vabs(ca - cb) % 2 != 0) return oo;     if (ca < cb && cx - a < 1 && cx + a > n) return oo;     if (ca > cb && cy - b < 1 && cy + b > m) return oo;     return max(ca, cb);   }   int main() {     while (cin >> n) {       cin >> m >> x >> y >> a >> b;       int ans = oo;       ans = min(ans, calc(1, 1));       ans = min(ans, calc(1, m));       ans = min(ans, calc(n, 1));       ans = min(ans, calc(n, m));       if (ans == oo)         cout <<  Poor Inna and pony!  << endl;       else         cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e10;   void solve() {     long long n, c;     cin >> n >> c;     long long a[n], b[n];     for (long long i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     long long low = -1, high = -1;     for (long long i = 1; i <= 100000; i++) {       long long cnt = 0;       for (long long j = 0; j < n; j++) {         cnt++;         cnt += (a[j] * i) / b[j];       }       if (cnt > c) break;       if (cnt < c) continue;       if (cnt == c) {         if (low == -1) low = i;         high = i;       }     }     if (high == -1)       cout << 0;     else       cout << high - low + 1;   }   int32_t main() {     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, x;     std::cin >> n >> x;     std::vector<int> data;     int counter = 0;     for (int i = 0; i != n; i++) {       int temp;       std::cin >> temp;       data.push_back(temp);     }     std::sort(data.begin(), data.end());     if (std::find(data.begin(), data.end(), x) != data.end()) {       auto it = std::find(data.begin(), data.end(), x);       counter++;       data.erase(it);     }     for (int i = 0; i < x; i++) {       if (std::find(data.begin(), data.end(), i) == data.end()) {         data.push_back(i);         counter++;       }     }     std::cout << counter << std::endl;     return 0;   }
#include <bits/stdc++.h>      #define ll long long   #define sz(x) ((int) (x).size())   #define all(x) (x).begin(), (x).end()   #define vi vector<int>   #define pii pair<int, int>   #define rep(i, a, b) for(int i = (a); i < (b); i++)   using namespace std;   template<typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;      struct pt {       ll x, y;       pt(ll x = 0, ll y = 0) : x(x), y(y) {}       pt operator-(const pt &o) const {           return pt(x - o.x, y - o.y);       }       ll cross(const pt &o) const {           return x * o.y - y * o.x;       }       bool operator<(const pt &o) const {           return cross(o) > 0;       }   };      struct dsu {       vi a;       dsu(int n) {           a.assign(n, -1);       }       int trace(int x) {           return a[x] < 0 ? x : a[x] = trace(a[x]);       }       void join(int x, int y) {           if((x = trace(x)) == (y = trace(y))) return;           if(a[x] > a[y]) swap(x, y);           a[x] += a[y];           a[y] = x;       }   };      int main() {       ios::sync_with_stdio(false);       cin.tie(0);       int n;       cin >> n;       vi a(n + 1);       vector<pt> p(n + 1);       rep(i, 1, n + 1) {           cin >> p[i].x >> p[i].y >> a[i];       }       int idx = -1;       rep(i, 1, n + 1) {           if(a[i] != i && (idx == -1 || p[i].y < p[idx].y)) {               idx = i;           }       }       if(idx == -1) {           cout << 0 <<   n ;           return 0;       }       vi balls;       rep(i, 1, n + 1) {           if(i != idx && a[i] != i) {               balls.push_back(i);           }       }       sort(all(balls), [&](int i, int j) {           return p[i] - p[idx] < p[j] - p[idx];       });       dsu D(n + 1);       rep(i, 1, n + 1) D.join(i, a[i]);       int k = sz(balls);       vector<pii> ops;       auto pass = [&](int i, int j) {           swap(a[i], a[j]);           ops.push_back({i, j});       };       rep(i, 0, k - 1) {           if(D.trace(balls[i]) != D.trace(balls[i + 1])) {               pass(balls[i], balls[i + 1]);               D.join(balls[i], balls[i + 1]);           }       }       while(a[idx] != idx) {           pass(idx, a[idx]);       }          cout << sz(ops) <<   n ;       for(auto &pa : ops) {           cout << pa.first <<     << pa.second <<   n ;       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a[102400], i, j, o = 0, l = 0, ma, k = 0;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 1; i < n; i++) {       if (a[i] + k < a[i - 1]) {         o += a[i - 1] - (a[i] + k);         k += a[i - 1] - (a[i] + k);         a[i] = a[i - 1];       } else {         if (a[i] < a[i - 1]) {           k = a[i - 1] - a[i];           a[i] = a[i - 1];         } else           k = 0;       }     }     cout << o << endl;   }