malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int Size = 1e5;   long long n, m;   bool onField(long long x, long long y) {     return (x <= n && x >= 1) && (y <= m && y >= 1);   }   int main() {     long long x, y, dx, dy, k;     long long ans = 0;     cin >> n >> m;     cin >> x >> y;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> dx >> dy;       for (long long cof = 1100000000; cof; cof /= 2)         while (onField(x + (cof * dx), y + (cof * dy))) {           x += (cof * dx);           y += (cof * dy);           ans += cof;         }     }     cout << ans <<   n ;     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--) {       long long n, k, ans = INT_MIN;       cin >> n >> k;       long long A[n];       for (int i = 0; i < n; i++) cin >> A[i];       for (long long j = n - 1; ~j; j--) {         for (long long i = j - 1; ~i; i--) {           if (ans >= (i + 1) * (j + 1)) break;           ans = max(ans, (i + 1) * (j + 1) - (k * (A[i] | A[j])));         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n = 0;     cin >> n;     string s;     cin >> s;     int pos = 0;     vector<int> v(n);     int flag = 1;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < n; i++) {       if (s[pos] ==  > ) {         pos += v[pos];       } else {         pos -= v[pos];       }       if (pos < 0 || pos > n - 1) {         cout <<  FINITE ;         flag = 0;         break;       }     }     if (flag == 1) {       cout <<  INFINITE ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[300001];   int arr[300001];   int dp[300001];   int maxi = -(int)1e10, max_pos;   bool flag = false;   void dfs(int beta, int baap) {     if (flag) return;     if (arr[beta] == maxi)       dp[beta] = 0;     else       dp[beta] = -(int)1e10;     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs(pota, beta);       if (dp[pota] != -(int)1e10) {         if (dp[beta] == -(int)1e10)           dp[beta] = 1 + dp[pota];         else {           int dist = 1 + dp[beta] + dp[pota];           if (dist > 2) flag = true;           dp[beta] = max(dp[beta], 1 + dp[pota]);         }       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       if (arr[i] > maxi) {         maxi = arr[i];         max_pos = i;       }     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     int max_count = 0, max_cnt = 0;     for (int i = 1; i <= n; i++) {       if (arr[i] == maxi) max_count++;       if (arr[i] == maxi - 1) max_cnt++;     }     if (max_count == 1) {       for (int i = 0; i < g[max_pos].size(); i++) {         int j = g[max_pos][i];         if (arr[j] == maxi - 1) max_cnt--;       }       if (max_cnt)         printf( %d n , maxi + 1);       else         printf( %d n , maxi);     } else {       dfs(1, 0);       if (flag)         printf( %d n , maxi + 2);       else         printf( %d n , maxi + 1);     }     return 0;   }
#include <bits/stdc++.h>   const int INF = INT_MAX;   using namespace std;   const int N = 3e5 + 10;   int arr[N];   int main() {     ios_base::sync_with_stdio(false);     stringstream ss;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     map<int, bool> ma;     vector<pair<int, int> > ans;     int i = 0, j;     int start, end;     bool flag = false;     while (i < n) {       j = i;       start = i;       ma.clear();       while (j < n) {         if (ma.find(arr[j]) == ma.end()) {           ma[arr[j]] = true;         } else {           break;         }         j++;       }       if (j < n) {         end = j;         ans.push_back(make_pair(start, end));       } else {         if (ans.size() > 0) {           ans[ans.size() - 1].second = n - 1;         } else {           flag = true;         }         break;       }       i = j + 1;     }     if (flag)       ss <<  -1 n ;     else {       ss << ans.size() <<   n ;       for (int k = 0, end = ans.size(); k < end; k++) {         ss << (ans[k].first + 1) <<     << (ans[k].second + 1) <<   n ;       }     }     cout << ss.str() << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   int t;   void solve() {     int n, res = 0, j = 0;     string s;     cin >> n >> s;     map<int, int> m;     for (int i = 0; i <= n; i++) {       if (s[i] ==  x ) {         m[j]++;       } else {         j++;       }     }     for (auto i : m) {       res += max(0, i.second - 2);     }     cout << res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (0) {       cin >> t;       while (t--) solve();     } else {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   long long arr[100010], dpArr[100010], dpQuery[100010];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     for (long long i = (1); i < (n + 1); ++i) cin >> arr[i];     pair<pair<long long, long long>, long long> q[m + 1];     for (long long i = (1); i < (m + 1); ++i)       cin >> q[i].first.first >> q[i].first.second >> q[i].second;     for (long long i = 0; i < (k); ++i) {       long long x, y;       cin >> x >> y;       ++dpQuery[x];       --dpQuery[y + 1];     }     long long sum = 0LL;     for (long long i = (1); i < (m + 1); ++i) {       sum += dpQuery[i];       dpArr[q[i].first.first] += (sum * q[i].second);       dpArr[q[i].first.second + 1] -= (sum * q[i].second);     }     sum = 0LL;     for (long long i = (1); i < (n + 1); ++i) {       sum += dpArr[i];       cout << (sum + arr[i]) <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, z, flag = 0;   vector<long long> sum(200005), mx(200005, INT_MIN);   vector<int> adj[200005 + 1];   vector<int> pl(200005 + 1);   map<int, int> vis;   void dfs(int a) {     vis[a] = 1;     for (int i = 0; i < adj[a].size(); i++) {       if (vis[adj[a][i]] == 0) {         dfs(adj[a][i]);         sum[a] += sum[adj[a][i]];         mx[a] = max(mx[a], mx[adj[a][i]]);       }     }     sum[a] += pl[a];     mx[a] = max(mx[a], sum[a]);     return;   }   map<int, int> mp;   long long ans = INT_MIN;   void dfs2(int x) {     mp[x] = 1;     long long k = 0;     priority_queue<long long> q;     for (int i = 0; i < adj[x].size(); i++) {       if (mp[adj[x][i]] == 0) q.push(mx[adj[x][i]]);     }     long long s = q.size();     int j = 2;     while (j > 0 && q.size()) {       k += q.top();       q.pop();       j--;     }     if (s > 1) ans = max(ans, k);     for (int i = 0; i < adj[x].size(); i++) {       if (mp[adj[x][i]] == 0) dfs2(adj[x][i]);     }   }   int main() {     int t;     t = 1;     for (int r = 0; r < t; r++) {       cin >> n;       long long i;       for (i = 1; i <= n; i++) cin >> pl[i];       for (i = 0; i < n - 1; i++) {         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       dfs(1);       dfs2(1);       if (ans == INT_MIN)         cout <<  Impossible n ;       else         cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int n, m, i, j, k, l, a, b, sz[2], v1[2][5005];   string s;   bool used[5005];   int main() {     ios_base ::sync_with_stdio();     cin.tie(0);     cin >> s;     n = s.size();     if (n == 1) {       cout << s;       return 0;     }     int pw = 1;     while (pw * 2 <= n) pw *= 2, k++;     a = 0;     b = 1;     v1[a][0] = 0;     sz[a] = 1;     for (l = 0; l < n - (1 << k) + 1; l++) {       char res =  z ;       int v, mask;       for (i = 0; i < sz[a]; i++) {         int v = v1[a][i], mask = ((1 << k) - 1) ^ (v - l);         used[v] = 0;         for (j = mask; j > 0; j = mask & (j - 1)) res = min(res, s[v + j]);         res = min(res, s[v]);       }       for (i = 0; i < sz[a]; i++) {         int v = v1[a][i], mask = ((1 << k) - 1) ^ (v - l);         for (j = mask; j >= 0; j = mask & (j - 1)) {           if (!used[v + j + 1] && s[v + j] == res)             v1[b][sz[b]++] = v + j + 1, used[v + j + 1] = true;           if (j == 0) break;         }       }       cout << res;       sz[a] = 0;       b = a;       a ^= 1;     }     return 0;   }
#include <bits/stdc++.h>   const int MAXQ = 5e5 + 5;   using namespace std;   struct edge {     int v, next;   } ed[MAXQ * 4];   int head[MAXQ * 2];   int topE;   void addE(int u, int v) {     ed[++topE].v = v;     ed[topE].next = head[u];     head[u] = topE;     return;   }   int dep[MAXQ * 2];   int fa[MAXQ * 2][25];   int Q;   int ans;   int topN;   int lca(int x, int y) {     int res = 0;     if (dep[x] < dep[y]) {       swap(x, y);     }     res += dep[x] - dep[y];     while (dep[x] != dep[y]) {       x = fa[x][int(log2(dep[x] - dep[y]))];     }     for (int i = int(log2(dep[x])); i >= 0; --i) {       if (fa[x][i] != fa[y][i]) {         res += dep[x] - dep[fa[x][i]];         res += dep[y] - dep[fa[y][i]];         x = fa[x][i];         y = fa[y][i];       }     }     if (x == y) {       return res;     }     x = fa[x][0];     y = fa[y][0];     res += 2;     return res;   }   void insertNode(int u, int v) {     fa[u][0] = v;     dep[u] = dep[v] + 1;     for (int i = 1; i <= int(log2(dep[u])); ++i) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];     }     return;   }   int da, db;   int main() {     scanf( %d , &Q);     topN = 4;     dep[2] = dep[3] = dep[4] = 1;     fa[2][0] = fa[3][0] = fa[4][0] = 1;     da = 2;     db = 3;     ans = 2;     for (int i = 1; i <= Q; ++i) {       int v;       scanf( %d , &v);       insertNode(++topN, v);       insertNode(++topN, v);       if (lca(da, topN) > ans) {         ans = lca(da, topN);         db = topN;       } else if (lca(db, topN) > ans) {         ans = lca(db, topN);         da = topN;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char m[1000000];   int main() {     int t, i, j;     string s;     cin >> t;     cin >> s;     int l = s.length();     for (i = 0; i < l; i++) m[i] = s[i];     for (i = 1; i < t; i++) {       cin >> s;       for (j = 0; j < l; j++) {         if (m[j] ==  ? ) m[j] = s[j];         if (m[j] != s[j] && s[j] !=  ? ) m[j] =  ! ;       }     }     for (i = 0; i < l; i++) {       if (m[i] ==  ? )         cout <<  x ;       else if (m[i] ==  ! )         cout <<  ? ;       else         cout << m[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lb = 1000;   void azmuth(long long n = 12) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(n) << fixed;   }   void solve() {     long long n;     string s;     cin >> n >> s;     vector<long long> ans(n);     ans[0] = 1;     for (long long i = 0; i < n - 1; i++) {       if (s[i] ==  = ) {         ans[i + 1] = ans[i];         continue;       }       if (s[i] ==  L ) {         ans[i + 1] = 1;         continue;       }       ans[i + 1] = 1 + ans[i];     }     for (long long i = n - 2; i >= 0; i--) {       if (s[i] ==  L ) {         ans[i] = max(ans[i], ans[i + 1] + 1);       } else if (s[i] ==  R ) {         ans[i] = min(ans[i], ans[i + 1] - 1);       } else         ans[i] = ans[i + 1];     }     for (auto a : ans) cout << a <<    ;     cout <<   n ;     ;   }   int32_t main() {     azmuth();     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k;   string str[400007];   long long int a[400007], p[400007][4];   long long int m1[200005], m2[200005];   int main() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  A ) {         p[i][0] = 1;         if (i - 1 >= 0) p[i - 1][0] = 1;         if (i + 1 < s.length()) p[i + 1][0] = 1;       }       if (s[i] ==  B ) {         p[i][1] = 1;         if (i - 1 >= 0) p[i - 1][1] = 1;         if (i + 1 < s.length()) p[i + 1][1] = 1;       }       if (s[i] ==  C ) {         p[i][2] = 1;         if (i - 1 >= 0) p[i - 1][2] = 1;         if (i + 1 < s.length()) p[i + 1][2] = 1;       }     }     for (int i = 0; i < s.length(); i++) {       if (p[i][0] == 1 && p[i][1] == 1 && p[i][2] == 1) {         cout <<  Yes ;         return 0;       }     }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, class F = function<T(const T&, const T&)>>   class SparseTable {    public:     int n;     vector<vector<T>> sp;     F func;     SparseTable(const vector<T>& a, const F& f) : func(f) {       n = static_cast<int>(a.size());       int max_log = 32 - __builtin_clz(n);       sp.resize(max_log);       sp[0] = a;       for (int j = 1; j < max_log; ++j) {         sp[j].resize(n - (1 << j) + 1);         for (int i = 0; i <= n - (1 << j); ++i) {           sp[j][i] = func(sp[j - 1][i], sp[j - 1][i + (1 << (j - 1))]);         }       }     }     T get(int l, int r) const {       int lg = 32 - __builtin_clz(r - l + 1) - 1;       return func(sp[lg][l], sp[lg][r - (1 << lg) + 1]);     }   };   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1), nxt(n + 1), prv(n + 1), cum(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       cum[i] = cum[i - 1] + a[i];     }     for (int i = n; i >= 1; i--) {       nxt[i] = i + 1;       while (nxt[i] <= n && a[nxt[i]] <= a[i]) nxt[i] = nxt[nxt[i]];     }     for (int i = 1; i <= n; i++) {       prv[i] = i - 1;       while (prv[i] >= 1 && a[prv[i]] <= a[i]) prv[i] = prv[prv[i]];     }     SparseTable<int> mn_sp(cum, [&](int i, int j) { return min(i, j); });     SparseTable<int> mx_sp(cum, [&](int i, int j) { return max(i, j); });     int ans = 0;     for (int i = 1; i <= n; i++) {       int l = prv[i] + 1, r = nxt[i] - 1;       ans = max(ans, mx_sp.get(i, r) - mn_sp.get(l - 1, i - 1) - a[i]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int treas[310][310];   long long dp[310][310];   long long d[310][310];   vector<pair<int, int> > G[110000];   vector<pair<long long, pair<int, int> > > lst;   queue<pair<long long, pair<int, int> > > bfs;   int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};   long long n, m;   long long Dist(int x1, int y1, int x2, int y2) {     return abs(x1 - x2) + abs(y1 - y2);   }   int main() {     ios_base::sync_with_stdio(0);     int p, fx, fy;     cin >> n >> m >> p;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> treas[i][j];         G[treas[i][j]].push_back({i, j});         if (treas[i][j] == p) fx = i, fy = j;         if (treas[i][j] == 1) dp[i][j] = i + j;       }     for (int i = 2; i <= p; i++) {       long long cur_size = G[i].size();       long long prev_size = G[i - 1].size();       if (cur_size * prev_size <= n * m) {         for (int j = 0; j < cur_size; j++) {           int cur_x = G[i][j].first;           int cur_y = G[i][j].second;           dp[cur_x][cur_y] = 1e9;           for (int k = 0; k < prev_size; k++) {             int prev_x = G[i - 1][k].first;             int prev_y = G[i - 1][k].second;             dp[cur_x][cur_y] =                 min(dp[cur_x][cur_y],                     dp[prev_x][prev_y] + Dist(cur_x, cur_y, prev_x, prev_y));           }         }       } else {         lst.clear();         for (int j = 0; j < n; j++)           for (int k = 0; k < n; k++) d[j][k] = -1;         for (int j = 0; j < prev_size; j++) {           int prev_x = G[i - 1][j].first;           int prev_y = G[i - 1][j].second;           lst.push_back({dp[prev_x][prev_y], {prev_x, prev_y}});         }         sort(lst.begin(), lst.end());         int ptr = 1;         bfs.push(lst[0]);         d[lst[0].second.first][lst[0].second.second] = lst[0].first;         while (!bfs.empty()) {           int x = bfs.front().second.first;           int y = bfs.front().second.second;           long long val = bfs.front().first;           bfs.pop();           while (ptr < lst.size() && lst[ptr].first <= val) bfs.push(lst[ptr++]);           int X, Y;           for (int k = 0; k < 4; k++) {             X = x + dir[k][0];             Y = y + dir[k][1];             if (X >= 0 && X <= n && Y >= 0 && Y < m && d[X][Y] == -1) {               d[X][Y] = val + 1;               bfs.push({val + 1, {X, Y}});             }           }         }         for (int j = 0; j < cur_size; j++) {           int x = G[i][j].first;           int y = G[i][j].second;           dp[x][y] = d[x][y];         }       }     }     cout << dp[fx][fy] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, i, j, sum = 0, k;     cin >> x >> y;     for (i = 1; i <= x; i++) {       j = i % 5;       k = y + j;       sum = sum + (k / 5);     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)2e9;   const long long md = 1000000007;   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<int, int> > v(n);     for (int i = 0; i < (int)n; i++) {       cin >> v[i].first >> v[i].second;     }     sort((v).begin(), (v).end(), [&](pair<int, int>& a, pair<int, int>& b) {       return abs(a.first) + abs(a.second) < abs(b.first) + abs(b.second);     });     vector<string> out;     for (pair<int, int>& p : v) {       int first = p.first, second = p.second;       if (first) {         out.emplace_back( 1   + to_string(abs(first)) +     +                          (first > 0 ?  R  :  L ));       }       if (second) {         out.emplace_back( 1   + to_string(abs(second)) +     +                          (second > 0 ?  U  :  D ));       }       out.emplace_back(to_string(2));       if (second) {         out.emplace_back( 1   + to_string(abs(second)) +     +                          (second < 0 ?  U  :  D ));       }       if (first) {         out.emplace_back( 1   + to_string(abs(first)) +     +                          (first < 0 ?  R  :  L ));       }       out.emplace_back(to_string(3));     }     cout << (int)(out.size()) <<   n ;     for (string& s : out) cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void yes() {     cout <<  YES           <<   n ;     return;   }   void no() {     cout <<  NO           <<   n ;     return;   }   template <typename T>   void p(T a) {     cout << a <<    ;     return;   }   template <typename T>   void pnl(T a) {     cout << a <<   n ;     return;   }   const int ten4 = 1e4;   const int ten5 = 1e5;   const int ten6 = 1e6;   const int ten7 = 1e7;   const int ten9 = 1e9;   const int mod = 1e9 + 7;   struct pair_hash {     inline std::size_t operator()(const std::pair<int, int>& v) const {       return v.first * 31 + v.second;     }   };   long long bin_to_integer(string strin) {     long long r = 1, sum = 0;     for (long long i = strin.length() - 1; i >= 0; i--) {       if (strin[i] ==  1 ) sum += r;       r *= 2;     }     return sum;   }   string to_binary(int n) {     string strng;     while (n > 0) {       if (n & 1)         strng +=  1 ;       else         strng +=  0 ;       n >>= 1;     }     reverse(strng.begin(), strng.end());     return strng;   }   int compare(const void* a, const void* b) {     const long long* x = (long long*)a;     const long long* y = (long long*)b;     if (*x > *y)       return 1;     else if (*x < *y)       return -1;     return 0;   }   int power(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res = (res * 1LL * a) % mod;       n /= 2;       a = (a * 1LL * a) % mod;     }     return res;   }   const int Nc = 200001;   int F[Nc];   bool Fcomputed = false;   int nCr(int n, int r) {     if (!Fcomputed) {       F[0] = 1, Fcomputed = true;       for (int i = 1; i < Nc; i++) F[i] = (F[i - 1] * 1LL * i) % mod;     }     if (n < r) return 0;     int res = F[n];     res = res * 1LL * power(F[r], mod - 2) % mod;     res = res * 1LL * power(F[n - r], mod - 2) % mod;     return res;   }   struct unionfind {     vector<int> p;     unionfind(int N) { p = vector<int>(N, -1); }     int root(int x) {       if (p[x] < 0) {         return x;       } else {         p[x] = root(p[x]);         return p[x];       }     }     bool same(int x, int y) { return root(x) == root(y); }     void unite(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (p[x] < p[y]) {           swap(x, y);         }         p[y] += p[x];         p[x] = y;       }     }   };   void testcase(int test) {     int n;     cin >> n;     int arr[n], cnt = 0;     for (int i = 0; i < (n); i++) cin >> arr[i];     if (n % 2 == 0) return yes();     for (int i = 0; i < (n - 1); i++) {       if (arr[i] >= arr[i + 1]) return yes();     }     no();     return;   }   int main() {     ios_base::sync_with_stdio(false);     ;     int test = 1, z = 1;     cin >> test;     while (z <= test) {       testcase(z);       z++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   long long p, q, b;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool ok() {     long long m = gcd(p, q);     q /= m;     m = b;     while (q != 1) {       m = gcd(q, m);       q /= m;       if (m == 1) break;     }     if (q == 1) return true;     return false;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %I64d%I64d%I64d , &p, &q, &b);       if (!p || ok())         printf( Finite n );       else         printf( Infinite n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ar[n];     long long br[n];     for (auto x = 0; x < n; x++) {       cin >> ar[x];       br[x] = ar[x];     }     sort(br, br + n);     long long m;     cin >> m;     while (m--) {       long long pos, k;       set<long long> s;       cin >> k >> pos;       long long bound = br[n - k];       vector<long long> q;       for (int x = 0; x < n; x++) {         if (bound <= ar[x]) {           q.push_back(ar[x]);         }       }       long long sub = q.size() - k;       for (int x = q.size() - 1; x >= 0 && sub != 0; x--) {         if (bound == q[x]) {           q[x] = -1;           sub--;         }         if (sub == 0) {           break;         }       }       for (int x = 0; x < q.size(); x++) {         if (q[x] == -1) {           continue;         }         pos--;         if (pos == 0) cout << q[x] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     if (n >= k) {       cout << (k - 1) / 2 << endl;     } else if (k - n > n) {       cout <<  0  << endl;     } else {       cout << (n - (k - n) + 1) / 2 << endl;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long pow(long long a, int b) {     if (b == 0) return 1;     long long base = pow(a, b >> 1);     base = base * base;     if (b & 1) base = base * a;     return base;   }   long long f(long long n) {     if (n == 1) return 1;     map<long long, int> factors;     long long n_ = n;     for (long long i = 2; i * i <= n_; i++) {       while (n % i == 0) {         factors[i]++;         n /= i;       }     }     if (n > 1) factors[n]++;     long long ans = 1;     for (pair<long long, int> p : factors) {       ans *= pow(p.first, p.second) - pow(p.first, p.second - 1);     }     return ans;   }   int main() {     scanf(  %lld %lld , &n, &k);     for (int i = 0; i < (k + 1) / 2; i++) {       n = f(n);       if (n == 1) break;     }     printf( %lld n , n % 1000000007);     return 0;   }