malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int INF = (1 << 31) - 1;   const double EPS = 1E-9;   const double PI = acos(-1);   using namespace std;   vector<bool> U;   vector<vector<int> > G;   vector<int> P, order, T;   int M[5100][5100];   void dfs(int v) {     U[v] = true;     for (int i = 0; i < G[v].size(); ++i)       if (!U[G[v][i]]) {         P[G[v][i]] = v;         dfs(G[v][i]);       }     order.push_back(v);   }   int main() {     int n, a, b, c;     cin >> n;     priority_queue<pair<int, int> > Q[n];     G.resize(n);     P.resize(n);     T.resize(n);     T.assign(n, 0);     U.resize(n);     U.assign(n, false);     for (int i = 0; i < n; ++i) {       cin >> a;       Q[i].push(make_pair(-a, i));     }     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b >> c;       G[a - 1].push_back(b - 1);       G[b - 1].push_back(a - 1);       M[a - 1][b - 1] = c;       M[b - 1][a - 1] = c;     }     P[0] = -1;     dfs(0);     int TIMER = 0;     reverse(order.begin(), order.end());     while (Q[0].size() < n) {       TIMER++;       for (int i = 1; i < n; ++i)         for (int j = 0; j < M[order[i]][P[order[i]]] && !Q[order[i]].empty();              ++j) {           pair<int, int> v = Q[order[i]].top();           Q[order[i]].pop();           Q[P[order[i]]].push(v);           if (P[order[i]] == 0) T[v.second] = TIMER;         }     }     for (int i = 0; i < n; ++i) cout << T[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 7;   const long long maxn = 1e6 + 9;   const long long inf = 1e9 + 7;   set<long long> W, H;   multiset<long long> l1, l2;   long long w, h, n, a;   long long x, y;   char c;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> w >> h >> n;     W.insert(0);     W.insert(w);     l1.insert(w);     H.insert(0);     H.insert(h);     l2.insert(h);     long long maxx;     while (n--) {       cin >> c >> a;       if (c ==  V ) {         W.insert(a);         x = *prev(W.find(a));         y = *next(W.find(a));         auto it = l1.find(y - x);         l1.erase(it);         l1.insert(y - a);         l1.insert(a - x);       } else {         H.insert(a);         x = *prev(H.find(a));         y = *next(H.find(a));         auto it = l2.find(y - x);         l2.erase(it);         l2.insert(y - a);         l2.insert(a - x);       }       long long p = *prev(l1.end());       long long q = *prev(l2.end());       cout << p * q <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 6;   const long long MOD = 1e9 + 7;   int par[MAX];   long long sz[MAX];   long long triplets(long long x) { return x * (x - 1) * (x - 2); }   bool isLucky(long long x) {     while (x) {       if (x % 10 != 4 and x % 10 != 7) return false;       x /= 10;     }     return true;   }   int Find(int u) {     if (u == par[u]) return u;     return par[u] = Find(par[u]);   }   void Union(int u, int v) {     u = Find(u);     v = Find(v);     if (sz[u] < sz[v]) swap(u, v);     if (u != v) {       par[v] = u;       sz[u] += sz[v];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     for (int i = 1; i <= n - 1; i++) {       long long u, v, w;       cin >> u >> v >> w;       if (!isLucky(w)) Union(u, v);     }     long long ans = n * (n - 1) * (n - 2);     for (int i = 1; i <= n; i++) {       if (Find(i) == i) {         ans -= 2 * sz[i] * (sz[i] - 1) * (n - sz[i]) +                sz[i] * (sz[i] - 1) * (sz[i] - 2);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.L);   struct Point {     double x;     double y;     Point() {       x = 0;       y = 0;     }     Point(double x, double y) : x(x), y(y) {}     Point operator+(const Point& other) const {       return Point(x + other.x, y + other.y);     }     Point operator-(const Point& other) const {       return Point(x - other.x, y - other.y);     }     double operator*(const Point& other) const {       return x * other.x + y * other.y;     }     double operator^(const Point& other) const {       return x * other.y - y * other.x;     }   };   ostream& operator<<(ostream& s, Point p) { return s << p.x <<     << p.y; }   int main() {     double px, py, vx, vy, a, b, c, d;     cin >> px >> py >> vx >> vy >> a >> b >> c >> d;     Point displ(px, py);     Point t1(0, b);     Point t2(-a / 2., 0);     Point t3(-c / 2., 0);     Point t4(-c / 2., -d);     Point t5(c / 2., -d);     Point t6(c / 2., 0);     Point t7(a / 2., 0);     double angle = atan2(vy, vx) - PI / 2.;     Point rotx(cos(angle), -sin(angle));     Point roty(sin(angle), cos(angle));     cout << fixed << setprecision(12);     Point s1(rotx * t1, roty * t1);     s1 = s1 + displ;     Point s2(rotx * t2, roty * t2);     s2 = s2 + displ;     Point s3(rotx * t3, roty * t3);     s3 = s3 + displ;     Point s4(rotx * t4, roty * t4);     s4 = s4 + displ;     Point s5(rotx * t5, roty * t5);     s5 = s5 + displ;     Point s6(rotx * t6, roty * t6);     s6 = s6 + displ;     Point s7(rotx * t7, roty * t7);     s7 = s7 + displ;     cout << s1 <<   n           << s2 <<   n           << s3 <<   n           << s4 <<   n           << s5 <<   n           << s6 <<   n           << s7 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200], b[200];     int countA = 0;     int countB = 0;     int countC = 0;     int n = 0;     cin >> 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++) {       if (a[i] == 1 && b[i] == 0) countA++;       if (a[i] == b[i]) countB++;       if (a[i] < b[i]) countC++;     }     if (countA == 0) {       countA = -1;     } else {       countA = (countC / countA) + 1;     }     printf( %d , countA);     return 0;   }
#include <bits/stdc++.h>   int search(int n, long long int a[n], long long int target) {     int i;     if (a[0] >= target) {       printf( 1 %lld n , target);       return 0;     }     int L = 0, R = n - 1;     int M;     while ((R - L) > 1) {       if ((L + R) % 2 == 0) {         M = (L + R) / 2;       } else {         M = (L + R - 1) / 2;       }       if (a[M] < target) {         L = M;       } else if (a[M] == target) {         printf( %d %lld n , M + 1, target - a[M - 1]);         return 0;       } else {         R = M;       }     }     if (target == a[L]) {       printf( %d %lld n , L + 1, target);       return 0;     } else if (target == a[R]) {       printf( %d %lld n , R + 1, target - a[R - 1]);     } else {       printf( %d %lld n , L + 2, target - a[L]);     }   }   int main() {     int n, m, i;     scanf( %d %d , &n, &m);     long long int a[n];     long long int b[m];     long long int sum = 0;     long long int tmp;     for (i = 0; i < n; i++) {       scanf( %lld , &tmp);       a[i] = tmp + sum;       sum = tmp + sum;     }     for (i = 0; i < m; i++) {       scanf( %lld , &b[i]);     }     for (i = 0; i < m; i++) search(n, a, b[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int main() {     int n;     cin >> n;     int i, j, sum = 0, in;     int a[n];     for (i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     int x = n / 2;     int avg = sum / x;     for (i = 0; i < n; i++) {       if (a[i] == 0) continue;       cout << i + 1 <<    ;       for (j = i + 1; j < n; j++) {         if (a[j] == 0) continue;         if ((a[j] + a[i]) == avg) {           cout << j + 1 <<    ;           a[j] = 0;           a[i] = 0;           break;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   const long long N = 1e6 + 5;   void solve() {     long long n;     cin >> n;     vector<vector<long long>> a;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       vector<long long> temp(x);       for (long long j = 0; j < x; j++) cin >> temp[j];       a.push_back(temp);     }     set<vector<long long>> vis;     set<vector<long long>> banned;     long long m;     cin >> m;     for (long long i = 0; i < m; i++) {       vector<long long> temp(n);       for (long long j = 0; j < n; j++) {         cin >> temp[j];         temp[j]--;       }       banned.insert(temp);     }     set<pair<long long, vector<long long>>> st;     long long s = 0;     vector<long long> temp;     for (long long i = 0; i < n; i++) {       s += a[i][(long long)a[i].size() - 1];       temp.push_back((long long)a[i].size() - 1);     }     st.insert({s, temp});     vis.insert(temp);     while (!st.empty()) {       auto [val, vec] = *prev(st.end());       st.erase(prev(st.end()));       if (banned.find(vec) == banned.end()) {         for (auto i : vec) cout << i + 1 <<    ;         return;       }       for (long long i = 0; i < n; i++) {         if (vec[i] - 1 >= 0) {           long long newval = val - a[i][vec[i]] + a[i][vec[i] - 1];           vector<long long> newvec = vec;           newvec[i]--;           if (vis.find(newvec) == vis.end()) {             st.insert({newval, newvec});             vis.insert(newvec);           }         }       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> vec;       for (int i = 0; i < n; i++) {         int d;         cin >> d;         vec.insert(d);       }       cout << vec.size() <<   n ;     }   }
#include <bits/stdc++.h>   long long k;   int _, n, a[200020];   int main() {     for (scanf( %d , &_); _--;) {       scanf( %d%lld , &n, &k);       for (int i = 0; i < n; i++) scanf( %d , a + i);       for (int i = 0; i < (k & 1) + 2; i++)         for (int i = 0, d = *std::max_element(a, a + n); i < n; i++)           a[i] = d - a[i];       for (int i = 0 * puts(  ); i < n; i++) printf( %d  , a[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = atan(1.0) * 4.0;   const long long int MOD = 1e9 + 7;   const long long int INF = 1e18;   const long double EPS = 0.0000001;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     map<char, int> a;     for (int i = 0; i < n; i++) a[s[i]]++;     int j = 97;     while (k != 0 && j <= 122) {       for (int i = 0; i < n; i++) {         if (s[i] == char(j)) {           s[i] =  * ;           k--;           if (k == 0) break;         }       }       j++;     }     for (int i = 0; i < n; i++) {       if (s[i] !=  * ) cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct abc {     int val, key, s, e, ind;   } z[100005];   bool cmp(abc a, abc b) {     if (a.key == b.key) return a.val < b.val;     return a.key > b.key;   }   bool cmp1(abc a, abc b) { return a.ind < b.ind; }   int main() {     int n, m, i, j, k, a[100005], l;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < m; i++) {       scanf( %d , &z[i].val);       scanf( %d , &z[i].key);       z[i].ind = i;     }     sort(z, z + m, cmp);     for (i = 0; i < n - 1; i++) {       z[i].s = i + 1;       z[i].e = i + 2;     }     l = 1;     j = 1;     k = 3;     for (i = n - 1; i < m; i++) {       if (z[i].val >= z[k - 2].val) {         z[i].s = j;         z[i].e = k;         j++;         if (j == k - 1) {           j = 1;           k++;         }       } else {         l = 0;         break;       }     }     if (l == 0)       printf( -1 n );     else {       sort(z, z + m, cmp1);       for (i = 0; i < m; i++) printf( %d %d n , z[i].s, z[i].e);     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int a[505],ch[505][505],cnt[505];   int main(){       ios_base::sync_with_stdio(0),cin.tie(0);       int n,c=0,i,j;       cin>>n;       for(i=1;i<=n;i++)cin>>a[i],ch[i][i]=a[i],cnt[a[i]]=a[i]-1;       for(i=1;i<=n&&c==0;i++){           int x,y;           x=y=i;           while(cnt[a[i]]>0){               cnt[a[i]]--;               if(x-1>0&&ch[y][x-1]==0)x--,ch[y][x]=a[i];               else if(y+1<=n&&ch[y+1][x]==0)y++,ch[y][x]=a[i];               else {c=1;break;}           }       }       if(c)cout<< -1 n ;       else{           for(i=1;i<=n;i++){               for(j=1;j<=i;j++)cout<<ch[i][j]<<   ;               cout<<endl;           }       }       return 0;   }
#include <bits/stdc++.h>   #define int long long   #define mp make_pair   #define pb push_back   #define ld long double   #define pii pair<int,int>   #define sz(x) (int)x.size()   #define piii pair<pii,pii>   #define precise cout<<fixed<<setprecision(10)   #define st first   #define nd second   #define ins insert   #define vi vector<int>   #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)   using namespace std;   const int MAX=5005;   pii p[MAX];   bool O[MAX];   int dist(pii a,pii b){      return (a.st-b.st)*(a.st-b.st)+(a.nd-b.nd)*(a.nd-b.nd);   }   int32_t main(){     BOOST;     int n;     cin>>n;     for (int i=1;i<=n;i++){       cin>>p[i].st>>p[i].nd;     }          vi ans;     ans.clear();     ans.pb(1);     O[1]=true;     while (sz(ans)<n){       int x=ans.back();       int maxi=0,wsk=-1;       for (int i=1;i<=n;i++){         if (!O[i] && dist(p[x],p[i])>maxi){            maxi=dist(p[x],p[i]);            wsk=i;         }       }       assert(wsk!=-1);       O[wsk]=true;       ans.pb(wsk);     }     for (auto it:ans)cout<<it<<   ;     return 0;    }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 9, lg = 19, MOD = 998244353, maxV = 1e3 + 9;   int T[3][maxN], n, q, arr[maxN], mp[129];   priority_queue<int> pqs[2][3];   string st;   int query(int w, int *T) {     int ret = 0;     for (w++; w > 0; w -= w & -w) ret += T[w];     return ret;   }   int query(int l, int r, int *T) { return query(r - 1, T) - query(l - 1, T); }   void update(int w, int x, int *T) {     for (w++; w <= n; w += w & -w) T[w] += x;   }   pair<int, int> getpa(int heroe, int mamon, priority_queue<int> *pqs) {     if (pqs[mamon].empty()) return pair<int, int>(n, n);     if (pqs[heroe].empty()) return pair<int, int>(0, pqs[mamon].top());     return pair<int, int>(min(pqs[mamon].top(), pqs[heroe].top()),                           pqs[mamon].top());   }   pair<int, int> gira(pair<int, int> x) {     return pair<int, int>(n - x.second, n - x.first);   }   int mergpl(pair<int, int> one, pair<int, int> two, int *lT) {     if (one > two) swap(one, two);     if (two.first < one.second)       return query(one.first, max(one.second, two.second), lT);     return query(one.first, one.second, lT) + query(two.first, two.second, lT);   }   int countGood() {     int ret = 0;     for (int u = 0, offs = 0, mu = 1; u < 2; u++, offs = n - 1, mu = -1)       for (int i = 0; i < 3; i++)         while (pqs[u][i].size() && arr[offs + mu * pqs[u][i].top()] != i)           pqs[u][i].pop();     for (int i = 0; i < 3; i++) {       int heroe = (i + 1) % 3, mamon = (i + 2) % 3;       ret += query(n - 1, T[i]) - mergpl(getpa(heroe, mamon, pqs[0]),                                          gira(getpa(heroe, mamon, pqs[1])), T[i]);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     mp[ R ] = 1;     mp[ S ] = 2;     cin >> n >> q >> st;     for (int i = 0; i < n; i++) {       arr[i] = mp[st[i]];       pqs[0][arr[i]].push(i);       pqs[1][arr[i]].push(n - 1 - i);       update(i, 1, T[arr[i]]);     }     cout << countGood() <<   n ;     while (q--) {       int pos;       char c;       cin >> pos >> c;       pos--;       update(pos, -1, T[arr[pos]]);       arr[pos] = mp[c];       update(pos, 1, T[arr[pos]]);       pqs[0][arr[pos]].push(pos);       pqs[1][arr[pos]].push(n - 1 - pos);       cout << countGood() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int NN = 1010;   double first[NN], second[NN];   int main() {     int n, a, b, c, d;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       double s = a * a * d * d + c * c * b * b;       first[i] = a * b * d * d / s;       second[i] = c * b * b * d / s;     }     const double eps = 1e-9;     vector<pair<pair<double, double>, double> > line(n * (n - 1) / 2);     for (int i = 0, id = 0; i < n; i++)       for (int j = i + 1; j < n; j++, id++) {         line[id] =             make_pair(make_pair(first[i] + first[j], second[i] + second[j]),                       fabs(first[i] - first[j]) < eps                           ? 1e9                           : (second[i] - second[j]) / (first[i] - first[j]));       }     sort(line.begin(), line.end(),          [&](const pair<pair<double, double>, double> &a,              const pair<pair<double, double>, double> &b) {            if (fabs(a.first.first - b.first.first) > eps)              return a.first.first < b.first.first;            if (fabs(a.first.second - b.first.second) > eps)              return a.first.second < b.first.second;            return a.second < b.second - eps;          });     auto cmp1 = [&](double first, double second) {       return fabs(first - second) < eps;     };     auto cmp = [&](pair<double, double> first, pair<double, double> second) {       return cmp1(first.first, second.first) && cmp1(first.second, second.second);     };     int ans = 0;     const int mod = 1000000007;     for (int i = 0, j, k; i < line.size(); i = j) {       int mid = 1;       for (j = i; j < line.size() && cmp(line[i].first, line[j].first); j = k) {         for (k = j; k < line.size() && cmp(line[k].first, line[j].first) &&                     cmp1(line[j].second, line[k].second);              k++)           ;         mid = (long long)mid * (k - j + 1) % mod;       }       mid = (mid + mod - 1 - j + i) % mod;       ans += mid;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       set<pair<pair<long long, long long>, pair<long long, long long> > > rem;       long long xi = 0, yi = 0, xf = 0, yf = 0;       string s;       cin >> s;       long long ans = 0;       for (long long i = 0; i < (long long)(s.length()); ++i) {         if (s[i] ==  N ) {           yf++;         } else if (s[i] ==  S ) {           yf--;         } else if (s[i] ==  E ) {           xf++;         } else {           xf--;         }         if (rem.count({{xi, yi}, {xf, yf}})) {           ans += 1;         } else {           ans += 5;           rem.insert({{xi, yi}, {xf, yf}});           rem.insert({{xf, yf}, {xi, yi}});         }         xi = xf;         yi = yf;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 7;   long long n;   pair<long double, long double> a[MAXN];   void read() {     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     bool ch1 = 0, ch2 = 0;     for (long long i = 0; i < n; ++i) {       if (a[i].second < 0)         ch1 = 1;       else         ch2 = 1;     }     if (ch1 && ch2) {       cout <<  -1 n ;       exit(0);     }   }   const long double INF = 1e16;   const long long IT = 100;   bool check(long double r) {     long double tl = -INF, tr = INF;     for (long long i = 0; i < n; ++i) {       if (abs(a[i].second - r) > r) return 0;       long double d = sqrtl(r * r - (a[i].second - r) * (a[i].second - r));       tl = max(tl, a[i].first - d);       tr = min(tr, a[i].first + d);     }     return tl <= tr;   }   long double ans = INF;   void solve() {     for (long long i = 0; i < n; ++i) a[i].second = abs(a[i].second);     long double l = 0;     long double r = INF;     for (long long i = 0; i < IT; ++i) {       long double m = (l + r) / 2;       if (check(m))         r = m;       else         l = m;     }     ans = r;   }   void print() { cout << ans <<   n ; }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     read();     solve();     print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     if (n % 2 == 1) {       ans = a[(n - 1) / 2];     }     if (n % 2 == 0) {       ans = a[(n / 2) - 1];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 5;   int n, k, top;   int a[N], l[N], r[N], s[N];   long long ans;   long long calc(int l, int r) {     if (l > r || r - l + 1 < k) return 0;     int m = (r - l + 2 - k) / (k - 1);     long long ret = 1LL * (m + 1) * (r - l + 2 - k) % mod -                     1LL * (1 + m) * m / 2 % mod * (k - 1) % mod;     return ret;   }   int main() {     int i;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i <= n; ++i) {       while (top && a[s[top]] < a[i]) --top;       l[i] = s[top] + 1, s[++top] = i;     }     top = 0, s[top] = n + 1;     for (i = n; i; --i) {       while (top && a[s[top]] <= a[i]) --top;       r[i] = s[top] - 1, s[++top] = i;     }     for (i = 1; i <= n; ++i)       ans = (ans +              (calc(l[i], r[i]) - calc(l[i], i - 1) - calc(i + 1, r[i])) * a[i]) %             mod;     if (ans < 0) ans += mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n;   int a[11][11] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0},                    {2, 0, 1}, {0, 2, 1}, {0, 1, 2}};   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     cout << a[n % 6][m] << endl;     return 0;   }