malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <class T1, class T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (T& x : v) in >> x;     return in;   }   template <class T>   ostream& operator<<(ostream& out, vector<vector<T>>& v) {     for (vector<T>& x : v) out << x <<   n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (T& x : v) out << x <<    ;     return out;   }   long long gcd(long long a, long long b) {     if (b > a) swap(a, b);     return (b ? gcd(b, a % b) : a);   }   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using tiii = pair<pair<int, int>, int>;   using vi = vector<int>;   using vl = vector<long long>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<long long>>;   const int h = 1000000007;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.setstate(ios::failbit);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vi v(n);       cin >> v;       vi x{v[0]};       for (int i = (1); i < (n); i++) {         if (v[i] == x.back() + 1)           x.back()++;         else           x.push_back(v[i]);       }       int y = true;       for (int i = (1); i < (x.size()); i++)         if (x[i - 1] < x[i]) y = false;       cout << (y ?  Yes  :  No ) <<   n ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   const int maxn = 2e5 + 10;   char s[maxn];   int N, K;   long long T;   int A[22][22];   long long DP[1 << 22];   long long t[22];   int mask[22];   int main() {     scanf( %d %d %lld , &N, &K, &T);     scanf( %s , s + 1);     for (int i = 0; i < K; ++i) {       scanf( %lld , &t[i]);     }     for (int i = 0; i < K; ++i) {       for (int j = 0; j < K; ++j) {         scanf( %d , &A[i][j]);       }     }     for (int i = 0; i < K; ++i) {       DP[1 << i] = t[i];       mask[i] = -1;     }     int S = 0;     for (int i = 1; i <= N; ++i) {       int x = s[i] -  A ;       S |= (1 << x);       for (int j = 0; j < K; ++j) {         if (mask[j] >= 0) {           if ((mask[j] & (1 << j)) == 0 && (mask[j] & (1 << x)) == 0) {             DP[mask[j]] += A[j][x];             DP[mask[j] | (1 << j)] -= A[j][x];             DP[mask[j] | (1 << x)] -= A[j][x];             DP[mask[j] | (1 << j) | (1 << x)] += A[j][x];           }           mask[j] |= (1 << x);         }       }       mask[x] = 0;     }     for (int i = 0; i < K; ++i) {       for (int s = 0; s < (1 << K); ++s) {         if (s & (1 << i)) {           DP[s] += DP[s ^ (1 << i)];         }       }     }     long long ret = 0;     for (int s = 0; s < (1 << K); ++s) {       if ((s & S) == s && DP[s] <= T && s != S) {         ++ret;       }     }     printf( %lld n , ret);   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, m, n, x, y, z, ans, counting;   int ara[2000];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> ara[i];     }     sort(ara, ara + n);     for (i = 0; i < n; i++) {       if (ara[i] != 0) break;     }     for (j = i + 1, counting = 1; j < n; j++) {       if (ara[j] == ara[j - 1]) {         counting++;       } else {         counting = 1;       }       if (counting > 2) {         printf( -1 );         return 0;       } else if (counting == 2)         ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int isWinning(string str) {     int n = str.length();     int arr[n + 1][n + 1];     for (int i = 0; i <= n; i++) arr[i][i] = 1;     return arr[1][n];   }   int main() {     int n;     cin >> n;     int arr[n];     long long ans;     long long sum = 0;     for (int i = 0; i < (n); ++i) {       cin >> arr[i];       sum += arr[i];     }     sort(arr, arr + n);     ans = sum;     if (n - 2 >= 0) {       for (int i = 0; i < n - 2; i++) {         ans += sum;         sum -= arr[i];       }       ans += arr[n - 2];       ans += arr[n - 1];     } else if (n == 1)       ans = arr[0];     else {       ans = 2 * sum;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char st[1000010];   int n, K;   int main() {     int i, j;     scanf( %d%d , &n, &K);     scanf( %s , st + 1);     for (i = 1; i < n && K; ++i)       if (st[i] ==  4  && st[i + 1] ==  7 ) {         if (i % 2)           st[i + 1] =  4 ;         else {           st[i] =  7 ;           if (i > 1 && st[i - 1] ==  4 ) {             if (K % 2 == 0) st[i] =  4 ;             break;           }         }         K--;       }     printf( %s n , st + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> go(int x, int d) {     long long mx = 0;     for (int i = 1; i <= d; i++) mx += 1ll << i;     if (mx < x) return vector<int>();     return vector<int>();   }   void solve() {     int n;     cin >> n;     long long x = n - 1;     long long curr = 1;     vector<long long> ans;     while (x > 0) {       if (curr <= x && x <= 2 * curr) {         ans.push_back(x - curr);         break;       } else if (x <= 4 * curr) {         ans.push_back(x / 2 - curr);         ans.push_back(x % 2);         break;       }       ans.push_back(curr);       curr *= 2;       x -= curr;     }     cout << ((int)ans.size()) <<   n ;     for (long long i : ans) cout << i <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int a[110][110];   int dp[100][2];   const int M = 1e5 + 10;   int vis[M], prime[M];   void prim() {     memset(vis, 0, sizeof(vis));     memset(prime, 0, sizeof(prime));     int cun = 1;     for (int i = 2; i <= M; i++) {       if (vis[i] == 0) {         prime[cun++] = i;       }       for (int j = 1; j <= cun && prime[j] * i < M; j++) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) {           break;         }       }     }   }   int main() {     int t;     cin >> t;     int sum = 0;     prim();     while (t--) {       long long n, m;       cin >> n >> m;       int temp = n + m - 2;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) a[i][j] += i - i + j - j;       }       for (int i = 0; i <= (temp / 2); i++) {         dp[i][0] = 0;         dp[i][1] = 0;       }       if (temp % 2) {         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             int fl = i + j;             if (fl <= temp / 2)               dp[fl][a[i][j]]++;             else               dp[temp - fl][a[i][j]]++;           }         }         int ans = 0;         for (int i = 0; i <= temp / 2; i++) {           ans += min(dp[i][0], dp[i][1]);         }         cout << ans << endl;       } else {         int ans = 0;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             int fl = i + j;             if (fl == temp / 2) continue;             if (fl < temp / 2)               dp[fl][a[i][j]]++;             else {               dp[temp - fl][a[i][j]]++;             }           }         }         for (int i = 0; i <= (temp / 2 - 1); i++) {           ans += min(dp[i][0], dp[i][1]);         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   int d[maxn];   std::vector<int> G[maxn];   int dp(int u) {     if ((int)G[u].size() == 0) {       return d[u] = 1;     } else if (d[u]) {       return d[u];     }     for (int i : G[u]) {       d[u] += dp(i);     }     return d[u];   }   int c[maxn];   int main(int argc, char const *argv[]) {     int n;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i) {       int u;       cin >> u;       G[u].push_back(i);     }     dp(1);     for (int i = 1; i <= n; ++i) {       c[d[i]]++;     }     int sum = c[1];     int res = 1;     for (int i = 1; i <= n; ++i) {       while (i > sum) {         sum += c[++res];       }       cout << res <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T nextInt() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) {       p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * p;   }   const int maxN = (int)3e5 + 10;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const long long LLINF = (long long)1e18;   const long double pi = acos(-1.0);   int x[2];   int y[2];   int r[2];   long double d;   long double solve(int xa, int ya, int ra, int xb, int yb, int rb) {     long double angle =         2 * acos((rb * 1LL * rb - ra * 1LL * ra - d * d) / (-2 * ra * d));     return pi * ra * ra * angle / (2 * pi) - 1LL * ra * ra * sin(angle) / 2;   }   int main() {     cin >> x[0] >> y[0] >> r[0] >> x[1] >> y[1] >> r[1];     d = sqrtl((x[0] - x[1]) * 1LL * (x[0] - x[1]) +               (y[0] - y[1]) * 1LL * (y[0] - y[1]));     cout.precision(21);     if (d >= r[0] + r[1]) {       cout << 0 <<   n ;       return 0;     }     if (d <= abs(r[0] - r[1])) {       cout << pi * min(r[0], r[1]) * min(r[0], r[1]) <<   n ;       return 0;     }     cout << solve(x[0], y[0], r[0], x[1], y[1], r[1]) +                 solve(x[1], y[1], r[1], x[0], y[0], r[0])          <<   n ;     return 0;   }
#include <bits/stdc++.h>   int abss(int x) { return x > 0 ? x : -x; }   int main() {     int n, m, x1, y1, x2, y2;     while (scanf( %d %d %d %d %d %d , &n, &m, &x1, &y1, &x2, &y2) == 6) {       int chax = abss(x1 - x2);       int chay = abss(y1 - y2);       bool ansflag = 0;       if (x1 == x2 && y1 == y2)         ansflag = 1;       else {         if (chax == 0 || chay == 0) {           if (chax + chay <= 4) ansflag = 1;         } else {           if (chax < chay)             chay--;           else             chax--;           if ((chax < 3 && chay <= 3) || (chax <= 3 && chay < 3)) ansflag = 1;         }       }       if (ansflag)         puts( First );       else         puts( Second );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string obj;   bool solve(int x) {     string s = to_string(x);     string ans;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  7  || s[i] ==  4 ) ans.push_back(s[i]);     return ans == obj;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int a, b;     cin >> a >> b;     obj = to_string(b);     int i = a + 1;     while (!solve(i)) i++;     cout << i <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     do {       s = s * 10 + c -  0 ;     } while ((c = getchar()) >=  0  && c <=  9 );     return s;   }   bool descending(int a, int b) { return a > b; }   string toStr(char c) { return string(1, c); }   const int maxN = (int)1e2 + 10;   const int inf = (int)1e9;   int x;   int a[maxN];   long long dp[maxN];   vector<int> vl;   int main() {     int n;     cin >> n;     int cnt = 0;     for (int i = 0; i < (n); i++) {       cin >> x;       cnt += x;     }     cout << fixed << setprecision(12);     cout << cnt / double(n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long a[501][501];   bool visited[501];   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       visited[i] = false;       for (long long j = 0; j < n; j++) {         cin >> a[i][j];       }     }     vector<long long> order(n);     for (long long i = 0; i < n; i++) {       cin >> order[i];       order[i]--;     }     visited[order[n - 1]] = true;     vector<long long> values;     for (long long k = 0; k < n; k++) {       long long ans = 0;       long long p = order[n - k - 1];       visited[p] = true;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           a[i][j] = min(a[i][j], a[i][p] + a[p][j]);           if (visited[i] && visited[j] && visited[p]) {             ans += a[i][j];           }         }       }       values.push_back(ans);     }     for (long long i = 0; i < n; i++) {       cout << values[n - 1 - i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   class Node {    public:     Node<T> *prev;     Node<T> *next;     T data;     Node(T data);   };   template <class T>   Node<T>::Node(T data) {     this->data = data;   }   template <class T>   class Stack {    public:     Node<T> *top;     int size;     Stack();     bool empty();     void push(T a);     void pop();     void clear();   };   template <class T>   Stack<T>::Stack() {     top = NULL;     size = 0;   }   template <class T>   bool Stack<T>::empty() {     return (size == 0);   }   template <class T>   void Stack<T>::push(T data) {     Node<T> *t = new Node<T>(data);     t->next = top;     top = t;     size++;     return;   }   template <class T>   void Stack<T>::pop() {     top = top->next;     size--;     return;   }   template <class T>   void Stack<T>::clear() {     top = NULL;     size = 0;   }   int main() {     Stack<int> *st = new Stack<int>();     int n;     cin >> n;     int a;     int answer = 0;     int size = 0;     int leftSum = 0, rightSum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       rightSum = rightSum + a;       st->push(a);       size++;     }     while (!st->empty()) {       leftSum = leftSum + st->top->data;       rightSum = rightSum - st->top->data;       if (leftSum == rightSum && size != 1) answer++;       st->pop();       size--;     }     cout << answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cekTanda(char ch) {     switch (ch) {       case  > :         return 8;       case  < :         return 9;       case  + :         return 10;       case  - :         return 11;       case  . :         return 12;       case  , :         return 13;       case  [ :         return 14;       case  ] :         return 15;     }   }   int main() {     char str[1024];     scanf( %s , str);     int panjang = strlen(str);     int res = 0;     for (int i = 0; i < panjang; i++) {       res = (res << 4) % 1000003;       res += cekTanda(str[i]);       res %= 1000003;     }     printf( %d , res);   }
#include <bits/stdc++.h>   using namespace std;   const int a[] = {0,   4,   22,  27,  58,  85,  94,  121, 166, 202, 265, 274,                    319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535,                    562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690};   int main() {     int n;     cin >> n;     cout << a[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   const long long N = 500005;   const long long mod = 1e9 + 7;   using namespace std;   std::vector<long long> adj[N];   std::vector<bool> vis(N);   void solve() {     long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0;     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     x = 0;     for (int i = 1; i <= n; ++i) {       if (x < adj[i].size()) {         x = adj[i].size();         y = i;       }     }     std::vector<pair<long long, long long> > v;     queue<long long> nodes;     nodes.push(y);     vis[y] = 1;     while (!nodes.empty()) {       x = nodes.front();       nodes.pop();       for (auto i : adj[x]) {         if (!vis[i]) {           vis[i] = 1;           nodes.push(i);           v.push_back({x, i});         }       }     }     for (int i = 0; i < v.size(); ++i) {       cout << v[i].first <<     << v[i].second <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int nb;     scanf( %d , &nb);     int arr[nb];     for (int i = 0; i < nb; i++) scanf( %d , arr + i);     sort(arr, arr + nb);     int occ[3] = {0};     for (int i = 0; i < nb; i++) {       for (int j = 0; j < 3; j++)         if (arr[i] == arr[j]) occ[j]++;     }     if ((occ[0] == 1 && occ[1] == 1) || (occ[0] == 2)) {       printf( %d , occ[2]);       return 0;     }     if (occ[0] == 1 && occ[1] >= 2) {       long long res = (occ[1] * (long long)(occ[1] - 1)) / 2;       printf( %lld , res);       return 0;     }     long long res = (occ[0] * (long long)(occ[0] - 1) * (occ[0] - 2)) / 6;     printf( %lld , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   void solve() {     int n, k, d;     cin >> n >> k >> d;     vector<int> a(n);     map<int, int> used;     for (int i = 0; i < n; i++) cin >> a[i];     int cnt = 0, ans = INF;     for (int i = 0; i < d; i++) {       if (used[a[i]] == 0) cnt++;       used[a[i]]++;     }     for (int i = d; i < n; i++) {       ans = min(ans, cnt);       used[a[i - d]]--;       if (used[a[i - d]] == 0) cnt--;       if (used[a[i]] == 0) cnt++;       used[a[i]]++;     }     ans = min(cnt, ans);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int _t;     cin >> _t;     for (int _q = 0; _q < _t; _q++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int *arr = new int[n];       for (int i = 0; i < n; i++) cin >> arr[i];       int j, k;       for (int i = 0; i < n; i++) {         if (arr[i] == 1) {           j = i;           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (arr[i] == 1) {           k = i;           break;         }       }       int ans = 0;       for (int i = j; i <= k; i++) {         if (arr[i] == 0) ans++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, d, bd[4];   vector<long long> pst[4][100069];   int main() {     long long i, j, ii, k, l, z = 1, y, x, p;     bool ft = 1;     scanf( %lld%lld%lld , &n, &m, &d);     for (i = 0; i < d; i++) {       scanf( %lld%lld , &k, &l);       for (ii = 0; ii < 4; ii++) {         pst[ii][k].push_back(l);         l = m + 1 - l;         swap(k, l);         swap(n, m);       }     }     for (ii = 0; ii < 4; ii++) {       for (i = 1; i <= n; i++) {         sort(pst[ii][i].begin(), pst[ii][i].end());         pst[ii][i].push_back(m + 1);       }       bd[ii] = m + 1;       swap(n, m);     }     y = 1;     x = 1;     for (ii = 0; 1; ii = (ii + 1) % 4) {       p = min(bd[ii], *upper_bound(pst[ii][y].begin(), pst[ii][y].end(), x)) - 1;       k = p - x;       bd[(ii + 3) % 4] = n + 1 - y;       x = p;       z += k;       if (k == 0 && !ft) {         break;       }       ft = 0;       x = m + 1 - x;       swap(y, x);       swap(n, m);     }     if (z == n * m - d) {       printf( Yes n );     } else {       printf( No n );     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   void SieveOfEratosthenes(long long n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p]) v.push_back(p);   }   signed main() {     long long n;     cin >> n;     SieveOfEratosthenes(n);     long long m = v.size();     vector<long long> ans;     long long ct = 0;     for (long long i = 0; i < m; i++) {       long long p = v[i];       while (p <= n) {         ct++;         ans.push_back(p);         p = p * v[i];       }     }     cout << ct <<   n ;     long long k = ans.size();     for (long long i = 0; i < k; i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   struct sp {     int x, y;     bool operator<(const sp &a) const { return x < a.x || x == a.x && y < a.y; }     bool operator==(const sp &a) const { return x == a.x && y == a.y; }   };   namespace std {   template <>   struct hash<sp> {     size_t operator()(sp a) const { return a.x * 9875321 + a.y; }   };   }  // namespace std   unordered_map<sp, int> m1;   vector<int> b;   vector<int> a[110000];   int n, m, ans;   int main() {     int i, j, k, x, y, d;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       a[x].push_back(y);       m1[sp{x, y}] = 1;     }     m = sqrt(n);     for (i = 0; i <= 100000; i++)       if (a[i].size() >= m) b.push_back(i);     for (i = 0; i < b.size(); i++)       for (j = i + 1; j < b.size(); j++) {         d = b[j] - b[i];         x = b[i];         for (k = 0; k < a[x].size(); k++) {           y = a[x][k];           if (m1.count(sp{x + d, y}) && m1.count(sp{x, y + d}) &&               m1.count(sp{x + d, y + d}))             ans++;         }       }     for (i = 0; i <= 100000; i++)       if (a[i].size() < m) {         sort(a[i].begin(), a[i].end());         x = i;         for (j = 0; j < a[x].size(); j++) {           y = a[x][j];           for (k = j + 1; k < a[x].size(); k++) {             d = a[x][k] - a[x][j];             if (m1.count(sp{x + d, y}) && m1.count(sp{x + d, y + d})) ans++;             if (x - d >= 0 && a[x - d].size() >= m)               if (m1.count(sp{x - d, y}) && m1.count(sp{x - d, y + d})) ans++;           }         }       }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(4E3 + 10), kInf = int(1E9 + 10);   int a[kN];   void solve() {     int n, m, k, lft, ans = 0, tmp;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     m--;     k = min(k, m);     lft = m - k;     for (int i = 0; i <= k; i++) {       tmp = kInf;       for (int j = 0; j <= lft; j++)         tmp = min(tmp, max(a[i + j + 1], a[n - (k - i) - (lft - j)]));       ans = max(ans, tmp);     }     printf( %d n , ans);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }