malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   class Interval {    public:     int s, e, i;   } interval[MAXN + 5];   bool cmp_input(const Interval &a, const Interval &b) { return a.i < b.i; }   bool cmp_interval(const Interval &a, const Interval &b) {     if (a.s != b.s) return a.s < b.s;     return a.e < b.e;   }   int arr[MAXN + 5];   int final[MAXN + 5];   int ptr[MAXN + 5];   vector<int> indx[MAXN + 5];   int answer[MAXN + 5];   int freq[MAXN + 5];   int tree[MAXN + 5];   int n, m;   void _update(int ind, int val) {     for (int i = ind; i <= n; i += i & -i) tree[i] += val;     return;   }   int _query(int ind) {     int ret = 0;     for (int i = ind; i > 0; i -= i & -i) ret += tree[i];     return ret;   }   void update(int s, int e, int val) {     _update(s + 1, val);     _update(e + 2, -val);     return;   }   int query(int ind) { return _query(ind + 1); }   void preCalculate() {     int c, c2;     for (c = 0; c < n; c++) {       if (c) answer[c] = answer[c - 1];       if (arr[c] > n) continue;       freq[arr[c]]++;       if (freq[arr[c]] == arr[c]) answer[c]++;       if (freq[arr[c]] == arr[c] + 1) answer[c]--;       indx[arr[c]].push_back(c);     }     for (c = 1; c <= n; c++) indx[c].push_back(n);     for (c = 0; c < n; c++) update(c, c, answer[c]);     return;   }   void add(int ind, int from, int val) {     int to = from + 1;     if (to >= indx[ind].size()) return;     update(indx[ind][from], indx[ind][to] - 1, val);     return;   }   void moveOne(int &start) {     if (arr[start] > n) {       start++;       return;     }     add(arr[start], ptr[arr[start]] + arr[start] - 1, -1);     add(arr[start], ptr[arr[start]] + arr[start], 1);     ptr[arr[start]]++;     start++;     return;   }   int main() {     FILE *in = stdin;     int c, c2;     fscanf(in,  %d%d , &n, &m);     for (c = 0; c < n; c++) fscanf(in,  %d , &arr[c]);     for (c = 0; c < m; c++) {       fscanf(in,  %d%d , &interval[c].s, &interval[c].e);       interval[c].s--;       interval[c].e--;       interval[c].i = c;     }     sort(interval, interval + m, cmp_interval);     preCalculate();     int start = 0;     for (c = 0; c < m; c++) {       while (interval[c].s > start) moveOne(start);       final[interval[c].i] = query(interval[c].e);     }     sort(interval, interval + m, cmp_input);     for (c = 0; c < m; c++) printf( %d n , final[c]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string s2;     cin >> s >> s2;     transform(s.begin(), s.end(), s.begin(), ::tolower);     transform(s2.begin(), s2.end(), s2.begin(), ::tolower);     if (s == s2) {       printf( 0 n );     } else if (s < s2) {       printf( -1 n );     } else if (s > s2) {       printf( 1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> a;     for (int i = 0; i < m; i++) {       int q, w;       cin >> q >> w;       a.push_back(make_pair(q, w));     }     sort(a.begin(), a.end(), comp);     int i = 0;     int ma = 0;     while (n > 0 && i <= m - 1) {       if (n >= a[i].first) {         n -= a[i].first;         ma += a[i].first * a[i].second;       } else {         ma += n * a[i].second;         n = 0;       }       i++;     }     cout << ma << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int N;     char in[120];     scanf( %d%s , &N, in);     int len = strlen(in);     int flag = 0;     for (int i = 0; i < len; i++) {       for (int d = 1; d < len; d++) {         if (i + 4 * d >= len) break;         if (in[i] ==  *  && in[i + d] ==  *  && in[i + 2 * d] ==  *  &&             in[i + 3 * d] ==  *  && in[i + 4 * d] ==  * )           flag = 1;       }     }     if (flag)       printf( yes n );     else       printf( no n );   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     scanf( %d , &n);     if (n == 1) {       printf( 0 n0 n0 n );       return 0;     }     for (int t = 1; t <= n - 1; t++)       if (gcd(t, n) == 1 && gcd(t + 1, n) == 1) {         for (int i = 0; i < n; i++) printf( %d  , i);         printf(  n );         for (int i = 0; i < n; i++) printf( %d  , (int)(1ll * t * i % n));         printf(  n );         for (int i = 0; i < n; i++) printf( %d  , (int)(1ll * (t + 1) * i % n));         printf(  n );         return 0;       }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const double PI = 3.141592653589793;   const double eps = 1e-6;   int n, r, R;   double x;   int main() {     scanf( %d %d %d , &n, &R, &r);     if (n == 1) {       if (r <= R)         printf( YES n );       else         printf( NO n );       return 0;     }     if (r > R / 2) {       printf( NO n );       return 0;     }     x = asin(r * 1.0 / (R - r)) * 180.0 / PI;     if (2 * n * x > 360 + eps)       printf( NO n );     else       printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)5e3 + 10;   const int MOD = (int)1e9 + 7;   long long dp[1111][1111];   int num[1111], k;   int mark[1111];   long long dfs(int pos, int x, int flag) {     if (pos == 0) return mark[x] == k - 1 && (x != 0);     if (dp[pos][x] != -1 && !flag) {       return dp[pos][x];     }     long long ans = 0;     int ed = flag ? num[pos] : 1;     for (int i = 0; i <= ed; i++) {       ans += dfs(pos - 1, x + i, flag && i == ed);       ans %= MOD;     }     if (!flag) dp[pos][x] = ans;     return ans;   }   char str[1111];   long long solve() {     memset(dp, -1, sizeof(dp));     int len = 0, l = strlen(str + 1);     for (int i = l; i >= 1; i--) {       num[++len] = str[i] -  0 ;     }     if (k == 0) return 1;     if (k == 1) return len - 1;     return dfs(len, 0, 1);   }   int work(int x) {     int re = 0;     while (x) {       re++;       x -= x & (-x);     }     return re;   }   void init() {     mark[1] = 0;     for (int i = 2; i <= 1000; i++) mark[i] = mark[work(i)] + 1;   }   int main() {     init();     scanf( %s , str + 1);     scanf( %d , &k);     printf( %lld n , solve());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[(1 << 20) + 4], n;   long long store[21][2], INV = 0;   long long query(int l, int r, int no) {     return (A + r + 1 - upper_bound(A + l, A + r + 1, no));   }   void gen(int de, int l, int r) {     if (!de) return;     gen(de - 1, l, (l + r) / 2);     gen(de - 1, (l + r) / 2 + 1, r);     int a = l, b = (l + r) / 2, c = r;     for (int i = a; i <= b; i++) {       long long nos = query(b + 1, c, A[i]);       store[de][1] += nos;     }     for (int i = b + 1; i <= c; i++) {       long long nos = query(a, b, A[i]);       store[de][0] += nos;     }     sort(A + l, A + r + 1);   }   int main() {     cin >> n;     for (int i = 1; i <= (1 << n); i++) cin >> A[i];     gen(n, 1, (1 << n));     for (int de = n; de > 0; de--) INV += store[de][0];     int m;     cin >> m;     while (m--) {       int de;       cin >> de;       while (de != 0) {         INV -= store[de][0];         INV += store[de][1];         swap(store[de][0], store[de][1]);         de--;       }       printf( %lld n , INV);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, k;   int a[N];   int b[N];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n - 1; ++i) {       b[i] = a[i + 1] - a[i] - 1;     }     sort(b, b + n - 1);     int kk = n;     long long ans = n;     for (int i = 0; i < n - 1; ++i) {       if (kk == k) break;       ans += b[i];       kk--;       if (kk == k) break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   bool is_Prime(long long a) {     for (long long i = 2; i * i <= a; ++i)       if (a % i == 0) return false;     return true;   }   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return (a.second < b.second);   }   long long fact(long long n) {     vector<long long> v;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           v.push_back(i);         else {           v.push_back(i);           v.push_back(n / i);         }       }     }     return v.size();   }   void C(long long n, long long r) {     vector<vector<long long>> c(n + 1, vector<long long>(r + 1, 0));     for (long long i = 0; i < n + 1; i++) {       for (long long j = 0; j <= i && j <= r; j++)         if (j == 0 || j == i)           c[i][j] = 1;         else           c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;     }   }   bool is_pl(string s, int n) {     for (long long i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) return false;     }     return true;   }   void solve() {     int n, k;     cin >> n >> k;     int cnt[5001] = {0};     vector<pair<int, int>> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i].first;       cnt[v[i].first]++;       v[i].second = (int)i;     }     for (long long i = 0; i < 5001; i++) {       if (cnt[i] > k) {         cout <<  NO n ;         return;       }     }     sort(v.begin(), v.end());     vector<int> ans(n);     int a = 1;     for (long long i = 0; i < n; i++) {       ans[v[i].second] = a;       a++;       if (a > k) a = 1;     }     cout <<  YES n ;     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long int qpow(long long int x, long long int y) {     long long int ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   const int maxn = 1024 * 2;   long long int dp[maxn * 2][maxn][2];   long long int inv[maxn * 4];   long long int Solve(int n, int k) {     dp[1][0][1] = 1;     long long int tem = qpow(2, mod - 2);     long long int ans = 0;     for (int i = 1; i < maxn * 4; i++) inv[i] = qpow(i, mod - 2);     for (int i = 1; i <= 2 * n; i++) {       for (int j = 0; j <= n; j++) {         if (j >= k) {           ans = (ans + dp[i][j][0]) % mod;           ans = (ans + dp[i][j][1]) % mod;         }         if (j - 1 <= (2 * n - i) && j >= 1) {           if (j - 1 == 2 * n - i) {             dp[i + 1][j - 1][0] = (dp[i + 1][j - 1][0] + dp[i][j][0]) % mod;           } else if (j == 1) {             dp[i + 1][j - 1][1] = (dp[i + 1][j - 1][1] + dp[i][j][0]) % mod;           } else {             long long int send = (2 * n - (i + j - 1));             long long int reci = j - 1;             long long int invt = inv[send + reci];             dp[i + 1][j - 1][1] =                 (dp[i + 1][j - 1][1] + dp[i][j][0] * send % mod * invt % mod) %                 mod;             dp[i + 1][j - 1][0] =                 (dp[i + 1][j - 1][0] + dp[i][j][0] * reci % mod * invt % mod) %                 mod;           }         }         if (j + 1 <= (2 * n - i)) {           if (j + 1 == (2 * n - i)) {             dp[i + 1][j + 1][0] = (dp[i + 1][j + 1][0] + dp[i][j][1]) % mod;           } else {             long long int send = (2 * n - (i + j + 1));             long long int reci = j + 1;             long long int invt = inv[send + reci];             dp[i + 1][j + 1][1] =                 (dp[i + 1][j + 1][1] + dp[i][j][1] * send % mod * invt % mod) %                 mod;             dp[i + 1][j + 1][0] =                 (dp[i + 1][j + 1][0] + dp[i][j][1] * reci % mod * invt % mod) %                 mod;           }         }       }     }     return ans;   }   int main() {     int n, k, l;     scanf( %d%d%d , &n, &k, &l);     long long int ans = Solve(n, k) * qpow(2 * n + 1, mod - 2) % mod * l % mod;     printf( %lld , ans);   }
#include <bits/stdc++.h>   #define ll long long int   #define ld long double   #define NMAX 1009   using namespace std;   ll mask;   ll u,d,r,l;   ll n;   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll t;       cin>>t;       while(t--)       {       cin>>n>>u>>r>>d>>l;       bool ok=0;       for(mask=0;mask<16;mask++)           {               ll cu=u;           ll cd=d;           ll cl=l;           ll cr=r;          if(mask & 1)              {cu--;cl--;}           if(mask & 2)              {cu--;cr--;}                       if(mask & 4)              {cl--;cd--;}            if(mask & 8)              {cd--;cr--;}           if(cd>=0 && cd<=n-2 && cu>=0 && cu<=n-2 && cl>=0 && cl<=n-2 && cr>=0 && cr<=n-2)              {ok=1;break;}                              }        if(!ok)        cout<< NO n ;        else        cout<< YES n ;          }             return 0;   }   ///limitele si tipul de date!!
#include <bits/stdc++.h>   const int max_N = 1000 + 21;   int n, a[max_N], b[max_N], cnt[max_N];   std::vector<int> vec, _vec, ret[max_N];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , a + i, b + i);       if (a[i] > b[i]) std::swap(a[i], b[i]);       if (b[i] != n) return puts( NO ), 0;       ++cnt[a[i]];     }     for (int i = 1; i < n; ++i)       if (!cnt[i]) {         vec.push_back(i);       } else {         _vec.push_back(i);       }     std::reverse(vec.begin(), vec.end());     std::queue<int> Q;     int i = n - 1;     for (auto u : vec) {       while (i && i > u) {         if (cnt[i]--) {           while (cnt[i]--) Q.push(i);         }         --i;       }       if (Q.empty()) return puts( NO ), 0;       int v = Q.front();       ret[v].push_back(u);       Q.pop();     }     if (!Q.empty()) return puts( NO ), 0;     puts( YES );     for (auto u : _vec) {       if (ret[u].empty()) {         printf( %d %d n , u, n);       } else {         printf( %d %d n , ret[u][0], n);         for (auto i = 1; i < ret[u].size(); ++i) {           printf( %d %d n , ret[u][i - 1], ret[u][i]);         }         printf( %d %d n , ret[u].back(), u);       }     }     return 0;   }
#include <bits/stdc++.h>   char a[100050], b[100050];   int sa[100050], sb[100050], ta[100050], tb[100050], Q;   int main() {     scanf( %s%s , a + 1, b + 1);     int la = strlen(a + 1), lb = strlen(b + 1);     for (int i = 1; i <= la; i++) {       if (a[i] ==  A ) sa[i] = sa[i - 1] + 1;       sb[i] = sb[i - 1] + (a[i] ==  B  || a[i] ==  C );     }     for (int i = 1; i <= lb; i++) {       if (b[i] ==  A ) ta[i] = ta[i - 1] + 1;       tb[i] = tb[i - 1] + (b[i] ==  B  || b[i] ==  C );     }     int l, r, lsa, lta, ssb, stb;     scanf( %d , &Q);     while (Q--) {       scanf( %d%d , &l, &r);       lsa = std::min(r - l + 1, sa[r]), ssb = sb[r] - sb[l - 1];       scanf( %d%d , &l, &r);       lta = std::min(r - l + 1, ta[r]), stb = tb[r] - tb[l - 1];       if (lsa < lta || ((ssb & 1) != (stb & 1)) || stb < ssb)         printf( 0 );       else if (lsa > lta && stb > ssb ||                ((lsa - lta) % 3 == 0 && (ssb || (ssb == stb))))         printf( 1 );       else         printf( 0 );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 123466;   bool is[N];   vector<int> adj[N];   int dp[N];   int mx_dep[N];   const int inf = 1 << 22;   pair<int, int> calc_dp(int v, int p) {     int res = 0;     int mx = -inf;     if (is[v]) mx = 0;     for (auto u : adj[v])       if (u != p) {         auto cur = calc_dp(u, v);         if (cur.first == -inf) continue;         res += cur.first + 1;         res += cur.second + 1;         mx = max(mx, cur.first + 1);       }     if (mx != -inf) res -= mx;     dp[v] = res, mx_dep[v] = mx;     return {mx, res};   }   int ans = inf;   int ans_pos = 1;   int final_ans[N];   void calc(int v, int p, int load_dep, int load_res) {     int added_dep = min(load_dep, mx_dep[v]);     int cur_ans = load_res + dp[v] + added_dep;     if (cur_ans < ans) ans = cur_ans, ans_pos = v;     if (cur_ans == ans && v < ans_pos) ans_pos = v;     final_ans[v] = cur_ans;     multiset<int> s;     s.insert(load_dep);     int nload = load_dep + load_res;     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         s.insert(mx_dep[u] + 1);         nload += mx_dep[u] + 1 + dp[u] + 1;       }     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         int cur_nload = nload - mx_dep[u] - 1 - dp[u] - 1;         s.erase(s.find(mx_dep[u] + 1));         int mx = *s.rbegin();         cur_nload -= mx;         calc(u, v, mx + 1, cur_nload + 1);         s.insert(mx_dep[u] + 1);       }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int root = 1;     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       is[x] = true;       root = x;     }     calc_dp(root, 0);     calc(root, 0, 0, 0);     printf( %d n%d n , ans_pos, ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     int dp[n][n];     memset(dp, 0, sizeof dp);     int s = 0;     for (int i = 0; i < n; ++i) {       for (int j = i - 1; j >= 0; --j)         if (a[j] > a[i])           dp[i][j] = dp[i][j + 1] + 1;         else           dp[i][j] = dp[i][j + 1];       for (int j = i + 1; j < n; ++j)         if (a[j] > a[i])           dp[i][j] = dp[i][j - 1] + 1;         else           dp[i][j] = dp[i][j - 1];       s += dp[i][0];     }     int cnt = 0, m = INT_MAX;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         int tmp = s + dp[i][j] + dp[i][j - 1] - dp[j][i] - dp[j][i + 1];         if (tmp < m) {           m = tmp;           cnt = 1;         } else if (tmp == m)           cnt++;       }     }     cout << m <<     << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   FILE* g_f_;   int g_s_;   char* g_g_;   template <class _T>   inline _T sqr(const _T& x) {     return x * x;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   signed long long n;   int k;   signed long long a[1024000];   int main() {     cout << setiosflags(ios::fixed) << setprecision(10);     cin >> n;     if (n % 3 != 0) {       puts( 0 );       return 0;     }     n /= 3;     k = 0;     for (int i = (1); i <= (int)(10000000); i++) {       signed long long x = i;       x *= x;       if (x > n) break;       if (n % i == 0) {         a[k++] = i;         if (x != n) a[k++] = n / i;       }     }     sort(a, a + k);     int cma = (int)(pow(n / 2.0, 1.0 / 3.0) + 1e-7);     signed long long ans = 0;     a[k] = n + 1;     for (int c = (1); c <= (int)(cma); c++) {       int bma = (int)(pow(n / 2.0 / c, 1.0 / 2.0) + 1e-7);       signed long long b = c;       while (b <= bma) {         if (n % (b + c) != 0) {           int t = upper_bound(a, a + k, n / (b + c)) - a;           if (t == 0) break;           signed long long y = a[t - 1];           signed long long nb = n / y - c;           if (nb < b) nb = b + 1;           b = nb;           continue;         }         signed long long bb = b + c;         signed long long cc = b * (signed long long)c - n / (b + c);         signed long long dd = bb * bb - 4LL * cc;         signed long long z = (int)(sqrt(dd) + 1e-7);         signed long long a = (-bb + z) / 2;         if (a < b) break;         if (z * z != dd) goto l1;         if (a != b && b != c)           ans += 6;         else if (a != b || b != c)           ans += 3;         else           ans++;       l1:;         b++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool b1[N];   int Z, num[N], in[N], dp[N][20], dep[N], freq[2][N], f[N];   long long fans[N];   vector<int> g[N], v;   map<int, int> mp;   struct qq {     int in, l, r, c;     qq(int a, int b, int e, int d) { in = a, l = b, r = e, c = d; }     bool operator<(const qq& s) const {       if (l / Z != s.l / Z) return l / Z < s.l / Z;       return r / Z < s.r / Z;     }   };   vector<qq> q;   void dfs(int u, int p, int d) {     dep[u] = d;     dp[u][0] = p;     in[u] = v.size();     v.push_back(u);     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != p) dfs(v, u, d + 1);     }     v.push_back(u);   }   int lca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     int x = dep[a] - dep[b];     for (int i = 0; i < 20; i++) {       if ((1 << i) & x) a = dp[a][i];     }     if (a == b) return a;     for (int i = 19; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         a = dp[a][i], b = dp[b][i];       }     }     return dp[a][0];   }   long long ans;   int l = 0, r = -1;   void add(int in, int d) {     int x = v[in];     f[x] += d;     if (d == 1 && f[x] == 2)       d = -1;     else if (d == -1 && f[x] == 1)       d = 1;     ans += d * freq[!b1[x]][num[x]];     freq[b1[x]][num[x]] += d;   }   void fix(int L, int R) {     while (l < L) {       add(l, -1);       l++;     }     while (l > L) {       l--;       add(l, 1);     }     while (r < R) {       r++;       add(r, 1);     }     while (r > R) {       add(r, -1);       r--;     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , b1 + i);     }     for (int i = 1; i <= n; i++) {       scanf( %d , num + i);       if (mp.find(num[i]) == mp.end()) mp[num[i]] = mp.size();       num[i] = mp[num[i]];     }     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b), g[b].push_back(a);     }     dfs(1, -1, 0);     Z = sqrt(v.size() + 0.0) + 1;     for (int k = 1; k < 20; k++) {       for (int i = 1; i <= n; i++) {         if (dp[i][k - 1] == -1)           dp[i][k] = -1;         else           dp[i][k] = dp[dp[i][k - 1]][k - 1];       }     }     int m;     scanf( %d , &m);     for (int i = 0, a, b, c; i < m; i++) {       scanf( %d%d , &a, &b);       c = lca(a, b);       bool f = (c != a) & (c != b);       q.push_back(qq(i, min(in[a], in[b]) + f, max(in[a], in[b]), c * f));     }     sort(q.begin(), q.end());     for (int i = 0; i < m; i++) {       fix(q[i].l, q[i].r);       if (q[i].c) add(in[q[i].c], 1);       fans[q[i].in] = ans;       if (q[i].c) add(in[q[i].c], -1);     }     for (int i = 0; i < m; i++) {       printf( %I64d n , fans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s = 0, x, m = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       s += x;       m = max(m, x);     }     long long t = s / (n - 1);     if (s % (n - 1)) t++;     cout << max(m, t);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[5000010], f[5000010];   int main() {     long long t, l, r, i, j, a, b, mod, ans, k = 1, final = 0;     mod = 1e9 + 7;     scanf( %lld %lld %lld , &t, &l, &r);     for (i = 2; i <= r; i++) {       if (dp[i] == 0) {         for (j = i; j <= r; j += i)           if (!dp[j]) dp[j] = i;       }       a = dp[i];       b = i / dp[i];       if (b == 1)         f[i] = (i * (i - 1) / 2) % mod;       else         f[i] = (b * f[a] + f[b]) % mod;       if (i >= l) {         final = (final + k * f[i]) % mod;         k = (k * t) % mod;       }     }     printf( %lld n , final);     return 0;   }