malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   const int M = 1000000007;   const double eps = 1e-9;   const double PI = acos(-1);   const int oo = 1000000000;   typedef double TT;   struct point {     TT x, y;     point() : x(0), y(0) {}     point(TT a, TT b) {       x = a;       y = b;     }     point operator+(const point& p) const { return point(x + p.x, y + p.y); }     friend ostream& operator<<(ostream& os, const point& p) {       return os <<  (  << p.x <<  ,  << p.y <<  ) ;     }     point operator-(const point& p) const { return point(x - p.x, y - p.y); }     bool operator<(const point& p) const {       if (x - p.x) return x < p.x;       return y < p.y;     }     bool operator==(const point& p) const { return x == p.x && y == p.y; }     bool operator!=(const point& p) const { return !(*this == p); }     void scan() { scanf( %lf%lf , &x, &y); }     double len() { return sqrt(x * x + y * y); }     double dist(const point& p) const { return (p - *this).len(); }     point operator*(TT d) { return point(x * d, y * d); }     point operator/(TT d) { return point(x / d, y / d); }     TT operator*(const point& p) const { return x * p.x + y * p.y; }     TT operator^(const point& p) const { return x * p.y - y * p.x; }     double linePointDist(point a, point b, bool seg = false) {       point c = *this;       if (seg) {         if ((b - a) * (c - b) > 0) return b.dist(c);         if ((a - b) * (c - a) > 0) return a.dist(c);       }       return abs((b - a) ^ (c - a)) / a.dist(b);     }     void rotate(double theta, point Z = point(0, 0)) {       TT ox = x - Z.x;       TT oy = y - Z.y;       x = ox * cos(theta) - oy * sin(theta) + Z.x;       y = ox * sin(theta) + oy * cos(theta) + Z.y;     }   };   double areaOfTri(point a, point b, point c) {     point x = b - a;     point y = c - a;     return (x ^ y) / 2.0;   }   double areaOfPolygon(vector<point>& P) {     TT area = 0;     for (int i = 1; i < P.size() - 1; ++i)       area += (P[i] - P[0]) ^ (P[i + 1] - P[0]);     return abs(area / 2.0);   }   bool collinear(point a, point b, point c) { return areaOfTri(a, b, c) == 0; }   vector<point> x(4), y(4);   int main() {     double mnx = oo, mxx = -oo, mny = oo, mxy = -oo;     for (int i = 0; i < 4; ++i) {       x[i].scan();       mnx = min(mnx, x[i].x);       mny = min(mny, x[i].y);       mxx = max(mxx, x[i].x);       mxy = max(mxy, x[i].y);     }     point dx((mnx + mxx) / 2, (mny + mxy) / 2);     for (int i = 0; i < 4; ++i) y[i].scan();     for (int i = 0; i < 4; ++i)       if (y[i].x >= mnx && y[i].x <= mxx && y[i].y >= mny && y[i].y <= mxy)         return cout <<  YES , 0;     double area = abs(areaOfPolygon(y));     for (int i = 0; i < 4; ++i) {       double cc = abs(areaOfTri(y[3], y[0], x[i]));       for (int j = 1; j < 4; ++j) cc += abs(areaOfTri(y[j - 1], y[j], x[i]));       if (abs(cc - area) < eps) return cout <<  YES , 0;     }     double cc = abs(areaOfTri(y[3], y[0], dx));     for (int j = 1; j < 4; ++j) cc += abs(areaOfTri(y[j - 1], y[j], dx));     if (abs(cc - area) < eps) return cout <<  YES , 0;     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, l;   long long sum;   int main() {     cin >> a >> b >> c >> l;     sum = ((l + 1) * (l + 2) * (l + 3)) / 6;     for (long long i = 0; i <= l; i++) {       long long temp1 = a - b - c + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     for (long long i = 0; i <= l; i++) {       long long temp1 = b - a - c + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     for (long long i = 0; i <= l; i++) {       long long temp1 = c - b - a + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 2e5 + 5;   const int T = 1e3 + 10;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   long long binpow(long long val, long long deg) {     if (!deg) return 1;     if (deg & 1) return binpow(val, deg - 1) * val % MOD;     long long res = binpow(val, deg / 2);     return (res * res) % MOD;   }   long long inv(long long a) { return binpow(a, MOD - 2); }   pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first - b.first, a.second - b.second);   }   void rotate90(int& first, int& second, int x0, int y0) {     first = first - x0;     second = second - y0;     swap(first, second);     first = -first;     first += x0;     second += y0;   }   long long i, j;   long long n, m;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout.precision(10);     cin >> n >> m;     set<int> column, line;     while (m--) {       int first, second;       cin >> first >> second;       column.insert(first);       line.insert(second);       cout << (n - column.size()) * (n - line.size()) <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const double PI = 3.141592653589793238463;   const int INF = 0x3f3f3f3f;   const int INFS = 1000000000;   const long long LLINF = 9223372036854775807;   const int M = 1000000007;   const double EPS = 1e-9;   set<int> get(int n) {     set<int> ans = {};     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         ans.insert(i);         while (n % i == 0) n /= i;       }     }     if (n != 1) ans.insert(n);     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<set<int> > a(n + 1);     for (int i = 1; i < n + 1; i++) a[i] = get(i);     map<int, int> curr;     vector<bool> on(n + 1, false);     char t;     int i;     while (m--) {       cin >> t >> i;       if (t ==  + ) {         if (on[i])           cout <<  Already on  << endl;         else {           bool ok = true;           int j;           for (auto x : a[i]) {             if (curr[x] != 0) {               ok = false;               j = curr[x];               break;             }           }           if (ok) {             cout <<  Success  << endl;             for (auto x : a[i]) curr[x] = i;             on[i] = true;           } else {             cout <<  Conflict with   << j << endl;           }         }       } else {         if (!on[i])           cout <<  Already off  << endl;         else {           cout <<  Success  << endl;           for (auto x : a[i]) curr[x] = 0;           on[i] = false;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, kol[100500];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (kol[j] <= v[i]) {           kol[j]++;           break;         }     for (int i = 0; i < n; i++) ans += (kol[i] > 0);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, dist1, dist2;     char ch[3], a;     ch[0] = getchar();     a = getchar();     ch[2] = getchar();     cin >> n;     n = n % 4;     if (n == 1 &&         ((ch[0] ==  ^  && ch[2] ==  > ) || (ch[0] ==  >  && ch[2] ==  v ) ||          (ch[0] ==  v  && ch[2] ==  < ) || (ch[0] ==  <  && ch[2] ==  ^ )))       cout <<  cw ;     else if (n == 1 &&              ((ch[0] ==  ^  && ch[2] ==  < ) || (ch[0] ==  <  && ch[2] ==  v ) ||               (ch[0] ==  v  && ch[2] ==  > ) || (ch[0] ==  >  && ch[2] ==  ^ )))       cout <<  ccw ;     else if (n == 3 &&              ((ch[0] ==  ^  && ch[2] ==  < ) || (ch[0] ==  >  && ch[2] ==  ^ ) ||               (ch[0] ==  v  && ch[2] ==  > ) || (ch[0] ==  <  && ch[2] ==  v )))       cout <<  cw ;     else if (n == 3 &&              ((ch[0] ==  ^  && ch[2] ==  > ) || (ch[0] ==  <  && ch[2] ==  ^ ) ||               (ch[0] ==  v  && ch[2] ==  < ) || (ch[0] ==  >  && ch[2] ==  v )))       cout <<  ccw ;     else       cout <<  undefined ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s;     int a;     int x = 0, y = n + 1;     for (int i = 0; i < m; i++) {       cin >> s;       cin >> s;       cin >> s;       if (s[0] ==  r ) {         cin >> s;         cin >> a;         if (a > x) x = a;       } else {         cin >> s;         cin >> a;         if (a < y) y = a;       }     }     if (y - x <= 1 || x == n || y == 1)       cout << -1;     else       cout << y - x - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       vector<int> original;       int temp;       for (int i = 0; i < n; i++) {         cin >> temp;         original.push_back(temp);       }       for (int i = 0; i < original.size(); i++) {         int days = 0;         int origpos = i;         int newpos = original[i];         bool home = false;         while (!home) {           newpos = original[newpos - 1];           if (newpos == original[i]) {             home = true;           }           days++;         }         cout << days <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     priority_queue<int> q;     for (int i = 0; i < 32; i++) {       if (n & (1 << i)) {         q.push(i);       }     }     if (q.size() > k) {       cout <<  NO n ;     } else {       while (q.size() != k) {         int f = q.top();         q.pop();         if (f == 0) {           cout <<  NO n ;           return 0;         }         q.push(f - 1);         q.push(f - 1);       }       cout <<  YES n ;       while (!q.empty()) {         int val = 1 << q.top();         cout << val <<    ;         q.pop();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T mod_v(T num) {     if (num >= 0)       return num % 1000000007;     else       return (num % 1000000007 + 1000000007) % 1000000007;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   T fast_pow(T n, T p) {     if (p == 0) return 1;     if (p % 2) {       T g = mod_v(mod_v(n) * mod_v(fast_pow(n, p - 1)));       return g;     } else {       T g = fast_pow(n, p / 2);       g = mod_v(mod_v(g) * mod_v(g));       return g;     }   }   template <class T>   inline T modInverse(T n) {     return fast_pow(n, 1000000007 - 2);   }   template <class T>   inline void debug(string S1, T S2, string S3) {     cout << S1 << S2 << S3;   }   template <class T>   inline T in() {     register char c = 0;     register T num = 0;     bool n = false;     while (c < 33) c = getchar();     while (c > 33) {       if (c ==  - )         n = true;       else         num = num * 10 + c -  0 ;       c = getchar();     }     return n ? -num : num;   }   class data {    public:     int t, w;   };   int dp[108][208][208];   int n;   data ara[108];   vector<int> ans;   int re(int p, int s, int u) {     if (p == n) {       return s;       return ((s >= u) ? s : 100000000);     }     if (dp[p][s][u] != -1) return dp[p][s][u];     dp[p][s][u] = 1 << 30;     if (u - ara[p].w - ara[p].t >= 0) {       dp[p][s][u] =           min(dp[p][s][u], re(p + 1, s - ara[p].t, u - ara[p].t - ara[p].w));     }     ans.push_back(p + 1);     dp[p][s][u] = min(dp[p][s][u], re(p + 1, s, u));     ans.pop_back();     return dp[p][s][u];   }   int main() {     n = in<int>();     int t = 0, w = 0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i].t, &ara[i].w);       t += ara[i].t;     }     memset(dp, -1, sizeof(dp));     ;     printf( %d n , re(0, t, t));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<long long int> vec(n);       for (int i = 0; i < n; i++) {         cin >> vec[i];       }       sort(vec.begin(), vec.end());       long long int sum = vec[n - 1];       int x = n - 2;       while (k--) {         sum += vec[x];         x--;       }       cout << sum <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int ans = 0;     for (int i = 1; i < n; i++) {       int a = max(0, k - (arr[i] + arr[i - 1]));       arr[i] += a;       ans += a;     }     cout << ans <<   n ;     for (int i = 0; i < n; i++) cout << arr[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int c = 0, i;     for (i = 4; i < s.size(); i++) {       if (s[i - 4] ==  D  && s[i - 3] ==  a  && s[i - 2] ==  n  &&           s[i - 1] ==  i  && s[i] ==  l )         c++;     }     for (i = 3; i < s.size(); i++) {       if (s[i - 3] ==  O  && s[i - 2] ==  l  && s[i - 1] ==  y  && s[i] ==  a )         c++;     }     for (i = 4; i < s.size(); i++) {       if (s[i - 4] ==  S  && s[i - 3] ==  l  && s[i - 2] ==  a  &&           s[i - 1] ==  v  && s[i] ==  a )         c++;     }     for (i = 2; i < s.size(); i++) {       if (s[i - 2] ==  A  && s[i - 1] ==  n  && s[i] ==  n ) c++;     }     for (i = 5; i < s.size(); i++) {       if (s[i - 5] ==  N  && s[i - 4] ==  i  && s[i - 3] ==  k  &&           s[i - 2] ==  i  && s[i - 1] ==  t  && s[i] ==  a )         c++;     }     if (c == 1)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int main(void) {     char arr1[N] = {0};     char arr2[N] = {0};     char str1[2] = {0}, str2[2] = {0};     scanf( %[^ n]s , arr1);     scanf(  %[^ n]s , arr2);     if (strlen(arr1) != strlen(arr2)) {       cout <<  NO n ;       return 0;     }     int a = 0;     for (int i = 0, j = 0, k = 0; i < strlen(arr1); i++) {       if (arr1[i] != arr2[i]) {         a++;         if (a <= 2) {           str1[j++] = arr1[i];           str2[k++] = arr2[i];         }       }     }     if (a == 2) {       if ((str1[1] == str2[0]) && (str1[0] == str2[1]))         cout <<  YES n ;       else         cout <<  NO n ;     } else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     cin >> n >> k;     if (n / 2 > k) return !printf( -1 );     if (n == 1) {       if (k == 0)         printf( 1 );       else         printf( -1 );       return 0;     }     int t = k - (n - 2) / 2;     printf( %d %d , t, 2 * t);     for (int i = 1; i <= n - 2; ++i) printf(  %d , i + 2 * t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void input() {}   void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n][m];     long long int flag = 1, temp = 0;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         char ch;         cin >> ch;         if (ch ==  A ) {           a[i][j] = 1;         } else {           a[i][j] = 0;         }         if (a[i][j]) {           flag = 0;         }         temp += a[i][j];       }     }     if (temp == n * m) {       cout <<  0 ;       return;     }     if (flag) {       cout <<  MORTAL ;       return;     }     for (long long int i = 0; i < 1; i++) {       long long int cnt1 = 0, cnt2 = 0;       for (long long int j = 0; j < m; j++) {         if (a[0][j]) {           cnt1++;         }         if (a[n - 1][j]) {           cnt2++;         }       }       if (cnt1 == m || cnt2 == m) {         cout <<  1 ;         return;       }     }     for (long long int j = 0; j < 1; j++) {       long long int cnt1 = 0, cnt2 = 0;       for (long long int i = 0; i < n; i++) {         if (a[i][0]) {           cnt1++;         }         if (a[i][m - 1]) {           cnt2++;         }       }       if (cnt1 == n || cnt2 == n) {         cout <<  1 ;         return;       }     }     for (long long int i = 1; i < n - 1; i++) {       long long int cnt = 0;       for (long long int j = 0; j < m; j++) {         if (a[i][j]) {           cnt++;         }       }       if (cnt == m) {         cout <<  2 ;         return;       }     }     for (long long int j = 1; j < m - 1; j++) {       long long int cnt = 0;       for (long long int i = 0; i < n; i++) {         if (a[i][j]) {           cnt++;         }       }       if (cnt == n) {         cout <<  2 ;         return;       }     }     if (a[0][m - 1] || a[0][0] || a[n - 1][0] || a[n - 1][m - 1]) {       cout <<  2 ;       return;     }     long long int cnt = 0;     for (long long int i = 0; i < n; i++) {       cnt += a[i][0];       cnt += a[i][m - 1];     }     for (long long int i = 0; i < m; i++) {       cnt += a[0][i];       cnt += a[n - 1][i];     }     if (cnt) {       cout <<  3 ;     } else {       cout <<  4 ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     input();     int t = 1, i = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long pow(long long p, long long r, long long m) {     long long ans = 1;     while (r > 0) {       if (r & 1) {         ans = ((ans % m) * (p % m)) % m;       }       r = r >> 1;       p = ((p % m) * (p % m)) % m;     }     return ans;   }   string con(string s) {     for (long long i = 0; i < s.length(); i++) {       s[i] = toupper(s[i]);     }     return s;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       stack<long long> s1;       for (char i : s) {         if (!s1.empty() && i ==  B )           s1.pop();         else           s1.push(i);       }       cout << s1.size() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   string dna =  ACGT ;   string word[20];   set<string> words;   map<string, int> mp;   string pm[110];   pair<int, int> graph[110][20][4];   long long dp[1010][110][20];   int main() {     ios::sync_with_stdio(false);     int N, K, i, j, k, l, x;     cin >> N >> K;     for (i = 0; i < K; i++) cin >> word[i];     for (i = 0; i < K; i++) words.insert(word[i]);     for (i = 0; i < K; i++)       for (j = 1; j <= word[i].length(); j++) mp[word[i].substr(0, j)] = 0;     mp[  ] = 0;     int s = 0;     for (auto itr = mp.begin(); itr != mp.end(); itr++) {       (itr->second) = s;       pm[s] = (itr->first);       s++;     }     for (i = 0; i < s; i++) {       for (j = 0; j < pm[i].length() + 1; j++) {         for (k = 0; k < 4; k++) {           string s = pm[i] + dna[k];           int nextst = -1;           for (l = 0;; l++) {             if (mp.find(s.substr(l)) != mp.end()) {               nextst = mp[s.substr(l)];               break;             }           }           bool cover = false;           for (l = 0; l < pm[i].length() - j + 1; l++)             if (words.find(s.substr(l)) != words.end()) cover = true;           graph[i][j][k] = make_pair(-1, -1);           int nextcover = j + 1;           if (cover) nextcover = 0;           if (nextcover >= 10 || nextcover > pm[nextst].length()) continue;           graph[i][j][k] = make_pair(nextst, nextcover);         }       }     }     int start = mp[  ];     dp[0][start][0] = 1;     for (i = 0; i < N; i++) {       for (j = 0; j < s; j++) {         for (k = 0; k < 10; k++) {           if (dp[i][j][k] != 0) {             for (x = 0; x < 4; x++) {               pair<int, int> p = graph[j][k][x];               if (p.first != -1) {                 int i2 = i + 1, j2 = p.first, k2 = p.second;                 dp[i2][j2][k2] = (dp[i][j][k] + dp[i2][j2][k2]) % 1000000009ll;               }             }           }         }       }     }     long long ans = 0;     for (i = 0; i < s; i++) ans = (ans + dp[N][i][0]) % 1000000009ll;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<int> v[2][N];   int a[N], q[N], n;   bool vst[2][N];   void bfs(int val) {     int i, j, qh = 0, qe = 0, k = val - 1, s, out;     for (i = 1; i <= n; i++)       if (a[i] == val) q[qe++] = i, vst[k][i] = 1;     while (qh < qe) {       out = q[qh++];       if (val != 2 || a[out] != 1)         for (i = 0, s = v[k][out].size(); i < s; i++)           if (!vst[k][j = v[k][out][i]]) q[qe++] = j, vst[k][j] = 1;     }   }   int main() {     int i, j, e;     while (2 == scanf( %d%d , &n, &e)) {       for (i = 1; i <= n; i++)         scanf( %d , a + i), v[0][i].clear(), v[1][i].clear();       while (e--) {         scanf( %d%d , &i, &j);         v[0][i].push_back(j);         v[1][j].push_back(i);       }       memset(vst, 0, sizeof vst);       bfs(1);       bfs(2);       for (i = 1; i <= n; i++) puts(vst[0][i] && vst[1][i] ?  1  :  0 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPossible(long long k, long long x, long long y, long long p,                   long long q) {     p = p * k;     q = q * k;     if (x > p || y > q) {       return false;     }     if (q - y < p - x) {       return false;     }     return true;   }   long long solve(long long x, long long y, long long p, long long q) {     long long low = 1;     long long high = 1e9;     while (low < high) {       long long mid = low + (high - low) / 2;       if (!isPossible(mid, x, y, p, q)) {         low = mid + 1;       } else {         high = mid;       }     }     if (!isPossible(low, x, y, p, q)) {       return -1;     }     return (q * low - y);   }   int main() {     long long t;     cin >> t;     while (t--) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       cout << solve(x, y, p, q) << endl;     }     return 0;   }