malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   namespace stuff {   void solve(int test_num) {     int R, C;     cin >> R >> C;     vector<string> grid(R);     for (int r = 0; r < R; r++) cin >> grid[r];     vector<vector<int> > cnt(R, vector<int>(C, 0));     for (int r = 0; r < R; r++) {       for (int c = 0; c < C; c++) {         const int X = grid[r][c] ==  W  ? 1 : -1;         cnt[r][c] += X;         if (r > 0) cnt[r - 1][c] -= X;         if (c > 0) cnt[r][c - 1] -= X;         if (r > 0 && c > 0) cnt[r - 1][c - 1] += X;       }     }     int res = 0;     for (int r = 0; r < R; r++)       for (int c = 0; c < C; c++)         if (cnt[r][c] != 0) res++;     cout << res << endl;   }   void solve() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     for (int t = 1; t <= T; t++) solve(t);   }   }  // namespace stuff   int main() {     stuff::solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, temp = 0;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int i;     for (i = 1; i <= n; i++) {       temp += i;       if (temp >= k) break;     }     int gap = temp - k;     cout << a[i - gap - 1];   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   set<long long> ns;   long long p2[100];   int main() {     int n, i, j;     int cnt = 0;     long long t = 1;     while (t < 2000000000) {       cnt++;       p2[cnt] = t;       t *= 2;     }     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       ns.insert(a[i]);     }     sort(a + 1, a + 1 + n);     for (i = 2; i < n; i++) {       for (j = 1; j <= cnt; j++) {         long long t1 = a[i] - p2[j], t2 = a[i] + p2[j];         if (ns.find(t1) != ns.end() && ns.find(t2) != ns.end()) {           puts( 3 );           cout << t1 <<     << a[i] <<     << t2 << endl;           return 0;         }       }     }     for (i = 2; i <= n; i++) {       for (j = 1; j <= cnt; j++) {         long long t1 = a[i] - p2[j];         if (ns.find(t1) != ns.end()) {           puts( 2 );           cout << t1 <<     << a[i] << endl;           return 0;         }       }     }     puts( 1 );     cout << a[1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   constexpr int N = 1e2 + 5;   int n, m, k, g[N][N], ans = -1, id;   unordered_set<int> dp[N][N];   char c;   bool check(int i, int j, int val) {     for (auto el : dp[i][j]) {       if (ans == el + val) {         ans -= val;         return true;       }     }     return false;   }   void Solve() {     cin >> n >> m >> k;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) {         dp[i][j].reserve(1024);         dp[i][j].max_load_factor(0.25);       }     for (int i = 0; i < N; i++) dp[0][i] = {0};     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         g[i][j] = c -  0 ;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (auto el : dp[i - 1][j - 1]) dp[i][j].insert(el + g[i][j]);         for (auto el : dp[i - 1][j + 1]) dp[i][j].insert(el + g[i][j]);       }     for (int i = 1; i <= m; i++)       for (auto el : dp[n][i]) {         if (!(el % (k + 1))) {           if (ans < el) {             ans = el;             id = i;           }         }       }     cout << ans <<   n ;     if (ans == -1) return;     cout << id <<   n ;     for (int i = n; i > 1; i--) {       if (check(i - 1, id - 1, g[i][id])) {         id = id - 1;         cout <<  L ;       } else if (check(i - 1, id + 1, g[i][id])) {         id = id + 1;         cout <<  R ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int SG(double x) { return x > -1E-8 ? x < 1E-8 ? 0 : 1 : -1; }   int c[1000000];   int main() {     int n, m, r, i, j, k, d;     long long md;     scanf( %d %d %d , &n, &m, &r);     for (i = 0; i < (n); i++) {       scanf( %d , &c[i]);     }     if (n % 2 == 0) {       puts( 0 );       return 0;     }     d = (n + 1) / 2;     md = (long long)(m / d) * (long long)r;     for (i = 0; i < n; i += 2) {       if (c[i] < md) md = c[i];     }     printf( %I64d n , md);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     double general_sum, sum;     general_sum = sum = 0;     int i = 0;     int j = 0;     cin >> n >> k;     vector<int> a(n);     double w = n - k + 1;     for (i; i < w; i++) {       if (i == 0) {         for (j; j < k; j++) {           cin >> a[j];           sum += a[j];         }       } else {         cin >> a[j];         sum += a[j];         sum -= a[i - 1];         j++;       }       general_sum += sum;     }     cout.precision(6);     cout << fixed << general_sum / w << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const int inf = 0x3f3f3f3f;   int n, a[N], ma[N][N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (a[i] > a[j]) cnt++;     int ans = cnt, tot = 1;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ma[i][j] = ma[i][j - 1] + (a[i] < a[j]);     for (int i = n; i >= 1; i--)       for (int j = i - 1; j >= 1; j--) ma[i][j] = ma[i][j + 1] + (a[i] > a[j]);     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int aa = ma[i][j - 1], bb = ma[j][i + 1];         int tmp = cnt + aa - (j - i - 1 - aa) + bb - (j - i - 1 - bb);         tmp += (a[i] < a[j] ? 1 : -1);         if (ans > tmp) {           ans = tmp;           tot = 1;         } else if (ans == tmp)           tot++;       }     }     printf( %d %d n , ans, tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, K, f[110][110][30], ans = -1e9 - 7, a[30][30], c;   char s[110], x, y;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     scanf( %d%d , &K, &m);     for (int i = 1; i <= m; i++) {       scanf(  %c %c %d , &x, &y, &c);       a[x -  a ][y -  a ] = c;     }     memset(f, 0xcf, sizeof(f));     for (int i = 0; i < 26; i++) f[1][s[1] -  a  == i ? 0 : 1][i] = 0;     for (int i = 2; i <= n; i++)       for (int j = 0; j <= min(i, K); j++)         for (int k = 0; k < 26; k++)           for (int l = 0; l < 26; l++)             if (s[i] -  a  == l)               f[i][j][l] = max(f[i][j][l], f[i - 1][j][k] + a[k][l]);             else if (j)               f[i][j][l] = max(f[i][j][l], f[i - 1][j - 1][k] + a[k][l]);     for (int j = 0; j <= K; j++)       for (int k = 0; k < 26; k++) ans = max(ans, f[n][j][k]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     int cur = 1;     for (int i = 0; i < n; i++) {       if (cur <= arr[i]) {         cur++;       }     }     cout << cur;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int i = 1;     while (i < n) {       if (a[i] > a[i - 1])         i++;       else         break;     }     if (n == 1) {       cout <<  YES ;       return 0;     }     while (i < n) {       if (a[i] == a[i - 1])         i++;       else         break;     }     while (i < n) {       if (a[i] < a[i - 1])         i++;       else         break;     }     if (i == n)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, x, y, z, q, w, e;   int main() {     cin >> a >> b >> c >> x >> y >> z;     q = a - x;     if (q > 0) q /= 2;     w = b - y;     if (w > 0) w /= 2;     e = c - z;     if (e > 0) e /= 2;     if (q + w + e >= 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 0.000000001;   double x[200000];   int n;   void solve() {     if (abs(x[1]) < eps) {       int p = 0;       for (int i = 1; i < n; i++)         if (abs(x[i]) > eps) p++;       if (p == 0) {         printf( 1 n );         exit(0);       }       return;     }     double q = x[2] / x[1];     for (int i = 3; i < n; i++) {       if (abs(x[i]) < eps) {         if (abs(q) > eps) return;       } else if (abs(x[i] / x[i - 1] - q) > eps)         return;     }     printf( 1 n );     exit(0);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %lf , &x[i]);     if (abs(x[0]) < eps) {       int p = 0;       for (int i = 0; i < n; i++)         if (abs(x[i]) > eps) p++;       if (p < 2) {         printf( %d n , p);         return 0;       }       solve();       printf( 2 n );       return 0;     }     if (n < 3) {       printf( 0 n );       return 0;     }     double q = x[1] / x[0];     int p = 0;     for (int i = 2; i < n; i++) {       if (abs(x[i]) < eps) {         if (abs(q) > eps) {           if (p == 1) {             p = 2;             break;           }           p = 1;           x[i] = x[i - 1];         }       } else if (abs(x[i] / x[i - 1] - q) > eps) {         if (p == 1) {           p = 2;           break;         }         p = 1;         if (abs(x[i] - x[i - 1]) > eps && i != n - 1) {           if (abs(x[i + 1] / x[i - 1] - q) < eps)             x[i] = x[i - 1];           else if (abs(x[i + 1] / x[i] - q) > eps) {             p = 2;             break;           }         }       }     }     if (p < 2) {       printf( %d n , p);       return 0;     }     solve();     swap(x[0], x[1]);     solve();     printf( 2 n );     return 0;   }
#pragma GCC optimize ( O3 )   #include <bits/stdc++.h>      using namespace std;   typedef long long ll;   #define endl   n    const ll DIM = 607;   const ll INF = 1E18;   vector<pair<int,ll> > G[DIM];   ll dist[DIM],mod[DIM*4];   bool vis[DIM];   struct node{       ll dist;       int x,y;   };   const bool operator > (const node &a,const node &b){       return a.dist>b.dist;   }   int main() {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);          ll n, m;       cin >> n >> m;       for(ll i = 0;i<DIM*4;++i)           mod[i] = i%n;       for (int i = 1; i <= m; ++i) {           ll a, b, c;           cin >> a >> b >> c;           G[a].push_back({b, c});       }       for (ll i = 0; i < n; ++i) {           sort(G[i].begin(), G[i].end());           vector<pair<int, ll> > V;           int mi = 0;           for (int j = 1; j < G[i].size(); ++j) {               if (G[i][mi].second > G[i][j].second)                   mi = j;           }           for (int j = mi; j < G[i].size(); ++j)               V.push_back(G[i][j]);           for (int j = 0; j < mi; ++j)               V.push_back(G[i][j]);           G[i] = V;       }          for (ll x = 0; x < n; ++x) {           for(ll j = 0;j<n;++j){               dist[j] = INF;               vis[j] = 0;           }           dist[x] = 0;              while(1){               int y = -1;               for(int j = 0;j<n;++j){                   if (vis[j])                       continue;                   if (y==-1 || dist[y]>dist[j])                       y = j;               }               if (y==-1)                   break;               vis[y] = 1;               ll dd = dist[y];               ll dm = dd%n;               pair<int, ll> cur = G[y][0];               int start = mod[G[y][0].first + dm];               int ptr = 1;               ll ss = G[y][0].second - 1;               for (int i = start; i < n; ++i) {                   ++ss;                   while (ptr < G[y].size() && mod[G[y][ptr].first + dm] == i) {                       if (G[y][ptr].second < ss) {                           cur = G[y][ptr];                           ss = G[y][ptr].second;                       }                       ++ptr;                   }                   ll ds = ss + dd;                   if (dist[i] > ds) {                       dist[i] = ds;                      }               }               for (int i = 0; i < start; ++i) {                   ++ss;                   while (ptr < G[y].size() && mod[G[y][ptr].first + dm] == i) {                       if (G[y][ptr].second < ss) {                           cur = G[y][ptr];                           ss = G[y][ptr].second;                       }                       ++ptr;                   }                   ll ds = ss + dd;                   if (dist[i] > ds) {                       dist[i] = ds;                      }               }           }           for(ll i = 0;i<n;++i)               cout<<dist[i]<<   ;           cout<<endl;       }             return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int N = 5001;   int dp[N][26][26];   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.length();     for (int i = (int)(0); i < (int)(n); i++) {       int ch = s[i] -  a ;       for (int j = (int)(0); j < (int)(n); j++) {         int dh = s[(i + j) % n] -  a ;         dp[j][ch][dh] += 1;       }     }     int cnt = 0;     for (int j = (int)(0); j < (int)(26); j++) {       int ma = 0;       for (int i = (int)(1); i < (int)(n); i++) {         int uq = 0;         for (int k = (int)(0); k < (int)(26); k++) {           if (dp[i][j][k] == 1) {             uq++;           }         }         ma = max(ma, uq);       }       cnt += ma;     }     cout << setprecision(15) << ((double)cnt / (double)n) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int v[1010][1010], v1[1010][1010], tip[100], n, m;   char sir[2010][1010], sir1[2010][1010];   void transpune() {     for (int i = 1; i < 2 * m; i++)       if (i % 2)         for (int j = 1; j < n; j++) sir1[i][j] = sir[2 * j][i / 2 + 1];       else         for (int j = 1; j <= n; j++) sir1[i][j] = sir[2 * j - 1][i / 2];     swap(n, m);     for (int i = 1; i < 2 * n; i++)       for (int j = 1; j <= m - i % 2; j++) sir[i][j] = sir1[i][j];   }   int solve1() {     int sol = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (j < m) sol += sir[2 * i - 1][j] ==  E ;         if (i < n) sol += sir[2 * i][j] ==  E ;       }     return 4 * sol >= 3 * (2 * n * m - n - m);   }   int solve2() {     int transpus = 0;     if (n > m) {       transpune();       transpus = 1;     }     for (int i = 1; i <= n; i++) {       v[i][1] = 0;       for (int j = 2; j <= m; j++)         v[i][j] = v[i][j - 1] ^ tip[sir[2 * i - 1][j - 1]];       if (i > 1) {         int nr = 0;         for (int j = 1; j <= m; j++)           nr += (v[i][j] == v[i - 1][j]) ^ tip[sir[2 * i - 2][j]];         if (2 * nr < m)           for (int j = 1; j <= m; j++) v[i][j] ^= 1;       }     }     if (transpus) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) v1[j][i] = v[i][j];       swap(n, m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) v[i][j] = v1[i][j];     }     return 1;   }   int main() {     int k, ok;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i < 2 * n; i++) scanf(  n%s , sir[i] + 1);     tip[ E ] = 0;     tip[ N ] = 1;     if (k == 1)       ok = solve1();     else       ok = solve2();     if (ok) {       printf( YES n );       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) printf( %d  , v[i][j] + 1);         printf(  n );       }     } else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void Read(T &cn) {     char c;     int sig = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) sig = -1;     cn = c - 48;     while (isdigit(c = getchar())) cn = cn * 10 + c - 48;     cn *= sig;   }   template <typename T>   void Write(T cn) {     if (cn < 0) {       putchar( - );       cn = 0 - cn;     }     int wei = 0;     T cm = 0;     int cx = cn % 10;     cn /= 10;     while (cn) cm = cm * 10 + cn % 10, cn /= 10, wei++;     while (wei--) putchar(cm % 10 + 48), cm /= 10;     putchar(cx + 48);   }   int f[500 / 2 + 1][500 + 1][500 + 1];   int n, m, q;   int a[500 + 1][500 + 1];   int b[500 + 1][500 + 1];   int jian_c(int cn, int cm, int cx) {     if (a[cn - cx + 1][cm - cx + 1] !=  R  || b[cn - cx + 1][cm - cx + 1] != cx)       return 0;     if (a[cn - cx + 1][cm + 1] !=  G  || b[cn - cx + 1][cm + 1] != cx) return 0;     if (a[cn + 1][cm - cx + 1] !=  Y  || b[cn + 1][cm - cx + 1] != cx) return 0;     if (a[cn + 1][cm + 1] !=  B  || b[cn + 1][cm + 1] < cx) return 0;     return 1;   }   void jian(int cn, int cm) {     int lin = min(min(cn, cm), min(n - cn, m - cm));     for (int i = 1; i <= lin; i++) {       if (!jian_c(cn, cm, i)) return;       f[i][cn - i + 1][cm - i + 1] = 1;     }   }   void yuchu() {     for (int i = 1; i <= n; i++) b[i][m] = 1;     for (int i = 1; i <= m; i++) b[n][i] = 1;     for (int i = n - 1; i >= 1; i--)       for (int j = m - 1; j >= 1; j--) {         if (a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 1][j] &&             a[i][j] == a[i][j + 1])           b[i][j] = 1 + min(min(b[i + 1][j], b[i][j + 1]), b[i + 1][j + 1]);         else           b[i][j] = 1;       }   }   int suan(int cn, int cx1, int cy1, int cx2, int cy2) {     return f[cn][cx2][cy2] - f[cn][cx2][cy1] - f[cn][cx1][cy2] + f[cn][cx1][cy1];   }   int main() {     Read(n);     Read(m);     Read(q);     for (int i = 1; i <= n; i++) {       while (!isalpha(a[i][1] = getchar()))         ;       for (int j = 2; j <= m; j++) a[i][j] = getchar();     }     yuchu();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) jian(i, j);     for (int ij = 1; ij <= n / 2; ij++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           f[ij][i][j] = f[ij][i - 1][j] + f[ij][i][j - 1] - f[ij][i - 1][j - 1] +                         f[ij][i][j];     for (int i = 1; i <= q; i++) {       int bx1, by1, bx2, by2;       Read(bx1);       Read(by1);       Read(bx2);       Read(by2);       int ans = 0;       int lin = (min(bx2 - bx1, by2 - by1) + 1) / 2;       for (int j = lin; j >= 1; j--)         if (suan(j, bx1 - 1, by1 - 1, bx2 - j * 2 + 1, by2 - j * 2 + 1)) {           ans = 4 * j * j;           break;         }       Write(ans);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x);       x = (x * x);       n >>= 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long x = n / 2;       if (x % 2) {         cout <<  NO  <<   n ;         continue;       }       cout <<  YES  <<   n ;       vector<long long> a;       for (long long i = 0; i < n; i += 2) {         a.push_back(i + 2);       }       long long c = a.size() / 2;       for (long long i = 0; i < c; i++) {         a.push_back(a[i] - 1);         a.push_back(a[x - i - 1] + 1);       }       for (auto x : a) cout << x <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char a[15][15];   vector<long long int> dp[1 << 14][14];   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       dp[1 << i][i].push_back(1LL);     }     for (int i = 1; i < (1 << n); i++) {       int p = __builtin_popcount(i);       for (int j = 0; j < n; j++) {         if (((i >> j) & 1) == 0) continue;         for (int k = 0; k < n; k++) {           if ((i >> k) & 1) continue;           if (dp[i + (1 << k)][k].size() == 0) {             dp[i + (1 << k)][k].resize((1 << p));           }           int t = 0;           if (a[j][k] ==  1 ) t = 1;           for (int l = 0; l < dp[i][j].size(); l++) {             dp[i + (1 << k)][k][t * (1 << (p - 1)) + l] += dp[i][j][l];           }         }       }     }     for (int i = 0; i < (1 << (n - 1)); i++) {       long long int res = 0;       for (int j = 0; j < n; j++) {         res += dp[(1 << n) - 1][j][i];       }       printf( %lld  , res);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   static const int maxn = 1000 + 10;   int n, m, f[maxn][maxn];   char s[maxn], t[maxn];   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s);     scanf( %s , t);     int mn = n + 1;     vector<int> ans;     for (int i = 0; i + n <= m; i++) {       int count = 0;       vector<int> now;       for (int j = 0; j < n; j++)         if (s[j] != t[i + j]) {           count++;           now.emplace_back(j + 1);         }       if (count < mn) {         mn = count;         ans = now;       }     }     printf( %d n , mn);     for (int i = 0; i < ans.size(); i++)       printf( %d%c , ans[i],    n [i == mn - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void swapll(long long *a, long long *b) {     long long tmp = *a;     *a = *b;     *b = tmp;   }   void swapc(char *a, char *b) {     char tmp = *a;     *a = *b;     *b = tmp;   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n, 0);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     long long count = 0;     long long idx = -1;     for (long long i = 0; i < n; i++) {       if (v[i] == 1 && idx == -1) {         count++;         idx = i;       } else if (v[i] == 1 && i - idx == 1) {         count++;         idx = i;       } else if (v[i] == 1 && i - idx != 1) {         count += 2;         idx = i;       }     }     cout << count << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, ans;     cin >> n >> a >> b;     if (n == 1)       cout <<  1  << endl;     else {       ans = (a + b + abs(b) * n) % n;       if (ans == 0) ans = n;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   struct Node {     int l, r, w, s;   } t[N << 2];   vector<int> a[N], c[N];   int p[N], q[N], L[N], R[N], s[N], z[N];   int cnt, n, m, x, y;   void update(int x) {     if (t[x].w)       t[x].s = t[x].r - t[x].l + 1;     else if (t[x].r != t[x].l)       t[x].s = t[x << 1].s + t[x << 1 | 1].s;     else       t[x].s = 0;   }   void build(int x, int l, int r) {     t[x].l = l, t[x].r = r;     if (l == r) return;     int m = (l + r) >> 1;     build(x << 1, l, m);     build(x << 1 | 1, m + 1, r);     update(x);   }   void change(int x, int l, int r, int d) {     if (t[x].l > r || t[x].r < l)       return;     else if (l <= t[x].l && t[x].r <= r)       t[x].w += d;     else       change(x << 1, l, r, d), change(x << 1 | 1, l, r, d);     update(x);   }   void dfs(int x, int y) {     L[x] = ++cnt;     for (__typeof(a[x].begin()) i = a[x].begin(); i != a[x].end(); i++)       if (*i != y) dfs(*i, x);     R[x] = cnt;   }   inline void tcg(int k, int d) { change(1, L[k], R[k], d); }   void DFS(int x, int y) {     for (__typeof(c[x].begin()) i = c[x].begin(); i != c[x].end(); i++)       tcg(p[*i], 1), tcg(q[*i], 1);     z[x] = t[1].s;     for (__typeof(a[x].begin()) i = a[x].begin(); i != a[x].end(); i++)       if (*i != y) DFS(*i, x);     for (__typeof(c[x].begin()) i = c[x].begin(); i != c[x].end(); i++)       tcg(p[*i], -1), tcg(q[*i], -1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       a[x].push_back(y);       a[y].push_back(x);     }     dfs(1, 0);     build(1, 1, n);     for (int i = 0; i < m; i++) {       scanf( %d%d , p + i, q + i);       c[p[i]].push_back(i);       c[q[i]].push_back(i);     }     DFS(1, 0);     for (int i = 1; i <= n; i++) printf( %d  , max(z[i] - 1, 0));     return 0;   }