malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n;   int degree[100010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n - 1; i++) {       int r1, r2;       scanf( %d%d , &r1, &r2);       degree[r1]++;       degree[r2]++;     }     for (int i = 1; i <= n; i++) {       if (degree[i] == 2) {         printf( NO );         return 0;       }     }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long int cost = 0;   vector<int> a, b, c;   vector<vector<int>> g;   pair<int, int> dfs(int cur, int par, int mn_before) {     pair<int, int> ap = {0, 0};     int mn_cur = min(a[cur], mn_before);     if (b[cur] != c[cur]) {       if (b[cur] == 1) {         ap.first = 1;         ap.second = 0;       } else {         ap.first = 0;         ap.second = 1;       }     }     for (auto it : g[cur]) {       if (it != par) {         pair<int, int> pa = dfs(it, cur, mn_cur);         ap.first += pa.first;         ap.second += pa.second;       }     }     if (a[cur] < mn_before) {       int cnt = min(ap.first, ap.second);       cost += 2 * 1ll * cnt * 1ll * a[cur];       ap.first -= cnt;       ap.second -= cnt;     }     return ap;   }   long long int solve() {     cin >> n;     a.resize(n + 1);     b.resize(n + 1);     c.resize(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i] >> c[i];     }     g.resize(n + 1);     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     pair<int, int> a = dfs(1, -1, 1000000000);     if (a.first != a.second) {       return -1;     }     return cost;   }   int main() {     int t = 1;     while (t--) {       cout << solve() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int num, rt[200010], n;   struct data {     int l, r, v;   } tr[200010 * 20];   void insert(int p, int l, int r, int n, int &x) {     x = ++num;     tr[x] = tr[n];     if (l == r) {       tr[x].v++;       return;     }     int mid = l + r >> 1;     if (p <= mid)       insert(p, l, mid, tr[n].l, tr[x].l);     else       insert(p, mid + 1, r, tr[n].r, tr[x].r);     tr[x].v = tr[tr[x].l].v + tr[tr[x].r].v;   }   int ask(int al, int ar, int l, int r, int lx, int x) {     if (x == 0) return 0;     if (al <= l && r <= ar) return tr[x].v - tr[lx].v;     int mid = l + r >> 1, ans = 0;     if (al <= mid) ans = ask(al, ar, l, mid, tr[lx].l, tr[x].l);     if (ar > mid) ans += ask(al, ar, mid + 1, r, tr[lx].r, tr[x].r);     return ans;   }   int ask(int r1, int r2, int l1, int l2) {     if (r1 > r2 || l1 > l2) return 0;     return ask(r1, r2, 1, n, rt[l1 - 1], rt[l2]);   }   int main() {     int m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       insert(x, 1, n, rt[i - 1], rt[i]);     }     for (int i = 1; i <= m; i++) {       int l1, l2, r1, r2;       scanf( %d%d%d%d , &l1, &r1, &l2, &r2);       long long ans = 0;       ans += 1ll * ask(1, r1 - 1, 1, l1 - 1) * ask(r1, n, l1, n);       ans += 1ll * ask(1, r1 - 1, l1, l2) * ask(r1, n, 1, n);       ans += 1ll * ask(1, r1 - 1, l2 + 1, n) * ask(r1, n, 1, l2);       ans += 1ll * ask(r1, r2, 1, l1 - 1) * ask(r1, n, l1, n);       ans += 1ll * ask(r1, r2, l1, l2) *              (ask(r1, n, 1, n) - ask(r1, r2, 1, l1 - 1) - ask(r1, r2, l1, l2));       ans += 1ll * ask(r1, r2, l2 + 1, n) * ask(r2 + 1, n, 1, l2);       ans += 1ll * ask(r1, r2, l1, l2) * (ask(r1, r2, l1, l2) - 1) / 2;       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 10000;   const long long MAXN = 1000;   int n, a[MAXN], sum, cnt, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n + 1);     for (int i = n; i >= 1; i--) {       cnt += a[i];       ans++;       if (cnt > sum - cnt) {         cout << ans;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int l = 0; l < t; l++) {       long long n, s, k;       cin >> n >> s >> k;       unordered_set<long long> tilos;       for (int i = 0; i < k; ++i) {         long long x;         cin >> x;         tilos.insert(x);       }       for (long long i = 0; i <= k; i++) {         if ((s + i <= n) && (tilos.find(s + i) == tilos.end())) {           cout << i << endl;           break;         }         if ((s - i >= 1) && (tilos.find(s - i) == tilos.end())) {           cout << i << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[200100], a[200100];   long long ans;   int main() {     int n, m, i, tmp, s, x;     bool f = false, flag = true;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , d + i);     scanf( %d , &m);     if (m % ((n - 1) << 1) == 0) f = true;     s = (m / ((n - 1) << 1)) << 1;     ans = (long long)s * (d[n] - d[1]);     while (m--) {       scanf( %d , &x);       ++a[x];     }     a[1] <<= 1;     a[n] <<= 1;     tmp = d[2] - d[1];     for (i = 1; i < n; ++i) {       if (f && d[i + 1] - d[i] != tmp) flag = false;       ans += min(a[i] - s, a[i + 1] - s) * (d[i + 1] - d[i]);     }     if (flag)       printf( %I64d n , ans - f * tmp);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long abs2(long long a) { return a >= 0 ? a : -a; }   long long calc(long long k, long long a) {     if (k >= 0) return k / a;     return (k - (a - 1)) / a;   }   long long calc2(long long a1, long long b1, long long a2, long long b2) {     long long x = abs2(a1 - a2) + abs2(b2 - (a2 + (b1 - a1)));     long long y = abs2(a1 - a2) + abs2(b2 - (-a2 + a1 + b1));     return min(x, y);   }   int main() {     long long a, b, x1, x2, y1, y2;     while (cin >> a >> b >> x1 >> y1 >> x2 >> y2) {       long long a1, b1;       long long a2, b2;       a1 = calc(x1 + y1, 2 * a);       b1 = calc(x1 - y1, 2 * b);       a2 = calc(x2 + y2, 2 * a);       b2 = calc(x2 - y2, 2 * b);       long long x = calc2(a1, b1, a2, b2);       long long y = calc2(b1, a1, b2, a2);       cout << (int)min(x, y) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lld = signed long long int;   lld solve() {     lld n, m, k;     cin >> n >> m >> k;     lld x = n / k;     if (m <= x) return m;     if (m <= x + (k - 1)) return x - 1;     return x - ceil((m - x) / (k - 1.0));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const int INF = 1 << 29;   const int MOD = 1e9 + 7;   struct Node {     Node *pre, *nxt;     int val, pos, len;     bool operator<(const Node& rhs) const {       if (len != rhs.len) return len > rhs.len;       return pos < rhs.pos;     }   };   const int N = 2e5 + 10;   Node pool[N << 1], *last;   struct cmp {     bool operator()(int u, int v) const { return pool[u] < pool[v]; }   };   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     set<int, cmp> A;     last = pool;     for (int i = 0, j; i < n; i = j) {       for (j = i + 1; j < n && a[j] == a[i]; ++j)         ;       Node* cur = last++;       cur->val = a[i];       cur->pos = i;       cur->len = j - i;       cur->pre = cur->nxt = nullptr;       if (i > 0) {         auto pre = last - 2;         pre->nxt = cur;         cur->pre = pre;       }     }     for (auto it = pool; it != last; ++it) {       A.insert(it - pool);     }     int ret = 0;     while (A.size()) {       auto it = A.begin();       auto cur = &pool[*it];       auto pre = cur->pre;       auto nxt = cur->nxt;       if (pre && nxt && pre->val == nxt->val) {         cur = last++;         cur->val = pre->val;         cur->pos = pre->pos;         cur->len = pre->len + nxt->len;         cur->pre = pre->pre;         cur->nxt = nxt->nxt;         if (cur->pre) cur->pre->nxt = cur;         if (cur->nxt) cur->nxt->pre = cur;         A.erase(pre - pool);         A.erase(nxt - pool);         A.insert(cur - pool);       } else {         if (pre) pre->nxt = nxt;         if (nxt) nxt->pre = pre;       }       A.erase(it);       ++ret;     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int a[maxn], b[maxn];   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     int cnt1 = 0, cnt2 = 0, cnt0 = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       if (a[i] <= -1) {         ans += -1 - a[i];         cnt1++;       } else if (a[i] >= 1) {         ans += a[i] - 1;         cnt2++;       } else {         cnt0++;       }     }     if (cnt1 % 2) {       if (cnt0) {         ans += cnt0;       } else {         ans += 2;       }     } else {       ans += cnt0;     }     printf( %lld n , ans);     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int T, n, m, las = 1, ndnum = 1, ans;   char s[maxn];   struct node {     int ch[26], len, fa;   } d[maxn << 1];   int siz[maxn << 1], vis[maxn << 1], timer;   int head[maxn << 1], tot;   struct edge {     int nxt, to;   } e[maxn << 1];   void Addedge(int x, int y) {     e[++tot] = (edge){head[x], y};     head[x] = tot;   }   void Insert(int x) {     int p = las, np = las = ++ndnum;     siz[np] = 1;     d[np].len = d[p].len + 1;     while (p && !d[p].ch[x]) {       d[p].ch[x] = np;       p = d[p].fa;     }     if (!p) {       d[np].fa = 1;     } else {       int q = d[p].ch[x];       if (d[q].len == d[p].len + 1) {         d[np].fa = q;       } else {         int nq = ++ndnum;         d[nq] = d[q];         d[nq].len = d[p].len + 1;         d[q].fa = d[np].fa = nq;         while (p && d[p].ch[x] == q) {           d[p].ch[x] = nq;           p = d[p].fa;         }       }     }   }   void dfs(int x) {     int id;     for (int i = head[x]; i; i = e[i].nxt) {       id = e[i].to;       dfs(id);       siz[x] += siz[id];     }   }   void go(int &x, int y, int &len) {     if (d[x].ch[y]) {       ++len;       x = d[x].ch[y];     } else {       while (x && !d[x].ch[y]) x = d[x].fa;       if (!x) {         x = 1;         len = 0;       } else {         len = d[x].len + 1;         x = d[x].ch[y];       }     }   }   void del(int &x, int &len) {     if (len != m) return;     --len;     if (len == d[d[x].fa].len) x = d[x].fa;   }   void work(int x, int y) {     if (y < m || vis[x] == timer) return;     ans += siz[x];     vis[x] = timer;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; ++i) Insert(s[i] -  a );     for (int i = 2; i <= ndnum; ++i) Addedge(d[i].fa, i);     dfs(1);     scanf( %d , &T);     int now, len;     while (T--) {       scanf( %s , s + 1);       m = strlen(s + 1);       now = 1;       len = 0;       for (int i = 1; i <= m; ++i) go(now, s[i] -  a , len);       ++timer;       ans = 0;       work(now, len);       for (int i = 1; i < m; ++i) {         del(now, len);         go(now, s[i] -  a , len);         work(now, len);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9;   const double PI = 2 * acos(0.0);   const double EPS = 1e-9;   int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a > b ? 1 : 2; }   int DI[] = {-1, 0, 1, 0, 1, -1, -1, 1};   int DJ[] = {0, 1, 0, -1, 1, -1, 1, -1};   void clc1(string x) {     int idx = x.find( C );     string r = x.substr(1, idx - 1);     string c = x.substr(idx + 1);     int cc = atoi(c.c_str());     string ans =   ;     while (cc) {       char d = cc % 26 +  A  - 1;       cc /= 26;       if (d ==  @ ) {         d =  Z ;         cc--;       }       ans += d;     }     reverse(ans.begin(), ans.end());     cout << ans << r << endl;   }   void clc2(string x) {     string c =   ;     cout <<  R ;     for (int i = 0; i < (int)(int)x.size(); i++) {       if (isdigit(x[i]))         cout << x[i];       else         c += x[i];     }     cout <<  C ;     int ans = 0;     int p = 1;     for (int i = (int)c.size() - 1; i >= 0; i--) {       ans += (((c[i] -  A ) + 1) * p);       p *= 26;     }     cout << ans << endl;   }   bool f(string x) {     if (x[0] !=  R ) return 0;     int r = x.find( C );     if (r == -1) return 0;     for (int i = 1; i < r; i++)       if (isdigit(x[i])) return 1;     return 0;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)n; i++) {       string x;       cin >> x;       if (f(x))         clc1(x);       else         clc2(x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300;   const int mod = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   string s;   int gx[] = {0, 0, 1, -1};   int gy[] = {1, -1, 0, 0};   bool used[MAX_N][MAX_N];   bool check(int x, int y) {     int cnt = 0;     for (int i = 0; i < 4; ++i) {       int nx = x + gx[i];       int ny = y + gy[i];       if (used[nx][ny]) ++cnt;     }     return cnt == 1;   }   bool solve() {     cin >> s;     int x = 100, y = 100;     used[x][y] = true;     for (auto &ch : s) {       if (ch ==  U )         ch = ch -  U  +  3 ;       else if (ch ==  D )         ch = ch -  D  +  2 ;       else if (ch ==  L )         ch = ch -  L  +  1 ;       else         ch = ch -  R  +  0 ;     }     for (auto ch : s) {       x += gx[ch -  0 ];       y += gy[ch -  0 ];       if (used[x][y]) return false;       used[x][y] = true;       if (!check(x, y)) return false;     }     return true;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t = 1;     while (t--) {       if (solve())         cout <<  OK  <<   n ;       else         cout <<  BUG  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.);   const int MX = 500500;   int t, n, i, j, z[MX];   char s[MX];   vector<complex<double> > a, b;   vector<int> r, ans;   void fft(vector<complex<double> >& a, bool inv) {     int n = a.size();     if (n == 1) return;     for (int i = 1, rv = 0; i < n; i++) {       int j = n / 2;       for (; rv >= j; j /= 2) rv -= j;       rv += j;       if (i < rv) swap(a[i], a[rv]);     }     for (int l = 2; l <= n; l *= 2) {       double alpha = 2 * pi / l;       if (inv) alpha = -alpha;       for (int i = 0; i < n; i += l) {         complex<double> w(1), wn(cos(alpha), sin(alpha));         for (int j = 0; j < l / 2; j++) {           complex<double> x = a[i + j];           complex<double> y = w * a[i + j + l / 2];           a[i + j] = x + y;           a[i + j + l / 2] = x - y;           w *= wn;         }       }     }     if (inv)       for (int i = 0; i < n; i++) a[i] /= n;   }   void mul(vector<complex<double> >& a, vector<complex<double> >& b) {     int n;     for (n = 1; n < a.size() || n < b.size(); n *= 2)       ;     n *= 2;     a.resize(n);     b.resize(n);     r.resize(n);     fft(a, false);     fft(b, false);     for (int i = 0; i < n; i++) a[i] *= b[i];     fft(a, true);     for (int i = 0; i < n; i++) r[i] = int(a[i].real() + 0.5);   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       scanf( %s , s);       a.resize(n);       b.resize(n);       for (i = 0; i < n; i++) a[i] = int(s[i] ==  V );       for (i = 0; i < n; i++) b[i] = int(s[n - i - 1] ==  K );       mul(a, b);       for (i = 1; i < n; i++) z[i] = r[n - 1 - i] + r[n - 1 + i];       ans.clear();       for (i = 1; i < n; i++)         if (z[i] == 0) {           for (j = i + i; j < n; j += i)             if (z[j] > 0) break;           if (j >= n) ans.push_back(i);         }       printf( %d n , int(ans.size()) + 1);       for (i = 0; i < ans.size(); i++) printf( %d  , ans[i]);       printf( %d n , n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int a[N], L[N], tot, R[N], Stack[N], n, m;   long long Ans[N];   struct Ask {     int l, r, from;   } A[N];   inline int cmp1(Ask x, Ask y) { return x.l > y.l; }   inline int cmp2(Ask x, Ask y) { return x.r < y.r; }   struct segTree {     struct Tree {       int l, r;       long long num, flag;     } T[N * 4];     inline void build(int x, int l, int r) {       T[x].l = l;       T[x].r = r;       T[x].flag = T[x].num = 0;       if (l == r) return;       int mid = (l + r) / 2;       build(x * 2, l, mid);       build(x * 2 + 1, mid + 1, r);     }     inline void down(int x) {       if (!T[x].flag) return;       T[x * 2].num += T[x].flag * (T[x * 2].r - T[x * 2].l + 1);       T[x * 2 + 1].num += T[x].flag * (T[x * 2 + 1].r - T[x * 2 + 1].l + 1);       T[x * 2].flag += T[x].flag;       T[x * 2 + 1].flag += T[x].flag;       T[x].flag = 0;     }     inline void insert(int x, int l, int r, int z) {       if (T[x].l > r || l > T[x].r) return;       if (T[x].l >= l && T[x].r <= r) {         T[x].num += z * (T[x].r - T[x].l + 1);         T[x].flag += z;         return;       }       down(x);       insert(x * 2, l, r, z);       insert(x * 2 + 1, l, r, z);       T[x].num = T[x * 2].num + T[x * 2 + 1].num;     }     inline long long find(int x, int y) {       if (T[x].l == T[x].r) return T[x].num;       down(x);       int mid = (T[x].l + T[x].r) / 2;       if (y <= mid) return find(x * 2, y);       return find(x * 2 + 1, y);     }   } T1, T2;   signed main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) A[i].from = i;     for (int i = 1; i <= m; i++) scanf( %d , &A[i].l);     for (int i = 1; i <= m; i++) scanf( %d , &A[i].r);     for (int i = 1; i <= m; i++) Ans[i] = A[i].r - A[i].l + 1;     a[0] = a[n + 1] = n + 1;     Stack[++tot] = 0;     for (int i = 1; i <= n; i++) {       while (a[i] > a[Stack[tot]]) tot--;       L[i] = Stack[tot] + 1;       Stack[++tot] = i;     }     Stack[tot = 1] = n + 1;     for (int i = n; i; i--) {       while (a[i] > a[Stack[tot]]) tot--;       R[i] = Stack[tot] - 1;       Stack[++tot] = i;     }     T1.build(1, 1, n);     T2.build(1, 1, n);     sort(A + 1, A + m + 1, cmp2);     for (int i = 1, j = 1; i <= n; i++) {       T1.insert(1, 1, L[i] - 1, -L[i]);       T2.insert(1, L[i], i, -1);       while (j <= m && A[j].r == i) {         Ans[A[j].from] +=             T1.find(1, A[j].l) + (long long)T2.find(1, A[j].l) * A[j].l;         j++;       }     }     T1.build(1, 1, n);     T2.build(1, 1, n);     sort(A + 1, A + m + 1, cmp1);     for (int i = n, j = 1; i; i--) {       T1.insert(1, R[i] + 1, n, R[i]);       T2.insert(1, i, R[i], 1);       while (j <= m && A[j].l == i) {         Ans[A[j].from] +=             T1.find(1, A[j].r) + (long long)T2.find(1, A[j].r) * A[j].r;         j++;       }     }     for (int i = 1; i <= m; i++) printf( %lld  , Ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int maxn = (1 << 18) - 1;   int main() {     int k;     scanf( %d , &k);     int b = maxn, cnt = 0;     for (int i = 0; i <= 20; ++i) {       if ((k >> i) & 1) {         b ^= (1 << i);       }     }     int cc = maxn >> 1;     printf( %d %d n , 3, 3);     printf( %d %d %d n , maxn, maxn, b);     printf( %d %d% d n , maxn, cc, maxn);     printf( %d %d %d n , b, maxn, cc);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, q;     cin >> n >> q;     bool lava[2][n];     for (int i = 0; i < 2; i++) {       for (int j = 0; j < n; j++) lava[i][j] = false;     }     set<int> blocked1;     set<int> blocked2;     for (int i = 0; i < q; i++) {       int r, c;       cin >> r >> c;       r--;       c--;       if (lava[r][c]) {         blocked2.erase(c);         if (c < n - 1 && !lava[r][c + 1]) {           blocked1.erase(c);         }         if (c > 0 && !lava[r][c - 1]) {           blocked1.erase(c - 1);         }       } else {         if (lava[(r + 1) % 2][c]) {           blocked2.insert(c);         }         if (c < n - 1 && lava[(r + 1) % 2][c + 1]) {           blocked1.insert(c);         }         if (c > 0 && lava[(r + 1) % 2][c - 1]) {           blocked1.insert(c - 1);         }       }       lava[r][c] = !lava[r][c];       if (blocked1.empty() && blocked2.empty() && !lava[0][0] &&           !lava[1][n - 1]) {         cout <<  Yes  << endl;       } else {         cout <<  No  << endl;       }     }   }
#include <bits/stdc++.h>   const long long maxn = 8e9 + 5;   long long v[10000000];   long long k[10000000];   long long n, sum;   int judge(long long m) {     long long i, sum1 = sum;     for (i = 0; i < n; i++) {       if (m * v[i] > k[i]) {         if (k[i] + sum1 < m * v[i])           break;         else if (k[i] + sum1 >= m * v[i])           sum1 = sum1 + k[i] - m * v[i];       }     }     if (i < n)       return 0;     else       return 1;   }   int main() {     long long l, r, mid;     scanf( %I64d%I64d , &n, &sum);     for (long long i = 0; i < n; i++) {       scanf( %I64d , &v[i]);     }     for (long long i = 0; i < n; i++) {       scanf( %I64d , &k[i]);     }     l = 0;     r = maxn;     while (l + 1 < r) {       mid = l + (r - l) / 2;       if (judge(mid)) {         l = mid;       } else         r = mid;     }     if (judge(l + 1))       printf( %I64d , l + 1);     else       printf( %I64d , l);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> g(n + 1);     for (int i = 0; i < n; i++) {       int u;       cin >> u;       g[i + 1] = u;     }     for (int i = 1; i <= n; i++) {       if (g[g[g[i]]] == i) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   const int maxn = 100010;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k;     double l, v1, v2;     cin >> n >> l >> v1 >> v2 >> k;     int t = (n + k - 1) / k;     if (t == 1) {       cout.precision(17);       cout << fixed << l / v2 <<   n ;     } else {       double y = l * (1 + v2 / v1) / (2.0 * t - 1 + v2 / v1);       double x = l - y;       double a = y / v2 + x / v1;       cout.precision(17);       cout << fixed << a <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD(string s, long long c) {     long long ans = 0, p = 1;     for (int i = (((int)s.size()) - 1); i >= (0); i--) {       ans = (ans + (s[i] -  0 ) * p) % c;       p *= 10;       p %= c;     }     return ans;   }   long long mod(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b % 2) ans = ans * a % c;       a = a * a % c;       b /= 2;     }     return ans;   }   long long solve(long long a, string b, long long c) {     long long ans = 1;     for (int i = (((int)b.size()) - 1); i >= (0); i--) {       ans = ans * mod(a, (b[i] -  0 ), c) % c;       a = mod(a, 10, c);     }     return ans;   }   string dec(string s) {     for (int i = (((int)s.size()) - 1); i >= (0); i--) {       if (s[i] !=  0 ) {         s[i]--;         break;       } else {         s[i] =  9 ;       }     }     return s;   }   int main() {     string bb, n;     long long c;     cin >> bb >> n >> c;     long long b = MOD(bb, c);     long long ans = (b - 1 + c) * solve(b, dec(n), c) % c;     if (ans == 0) ans = c;     cout << ans;   }