malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, u, r;   vector<int> b, k;   vector<int> p;   void exec(vector<int> a, int type, int count) {     if (count < u) {       if (type == 0) {         for (int i = 0; i < n; ++i) a[i] = a[i] ^ b[i];         exec(a, 1, count + 1);       } else {         vector<int> aa(n);         for (int i = 0; i < n; ++i) aa[i] = a[p[i]] + r;         int rest = u - count - 1;         long long cur_cand = 0;         if (rest & 1) {           vector<int> aaa(n);           for (int i = 0; i < n; ++i) aaa[i] = aa[i] ^ b[i];           cur_cand = inner_product(aaa.begin(), aaa.end(), k.begin(), 0LL);         } else {           cur_cand = inner_product(aa.begin(), aa.end(), k.begin(), 0LL);         }         ans = max(cur_cand, ans);         exec(aa, 0, count + 1);         exec(aa, 1, count + 1);       }     } else {       long long cand = inner_product(a.begin(), a.end(), k.begin(), 0LL);       ans = max(cand, ans);     }   }   int main() {     cin >> n >> u >> r;     vector<int> a(n);     b.resize(n);     k.resize(n);     p.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) cin >> k[i];     for (int i = 0; i < n; ++i) {       cin >> p[i];       --p[i];     }     for (int i = 0; i < n; ++i) {       ans += k[i] * (u & 1 ? a[i] ^ b[i] : a[i]);     }     exec(a, 1, 0);     exec(a, 0, 0);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int book[100010];   vector<pair<int, int>> v;   deque<int> high, low;   int main() {     int n, k, ans = 0, num = 0, r, l;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> book[i];     for (r = 1, l = 1; r <= n; r++) {       while (!high.empty() && high.back() < book[r]) high.pop_back();       high.push_back(book[r]);       while (!low.empty() && low.back() > book[r]) low.pop_back();       low.push_back(book[r]);       while (!high.empty() && !low.empty() && high.front() - low.front() > k) {         if (v.empty()) {           num = 1;           ans = r - l;           v.push_back(make_pair(l, r - 1));         } else if (r - l > ans) {           v.clear();           num = 1;           ans = r - l;           v.push_back(make_pair(l, r - 1));         } else if (!v.empty() && r - l == ans) {           num++;           v.push_back(make_pair(l, r - 1));         }         if (high.front() == book[l]) high.pop_front();         if (low.front() == book[l]) low.pop_front();         l++;       }     }     while (l <= n) {       if (v.empty()) {         num = 1;         ans = r - l;         v.push_back(make_pair(l, r - 1));       } else if (r - l > ans) {         v.clear();         num = 1;         ans = r - l;         v.push_back(make_pair(l, r - 1));       } else if (!v.empty() && r - l == ans) {         num++;         v.push_back(make_pair(l, r - 1));       }       if (high.front() == book[l]) high.pop_front();       if (low.front() == book[l]) low.pop_front();       l++;     }     cout << ans <<     << num << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > Dates;   int n, x, y, ans, cur;   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       Dates.push_back(make_pair(x, y));     }     sort(Dates.begin(), Dates.end());     for (int i = 0; i < Dates.size(); i++) {       if (Dates[i].second > cur)         cur = Dates[i].second;       else if (Dates[i].second < cur) {         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   string a[] = { zero ,  one ,  two ,    three ,  four ,                  five ,  six ,  seven ,  eight ,  nine };   string b[] = { ten ,    twenty ,   thirty ,  forty ,  fifty ,                  sixty ,  seventy ,  eighty ,  ninety };   string c[] = { eleven ,   twelve ,     thirteen ,  fourteen ,  fifteen ,                  sixteen ,  seventeen ,  eighteen ,  nineteen };   int main() {     int n;     cin >> n;     if (n < 10) {       cout << a[n] << endl;       return 0;     } else {       if (n % 10 == 0) {         cout << b[(n / 10) - 1] << endl;         return 0;       } else if (n > 10 && n < 20) {         cout << c[(n % 10) - 1] << endl;         return 0;       } else {         cout << b[(n / 10) - 1] <<  -  << a[n % 10] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 3e16;   const int N = 200010;   int n;   int ask(vector<int> v) {     printf( ? );     for (int i = 0; i < n; i++) printf(  %d , v[i]);     printf(  n );     fflush(stdout);     int ans;     scanf( %d , &ans);     return ans;   }   int main() {     scanf( %d , &n);     int pivo = -1;     for (int i = 1; i < n; i++) {       vector<int> tmp(n);       tmp[n - 1] = 1;       for (int j = 0; j < n - 1; j++) {         tmp[j] = 1 + i;       }       int k = ask(tmp);       if (k == 0) {         pivo = i;         break;       }     }     if (pivo == -1) pivo = n;     vector<int> ans(n + 1);     ans[n] = pivo;     for (int i = 1; i <= n; i++) {       if (i == pivo) continue;       vector<int> tmp(n);       tmp[n - 1] = (n + 1) - pivo;       for (int j = 0; j < n - 1; j++) {         tmp[j] = (n + 1) - i;       }       int k = ask(tmp);       ans[k] = i;     }     printf( ! );     for (int i = 1; i <= n; i++) printf(  %d , ans[i]);     printf(  n );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[300000 + 13];   int n;   void erf() {     for (int i = 1; i < n; i++) {       if (a[i - 1].first + 1 >= a[i].first) a[i].first = a[i - 1].first + 1;     }   }   int main() {     int cur, ebte;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     erf();     pair<int, int> b;     for (int i = 0; i < n; i++) {       b = make_pair(a[i].second, a[i].first);       swap(a[i], b);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       cout << a[i].second <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e6;   long long a[100000 + 5];   bool vis[100000 + 5];   char c[] = { 6 ,  7 ,  8 ,  9 ,  T ,  J ,  Q ,  K ,  A };   int main() {     long long n;     string s, s1, s2;     cin >> s >> s1 >> s2;     if (s1[1] == s[0]) {       if (s2[1] != s[0])         cout <<  YES  << endl;       else {         int i = 0;         for (i = 0; i < 9; i++) {           if (s1[0] == c[i]) break;         }         int j = 0;         for (j = 0; j < 9; j++) {           if (s2[0] == c[j]) break;         }         if (i > j)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     } else {       if (s2[1] == s[0])         cout <<  NO  << endl;       else if (s1[1] == s2[1]) {         int i = 0;         for (i = 0; i < 9; i++) {           if (s1[0] == c[i]) break;         }         int j = 0;         for (j = 0; j < 9; j++) {           if (s2[0] == c[j]) break;         }         if (i > j)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getID(char nms[202][30], char s[30], int &len) {     for (int i = 0; i < 30; ++i) {       if (s[i] >=  a  && s[i] <=  z ) s[i] +=  A  -  a ;     }     for (int i = 0; i < len; ++i) {       if (strcmp(nms[i], s) == 0) return i;     }     strcpy(nms[len], s);     len++;     return len - 1;   }   int search(int mailFrom[202], int mailTo[202], int p, int n, int h) {     int max = 0;     for (int i = 0; i < n; ++i) {       if (mailFrom[i] == p) {         int ans = search(mailFrom, mailTo, mailTo[i], n, h + 1);         if (max < ans) max = ans;       }     }     if (max == 0) return h;     return max;   }   int main() {     int n;     while (cin >> n) {       char nms[202][30] = {0};       int len = 0;       int mailFrom[202] = {0};       int mailTo[202] = {0};       bool notHead[202] = {0};       for (int i = 0; i < n; ++i) {         char n1[30], n2[30], t[30];         cin >> n1;         cin >> t;         cin >> n2;         mailFrom[i] = getID(nms, n2, len);         mailTo[i] = getID(nms, n1, len);         notHead[mailTo[i]] = 1;       }       int max = 0;       for (int i = 0; i < n; ++i) {         if (!notHead[i]) {           int ans = search(mailFrom, mailTo, i, n, 1);           if (ans > max) max = ans;         }       }       cout << max << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ;   const long long N = 5e3 + 10;   vector<bitset<N> > v;   vector<pair<long long, pair<long long, long long> > > hor, ver;   long long n, cnt, y11, y2, x1, x2;   long long ans;   bool check(long long x, pair<long long, long long> a) {     return a.first <= x && x <= a.second;   }   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x1 >> y11 >> x2 >> y2;       if (x1 > x2) swap(x1, x2);       if (y11 > y2) swap(y11, y2);       if (x1 == x2)         ver.push_back({x1, {y11, y2}});       else         hor.push_back({y11, {x1, x2}});     }     if ((long long)((hor).size()) > (long long)((ver).size())) swap(hor, ver);     v.resize((long long)((hor).size()));     for (long long i = 0; i < (long long)((hor).size()); i++) {       for (long long j = 0; j < (long long)((ver).size()); j++) {         v[i][j] = check(hor[i].first, ver[j].second) &&                   check(ver[j].first, hor[i].second);       }     }     for (long long i = 0; i < (long long)((v).size()); i++) {       for (long long j = i + 1; j < (long long)((v).size()); j++) {         cnt = (v[i] & v[j]).count();         ans += cnt * (cnt - 1) / 2;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(15);     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }
#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n], i, sum = 0, maxi = -1000000000, mini = 1000000000;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > maxi)           maxi = a[i];         else if (a[i] < mini)           mini = a[i];       }       for (i = 0; i < n - 1; i++) {         long long int pro = a[i] * a[i + 1];         if (pro > sum) {           sum = pro;         }       }       cout << sum <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1760777216 )   using namespace std;   const double Pi = 3.14159265358979323846;   int main() {     int T;     scanf( %d , &T);     while (T--) {       double R, r, k;       scanf( %lf%lf%lf , &R, &r, &k);       double x1 = 0.5 / R, x2 = 0.5 / r, rr = fabs(x1 - x2) / 2;       double x = (x1 + x2) / 2, y = 2 * k * rr, a = x / sqrt(x * x + y * y);       double dx = rr * a, dy = rr * sqrt(1 - a * a);       double res = sqrt(x * x + y * y);       printf( %.9lf n , (1 / (res - rr) - 1 / (res + rr)) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool arr[100100];   int dp[100100];   int pref[100100];   int pref2[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     char a;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a ==  G ) arr[i] = true;     }     for (int i = 1; i <= n; i++) {       if (arr[i]) pref[i] = pref[i - 1] + 1;     }     for (int i = 1; i <= n; i++) {       pref2[i] = pref2[i - 1] + arr[i];     }     if (pref2[n] == n) {       cout << n << endl;       return 0;     }     if (pref2[n] == 0) {       cout << 0 << endl;       return 0;     }     for (int i = n; i >= 1; i--) {       if (pref[i - 1] > 0 && pref[i] > 0) pref[i - 1] = pref[i];     }     int ma = -1e9;     for (int i = 1; i <= n; i++) {       if (!arr[i]) {         if (pref[i - 1] + pref[i + 1] < pref2[n])           ma = max(ma, pref[i - 1] + pref[i + 1] + 1);         else           ma = max(ma, pref[i - 1] + pref[i + 1]);       }     }     cout << ma << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream f( test.in );   ofstream g( test.out );   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, ans = 0;       cin >> n;       stack<int> s;       int x;       cin >> x;       s.push(x);       for (int i = 2; i <= n; i++) {         cin >> x;         while (!s.empty() and s.top() > x) {           ans++;           s.pop();         }         s.push(x);       }       while (!s.empty()) s.pop();       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<set<int> > newadj(212345);   int visit[212345];   vector<vector<int> > adj(212345);   vector<int> vec, vecans;   set<int> seti;   int cnt = 0;   int pos[212345];   int dfs(int cur) {     cnt++;     visit[cur] = 1;     set<int>::iterator it;     for (it = newadj[cur].begin(); it != newadj[cur].end(); it++) {       if (!visit[*it]) {         dfs(*it);       }     }     return 0;   }   int main() {     std::ios::sync_with_stdio(false);     int n, m;     int i, j, u, v;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     int mini = (1000 * 1000 * 1000 + 5), vert;     for (i = 0; i < n; i++) {       if (mini > adj[i].size()) {         mini = adj[i].size();         vert = i;       }     }     int sumi = 0;     for (i = 0; i < n; i++) {       sumi++;       pos[i] = vert;     }     vec.push_back(vert);     for (i = 0; i < adj[vert].size(); i++) {       sumi--;       pos[adj[vert][i]] = adj[vert][i];       vec.push_back(adj[vert][i]);       seti.insert(adj[vert][i]);     }     seti.insert(vert);     set<int>::iterator it;     for (i = 1; i < vec.size(); i++) {       for (it = seti.begin(); it != seti.end(); it++) {         newadj[vec[i]].insert(*it);       }       cnt = 0;       for (j = 0; j < adj[vec[i]].size(); j++) {         if (pos[adj[vec[i]][j]] == vert) {           cnt++;           continue;         }         newadj[vec[i]].erase(pos[adj[vec[i]][j]]);       }       if (cnt == sumi) {         newadj[vec[i]].erase(vert);       } else {         newadj[vert].insert(vec[i]);       }     }     for (i = 0; i < vec.size(); i++) {       if (!visit[vec[i]]) {         cnt = 0;         dfs(vec[i]);         if (i == 0) {           cnt += sumi - 1;         }         vecans.push_back(cnt);       }     }     sort(vecans.begin(), vecans.end());     cout << vecans.size() << endl;     for (i = 0; i < vecans.size(); i++) {       cout << vecans[i] <<    ;     }     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int b = -1, n = 0, limit = 10;     string pass, box =  0000000000 , zero, one, two, three, four, five, six,                  seven, eight, nine;     cin >> pass;     cin >> zero;     cin >> one;     cin >> two;     cin >> three;     cin >> four;     cin >> five;     cin >> six;     cin >> seven;     cin >> eight;     cin >> nine;     while (n < 8) {       for (int i = b + 1, i2 = 0; i < limit; i++, i2++) {         box[i2] = pass[i];         b = i;       }       if (box == zero)         cout <<  0 ;       else if (box == one)         cout <<  1 ;       else if (box == two)         cout <<  2 ;       else if (box == three)         cout <<  3 ;       else if (box == four)         cout <<  4 ;       else if (box == five)         cout <<  5 ;       else if (box == six)         cout <<  6 ;       else if (box == seven)         cout <<  7 ;       else if (box == eight)         cout <<  8 ;       else if (box == nine)         cout <<  9 ;       n++;       limit += 10;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 20;   const int MAXS = (1 << 16) + 10;   long long dp[MAXS];   int ans[MAXN], req[MAXN];   bool vis[MAXN];   int main() {     long long n, y, m;     cin >> n >> y >> m;     y -= 2001;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       req[b - 1] |= (1 << (a - 1));     }     memset(ans, -1, sizeof ans);     for (int i = 0; i < n; i++) {       for (ans[i] = 0; ans[i] < n; ans[i]++) {         if (!vis[ans[i]]) {           memset(dp, 0, sizeof dp);           dp[0] = 1;           for (int s = 0; s < (1 << n); s++) {             if (dp[s] > 0) {               for (int j = 0; j < n; j++) {                 if (!(s & (1 << j))) {                   if ((ans[j] == -1 || ans[j] == __builtin_popcount(s)) &&                       ((s & req[j]) == req[j])) {                     dp[s | (1 << j)] += dp[s];                   }                 }               }             }           }           if (y >= dp[(1 << n) - 1]) {             y -= dp[(1 << n) - 1];           } else {             vis[ans[i]] = true;             break;           }         }       }       if (ans[i] >= n) {         cout <<  The times have changed  << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       cout << ans[i] + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   const long long N = 2e5 + 100;   vector<long long> v[N];   long long dfn[N], num[N], val[N], sz[N], hs[N], tp[N], dep[N], f[N];   inline void dfs(long long x, long long fa) {     sz[x] = 1;     long long num = 0;     dep[x] = dep[fa] + 1;     f[x] = fa;     for (auto y : v[x]) {       if (y == fa) continue;       dfs(y, x);       sz[x] += sz[y];       if (num < sz[y]) hs[x] = y, num = sz[y];     }   }   long long cnt;   inline void redfs(long long x, long long fa, long long top) {     tp[x] = top;     dfn[x] = ++cnt;     num[cnt] = x;     if (hs[x]) redfs(hs[x], x, top);     for (auto y : v[x]) {       if (y == fa || y == hs[x]) continue;       redfs(y, x, y);     }   }   struct seg {     long long l, r, v;   } t[N << 2];   long long a[N];   inline void build(long long p, long long l, long long r) {     t[p].l = l, t[p].r = r;     if (l == r) {       t[p].v = abs(val[num[l]]);       return;     }     long long mid = l + r >> 1;     build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);     t[p].v = t[p << 1].v + t[p << 1 | 1].v;   }   inline void modify(long long p, long long x, long long v) {     if (t[p].l == t[p].r) {       t[p].v = v;       return;     }     long long mid = t[p].l + t[p].r >> 1;     if (x <= mid)       modify(p << 1, x, v);     else       modify(p << 1 | 1, x, v);     t[p].v = t[p << 1].v + t[p << 1 | 1].v;   }   inline long long query(long long p, long long x, long long y) {     if (x <= t[p].l && t[p].r <= y) {       return t[p].v;     }     long long mid = t[p].l + t[p].r >> 1;     if (y <= mid) return query(p << 1, x, y);     if (x > mid) return query(p << 1 | 1, x, y);     return query(p << 1, x, y) + query(p << 1 | 1, x, y);   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> val[i], val[i] = abs(val[i]);     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y), v[y].push_back(x);     }     dfs(1, 0);     redfs(1, 0, 1);     build(1, 1, n);     for (long long i = 1; i <= q; i++) {       long long opt, x, y;       cin >> opt >> x >> y;       if (opt == 1) {         modify(1, dfn[x], abs(y));         val[x] = abs(y);       } else {         long long ans = 0, X = x, Y = y;         ;         while (tp[x] != tp[y]) {           if (dep[tp[x]] < dep[tp[y]]) swap(x, y);           ans += query(1, dfn[tp[x]], dfn[x]);           x = f[tp[x]];         }         if (dep[x] < dep[y]) swap(x, y);         ans += query(1, dfn[y], dfn[x]);         cout << ans * 2 - val[X] - val[Y] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 200;   const int M = 1e9 + 7;   const long long M2 = 1ll * M * M;   int n;   long long a[N];   int mat[N][N];   int result[N][N];   void multiply(int a[N][N], int b[N][N]) {     static int c[N][N];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long result = 0;         for (int z = 0; z < n; z++) {           result += 1ll * a[i][z] * b[z][j];           if (result >= M2) {             result -= M2;           }         }         c[i][j] = result % M;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         a[i][j] = c[i][j];       }     }   }   void power(long long n) {     for (int i = 0; i < ::n; i++) {       result[i][i] = 1;     }     for (; n > 0; n >>= 1) {       if (n & 1) {         multiply(result, mat);       }       multiply(mat, mat);     }   }   int main() {     long long k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long x = a[i] ^ a[j];         int cnt = 0;         while (x > 0) {           cnt += x & 1;           x /= 2;         }         if (cnt % 3 == 0) {           mat[i][j]++;         }       }     }     power(k - 1);     int answer = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         answer += result[i][j];         if (answer >= M) {           answer -= M;         }       }     }     cout << answer << endl;     return 0;   }