malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string s;   int mynum(int x, int y) {     int temp;     stringstream ss;     ss << (s.substr(x, y - x));     ss >> temp;     if (temp > 1000000 || (y - x != 1 && s[x] ==  0 ) || x == y) return -1;     return temp;   }   int main() {     int mx = -1, x, y, z;     cin >> s;     for (int i = 0; i < s.length(); i++) {       for (int j = i + 1; j < s.length(); j++) {         x = mynum(0, i);         y = mynum(i, j);         z = mynum(j, s.length());         if (x != -1 && y != -1 && z != -1 && x + y + z > mx) mx = x + y + z;       }     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 + 5;   int n, l, k;   long long a[maxn];   void input() {     scanf( %d %d , &n, &l);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     scanf( %d , &k);   }   long long first() {     long long javab = 0, MAX = 0, x;     int y;     set<pair<long long, int> > second, t;     for (int i = 0; i < l; i++)       if (a[i] < 0) second.insert(make_pair(a[i], i));     while ((int)second.size() > k) {       t.insert(*(--second.end()));       second.erase(--second.end());     }     for (int i = 0; i < l; i++) {       if (second.find(make_pair(a[i], i)) == second.end())         javab += a[i];       else         javab -= a[i];     }     MAX = abs(javab);     for (int i = l; i < n; i++) {       if (second.find(make_pair(a[i - l], i - l)) == second.end()) {         t.erase(make_pair(a[i - l], i - l));         javab -= a[i - l];       } else {         javab += a[i - l];         second.erase(make_pair(a[i - l], i - l));       }       if (a[i] < 0) {         javab -= a[i];         second.insert(make_pair(a[i], i));       } else         javab += a[i];       if ((int)t.size()) {         x = t.begin()->first;         y = t.begin()->second;         javab -= (2 * x);         second.insert(make_pair(x, y));         t.erase(make_pair(x, y));       }       while ((int)second.size() > k) {         x = (--second.end())->first;         y = (--second.end())->second;         t.insert(make_pair(x, y));         javab += (2 * x);         second.erase(make_pair(x, y));       }       MAX = max(MAX, javab);     }     return MAX;   }   void output() {     long long javab = first();     for (int i = 0; i < n; i++) a[i] *= -1;     printf( %lld n , max(javab, first()));   }   int main() {     ios::sync_with_stdio(false);     input();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int size = 31;   const int mod = 1e8 + 7;   long long hash1[maxn], jec[maxn], hash2[maxn];   int cnt[maxn];   char s[maxn];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     jec[0] = 1;     for (int i = 1; i <= n; ++i) jec[i] = jec[i - 1] * size % mod;     for (int i = 1; i <= n; ++i) cnt[i] = cnt[i - 1] + !(s[i] -  0 );     for (int i = 1; i <= n; ++i) {       if (s[i] ==  0 ) {         hash1[i] = hash1[i - 1] * size + ((i & 1) +  0 );         hash2[i] = hash2[i - 1] * size + !(i & 1) +  0 ;         hash1[i] %= mod;         hash2[i] %= mod;       } else {         hash1[i] = hash1[i - 1];         hash2[i] = hash2[i - 1];       }     }     int q;     scanf( %d , &q);     while (q--) {       int l, r, len;       scanf( %d%d%d , &l, &r, &len);       long long p, pp;       if (l & 1)         p = (hash1[l + len - 1] -              hash1[l - 1] * jec[cnt[l + len - 1] - cnt[l - 1]] % mod + mod) %             mod;       else         p = (hash2[l + len - 1] -              hash2[l - 1] * jec[cnt[l + len - 1] - cnt[l - 1]] % mod + mod) %             mod;       if (r & 1)         pp = (hash1[r + len - 1] -               hash1[r - 1] * jec[cnt[r + len - 1] - cnt[r - 1]] % mod + mod) %              mod;       else         pp = (hash2[r + len - 1] -               hash2[r - 1] * jec[cnt[r + len - 1] - cnt[r - 1]] % mod + mod) %              mod;       if (p == pp)         printf( Yes n );       else         printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const pair<int, int> queen[8] = {pair<int, int>(-1, 0), pair<int, int>(-1, 1),                                    pair<int, int>(0, 1),  pair<int, int>(1, 1),                                    pair<int, int>(1, 0),  pair<int, int>(1, -1),                                    pair<int, int>(0, -1), pair<int, int>(-1, -1)};   const int maxN = 1e5 + 11;   int N, A[maxN], BIT[maxN];   vector<int> pos[maxN];   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return pair<int, int>(a.first + b.first, a.second + b.second);   }   void update(int x, int v) {     for (int i = x; i <= N; i += i & (i ^ (i - 1))) BIT[i] += v;   }   int get_BIT(int x) {     int res = 0;     for (int i = x; i >= 1; i -= i & (i ^ (i - 1))) res += BIT[i];     return res;   }   int get_BIT(int l, int r) { return get_BIT(r) - get_BIT(l - 1); }   int main() {     cin >> N;     for (int i = 1; i <= N; i++) cin >> A[i], pos[A[i]].push_back(i);     long long ans = 0;     for (int i = 1; i <= N; i++) update(i, 1);     for (int i = 1, p = 1; i <= 1e5; i++) {       if (pos[i].empty()) continue;       int q = lower_bound(pos[i].begin(), pos[i].end(), p) - pos[i].begin();       for (int j = 0; j < (int)pos[i].size(); j++) {         q %= (int)pos[i].size();         if (p <= pos[i][q])           ans += get_BIT(p, pos[i][q]);         else           ans += get_BIT(1, pos[i][q]) + get_BIT(p, N);         update(pos[i][q], -1);         p = pos[i][q];         q++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long N = 10000000000000000;   int points = 0;   int main() {     long long xo, yo, ax, ay, bx, by;     cin >> xo >> yo >> ax >> ay >> bx >> by;     long long x, y, t;     cin >> x >> y >> t;     long long X[100], Y[100];     X[0] = xo, Y[0] = yo;     for (int i = 1; i < 55; i++) {       X[i] = ax * X[i - 1] + bx;       Y[i] = ay * Y[i - 1] + by;       points++;       if (X[i] >= N || Y[i] >= N) break;     }     long long maxi = 0;     for (int i = 0; i <= points; i++) {       for (int j = 0; j <= points; j++) {         long long tmpx = X[i], tmpy = Y[i], tt = t, ans = 0;         tt -= abs(X[i] - x) + abs(y - Y[i]);         if (tt >= 0) ans = 1;         int k = i + 1;         if (i > j) k = i - 1;         for (;;) {           if ((k > i && k > j) || (k < i && k < j)) break;           long long curx = X[k], cury = Y[k];           tt -= abs(tmpx - curx) + abs(tmpy - cury);           tmpx = curx, tmpy = cury;           if (tt < 0) break;           ans++;           if (i <= j)             k++;           else             k--;         }         maxi = max(maxi, ans);       }     }     cout << maxi << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int maxn = 1500 + 5;   int count(vector<int>& rec, vector<int>& temp, int l, int h) {     if (h - l < 1) return 0;     int m = (l + h) / 2;     int ans = count(rec, temp, l, m) + count(rec, temp, m + 1, h);     int a = l, b = m + 1;     int i = l;     for (i = l; i < h; ++i) {       if (a > m || b > h) break;       if (temp[a] > temp[b]) {         ans += m - a + 1;         rec[i] = temp[b];         ++b;       } else {         rec[i] = temp[a];         ++a;       }     }     while (a <= m) {       rec[i++] = temp[a++];     }     while (b <= h) {       rec[i++] = temp[b++];     }     for (int i = l; i <= h; ++i) {       temp[i] = rec[i];     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> pr(n), tem(n);     for (int i = 0; i < n; ++i) {       cin >> pr[i];       tem[i] = pr[i];     }     int toi = count(pr, tem, 0, n - 1);     toi %= 2;     int m;     cin >> m;     while (m--) {       int l, r;       cin >> l >> r;       int le = r - l + 1;       int res = le * (le - 1) / 2;       toi += res;       toi %= 2;       if (toi == 0)         cout <<  even n ;       else         cout <<  odd n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, sum;     int xx[10005], yy[10005], a[10005];     while (scanf( %d , &n) != EOF) {       sum = 0;       for (i = 0; i <= n; i++) {         scanf( %d %d , &xx[i], &yy[i]);       }       for (i = 0; i < n; i++) {         if (xx[i] == xx[i + 1] && yy[i + 1] > yy[i]) a[i] = 1;         if (xx[i] < xx[i + 1] && yy[i + 1] == yy[i]) a[i] = 2;         if (xx[i] == xx[i + 1] && yy[i + 1] < yy[i]) a[i] = 3;         if (xx[i] > xx[i + 1] && yy[i + 1] == yy[i]) a[i] = 4;       }       for (i = 0; i < n - 1; i++) {         if (a[i] > a[i + 1]) sum++;       }       printf( %d n , sum);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e8 + 5;   long long MAX = 1e9;   long long MOD = 1e9 + 7;   long long Mod = 1e9 + 7;   double EPS = 0.0001;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   const int dx[] = {1, -1, 0, 0, 0, 0};   const int dy[] = {0, 0, 1, -1, 0, 0};   int main() {     int wait;     long long n, k;     int prin = 0;     scanf( %I64d , &n);     scanf( %I64d , &k);     long long check = k * (k - 1);     if (check < n) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 1; i < k + 1; i++) {       for (long long j = i + 1; j < k + 1; j++) {         cout << i <<     << j << endl;         prin++;         if (prin == n) return 0;         cout << j <<     << i << endl;         prin++;         if (prin == n) return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000LL * 1000000LL * 1000000LL;   int n, k;   int tyl, l, sum;   int T[1000][1000];   int main() {     scanf( %d %d , &n, &k);     tyl = n * n;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= k; j--) {         T[i][j] = tyl;         tyl--;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (j == k) {           sum += T[i][j];         }         if (T[i][j] == 0) {           l++;           T[i][j] = l;         }       }     }     printf( %d n , sum);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         printf( %d  , T[i][j]);       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     vector<long long> cnt(26, 0);     for (auto x : s) {       cnt[x -  a ]++;     }     deque<long long> d;     for (long long i = 0; i < 26; i++) {       if (cnt[i]) {         d.push_back(i);       }     }     deque<long long> ans;     if ((long long)d.size() == 2) {       if (d[0] + 1 == d[1]) {         cout <<  No answer  <<   n ;         return;       }       ans = d;     } else if ((long long)d.size() == 3) {       if (d[0] + 1 == d[1] && d[1] + 1 == d[2]) {         cout <<  No answer  <<   n ;         return;       } else if (d[0] + 1 == d[1]) {         ans.push_back(d[0]);         ans.push_back(d[2]);         ans.push_back(d[1]);       } else {         ans.push_back(d[1]);         ans.push_back(d[0]);         ans.push_back(d[2]);       }     } else {       long long fl = 1;       while ((long long)d.size() > 1) {         if (fl) {           ans.push_back(d.front());           d.pop_front();         } else {           ans.push_back(d.back());           d.pop_back();         }         fl ^= 1;       }       ans.push_front(d[0]);     }     for (auto x : ans) {       for (long long i = 0; i < cnt[x]; i++) {         cout << (char)(x +  a );       }     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     tc = 1;     cin >> tc;     for (int i = 1; i <= tc; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, -1, 0, 1};   int dy[] = {1, 0, -1, 0};   int c[2010][2010], edge[2010];   long double s[2010], C[2010][2010];   int main(int argc, char *argv[]) {     int n, k;     scanf( %d%d , &n, &k);     for (int i = (1); i <= (n); ++i) {       C[i][0] = 1;       for (int j = (1); j <= (i); ++j) C[i][j] = C[i][j - 1] * (i - j + 1) / j;     }     for (int i = (1); i <= (n - 1); ++i)       for (int j = (i + 1); j <= (n); ++j) {         scanf( %d , &c[i][j]);         c[j][i] = c[i][j];       }     long double m = 0;     for (int i = (1); i <= (n); ++i) {       edge[i] = 0;       for (int j = (1); j <= (n); ++j)         if (c[i][j] >= 0 && i != j) edge[i]++;       s[i] = 0;       if (edge[i] < k) continue;       s[i] = C[edge[i]][k];       m += s[i];     }     long double ans = 0;     for (int i = (1); i <= (n); ++i) {       if (edge[i] <= 0) continue;       long double p = (s[i] * k) / (m * edge[i]);       long double sum = 0;       for (int j = (1); j <= (n); ++j)         if (c[i][j] >= 0 && i != j) sum += (long double)c[i][j];       ans += sum * p;     }     ans = ans + 1e-5;     printf( %I64d n , (long long)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h, a;     vector<int> home, away;     cin >> n;     vector<int> cnt(100000, 0);     vector<int> ans_home(n, 0);     vector<int> ans_away(n, 0);     for (int i = 0; i < n; i++) {       cin >> h >> a;       home.push_back(h);       away.push_back(a);     }     for (int i = 0; i < n; i++) cnt[home[i] - 1]++;     for (int i = 0; i < n; i++) {       ans_home[i] = n - 1 + cnt[away[i] - 1];       ans_away[i] = 2 * (n - 1) - ans_home[i];     }     for (int i = 0; i < n; i++) cout << ans_home[i] <<     << ans_away[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int inf = 1e9;   const int N = 1e5;   vector<long long int> tot(N);   vector<bool> vis(N);   vector<int> adj[N];   void dfs(int node) {     vis[node] = true;     for (auto &i : adj[node]) {       if (!vis[i]) {         dfs(i);         tot[node] += tot[i];       }     }     if ((int)adj[node].size() == 1 && node != 0) tot[node]++;   }   void solve() {     vector<tuple<int, int, long long int, int>> vc;     int n, u, v, x;     long long int s, w;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v >> w >> x;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);       vc.push_back({u, v, w, x});     }     dfs(0);     int cnt = 0;     long long int sum = 0;     priority_queue<tuple<long long int, long long int, long long int>> q1, q2;     for (auto &i : vc) {       u = get<0>(i);       v = get<1>(i);       w = get<2>(i);       x = get<3>(i);       long long int tp = min(tot[u], tot[v]);       sum += tp * w;       if (x == 1)         q1.push({tp * w - tp * (w / 2), tp, w / 2});       else         q2.push({tp * w - tp * (w / 2), tp, w / 2});     }     long long int r1, r2, r3;     while (sum > s) {       tuple<long long int, long long int, long long int> x;       tuple<long long int, long long int, long long int> y;       r1 = r2 = r3 = 0;       if (!q1.empty()) x = q1.top();       if (!q2.empty()) y = q2.top();       if (!q1.empty()) {         long long int a = get<0>(x);         long long int b = get<1>(x);         long long int c = get<2>(x);         r1 = a;         q1.pop();         if (q1.empty())           r3 = b * c - b * (c / 2);         else {           r3 = max(get<0>(q1.top()), b * c - b * (c / 2));         }         q1.push(x);       }       if (!q2.empty()) r2 = get<0>(y);       if (r1 >= r2 || sum - r1 <= s) {         cnt++;         long long int a = get<0>(x);         long long int b = get<1>(x);         long long int c = get<2>(x);         sum -= a;         q1.pop();         q1.push({b * c - b * (c / 2), b, c / 2});       } else {         if (r1 + r3 >= r2) {           long long int a = get<0>(x);           long long int b = get<1>(x);           long long int c = get<2>(x);           sum -= a;           q1.pop();           q1.push({b * c - b * (c / 2), b, c / 2});           cnt++;         } else {           long long int a = get<0>(y);           long long int b = get<1>(y);           long long int c = get<2>(y);           sum -= a;           q2.pop();           q2.push({b * c - b * (c / 2), b, c / 2});           cnt += 2;         }       }     }     cout << cnt <<   n ;     for (int i = 0; i < n; i++) {       tot[i] = 0;       vis[i] = false;       adj[i].clear();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   void Get(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int L[2005][2005];   int R[2005][2005];   bool Rot;   int N, M, K;   int GetL(int X, int Y) {     if (L[X][Y] == Y) return Y;     return L[X][Y] = GetL(X, L[X][Y]);   }   int GetR(int X, int Y) {     if (R[X][Y] == Y) return Y;     return R[X][Y] = GetR(X, R[X][Y]);   }   void Init() {     Get(N);     Get(M);     Get(K);     if (N > M) {       std::swap(N, M);       Rot = 1;     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M + 1; j++) L[i][j] = R[i][j] = j;   }   int Ans;   int AnsX, AnsY;   int X0, Y0;   void Fresh(int X, int Y) {     if (X < 1 || X > N) return;     if (Y < 1 || Y > M) return;     int Dis = std::abs(X - X0) + std::abs(Y - Y0);     if (Rot) {       std::swap(X, Y);     }     if (Ans > Dis) {       Ans = Dis;       AnsX = X;       AnsY = Y;     } else if (Ans == Dis) {       if (AnsX > X) {         AnsX = X;         AnsY = Y;       } else if (AnsX == X && AnsY > Y) {         AnsX = X;         AnsY = Y;       }     }   }   void Work() {     for (int k = 1; k <= K; k++) {       Ans = 0x2f2f2f2f;       Get(X0);       Get(Y0);       if (Rot) std::swap(X0, Y0);       for (int d = 0; d <= Ans; d++) {         int X;         int Y;         if (X0 - d > 0) {           X = X0 - d;           Y = L[X][Y0];           Fresh(X, Y);           Y = R[X][Y0];           Fresh(X, Y);         }         if (X0 + d <= N) {           X = X0 + d;           Y = L[X][Y0];           Fresh(X, Y);           Y = R[X][Y0];           Fresh(X, Y);         }       }       printf( %d %d n , AnsX, AnsY);       if (Rot) {         std::swap(AnsX, AnsY);       }       L[AnsX][AnsY] = L[AnsX][AnsY - 1];       R[AnsX][AnsY] = R[AnsX][AnsY + 1];       for (int j = AnsY + 1; L[AnsX][j] != j; j++) L[AnsX][j] = L[AnsX][AnsY];       for (int j = AnsY - 1; L[AnsX][j] != j; j--) R[AnsX][j] = R[AnsX][AnsY];     }   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   const double eps = 1e-6;   const long long mod = 1000000007;   inline string getstr(string &s, long long l, long long r) {     string ret =   ;     for (long long i = l; i <= r; i++) ret.push_back(s[i]);     return ret;   }   long long modpow(long long x, long long y, long long md = mod) {     long long ret = 1;     do {       if (y & 1) ret = (long long)ret * x % md;       x = (long long)x * x % md;     } while (y >>= 1);     return ret;   }   long long n, mn;   vector<pair<long long, long long> > g[3003];   long long dfs(long long x, long long p, long long cur, long long mv) {     long long ret = 0;     mn = min(mn, cur - mv);     for (auto to : g[x])       if (to.first != p) {         ret += (to.second > 0);         ret += dfs(to.first, x, cur - to.second, max(mv, cur - to.second));       }     return ret;   }   signed main() {     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(make_pair(y, -1));       g[y].push_back(make_pair(x, 1));     }     long long ans = 1e9;     for (long long i = 1; i <= n; i++) {       mn = inf;       ans = min(ans, dfs(i, -1, 0, 0) + mn);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int>> vp;   int chk() {     bool ok = true;     int d = vp[2].first - vp[1].first;     for (int i = 2; i < n; i++)       if (vp[i].first - vp[i - 1].first != d) ok = false;     if (ok) {       printf( %d n , vp[0].second + 1);       exit(0);     }     d = vp[2].first - vp[0].first;     ok = true;     for (int i = 3; i < n; ++i)       if (vp[i].first - vp[i - 1].first != d) ok = false;     if (ok) {       printf( %d n , vp[1].second + 1);       exit(0);     }     d = vp[1].first - vp[0].first;     int cnt = 0, index = 0;     ok = true;     for (int i = 1; i < n; i++) {       if (vp[i].first - vp[i - 1].first == d) continue;       cnt++;       if (i == n - 1 or vp[i + 1].first - vp[i - 1].first != d) ok = false;       index = vp[i].second;       i++;     }     if (ok and cnt == 1) {       cout << index + 1 << endl;       exit(0);     }   }   int main() {     scanf( %d , &n);     vp.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &vp[i].first);       vp[i].second = i;     }     sort(begin(vp), end(vp));     chk();     if (n < 4) return !printf( 1 n );     reverse(begin(vp), end(vp));     chk();     cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int buff1, buff2;   void solution(vector<int> v) {     map<int, int> counter;     for (int n : v) counter[n]++;     vector<int> counts;     for (auto it : counter) {       counts.push_back(it.second);     }     sort(counts.begin(), counts.end(), greater<int>());     int cur = INT_MAX, ret = 0;     for (int n : counts) {       if (cur <= 1) {         break;       }       cur = min(cur - 1, n);       ret += cur;     }     cout << ret << endl;   }   int main() {     int nTest;     cin >> nTest;     for (int i = 0; i < nTest; i++) {       int N;       cin >> N;       vector<int> v;       for (int i = 0; i < N; i++) {         cin >> buff1;         v.push_back(buff1);       }       solution(v);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     for (int i = 0, c = 2 % n; i < n - 1; i++, c = (c + i + 1) % n) {       if (c)         cout << c <<    ;       else         cout << n << endl;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   int ss[250000], ff[250000], cc[250000], rr[250000], ii[250000];   int compare(const void *a, const void *b) {     int i = *(int *)a;     int j = *(int *)b;     return rr[i] - rr[j];   }   int main() {     static int aa[400];     typedef int ian[400];     static ian dp_[400], dq_[400], *dp = dp_, *dq = dq_, *tmp;     int n, m, h, h_, i, r, s, f;     long long v;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &aa[i]);     for (h = 0; h < m; h++) {       scanf( %d%d%d%d , &ss[h], &ff[h], &cc[h], &rr[h]);       ss[h]--;       ff[h]--;       ii[h] = h;     }     qsort(ii, m, sizeof *ii, compare);     for (s = 0; s < n; s++)       for (f = s + 1; f < n; f++) dp[s][f] = aa[f] - aa[s];     v = 0;     for (r = 0, h_ = 0; r <= n; r++) {       while (h_ < m && rr[h = ii[h_]] == r) {         long long x;         if (v < (x = (long long)dp[ss[h]][ff[h]] * cc[h])) v = x;         h_++;       }       for (s = 0; s < n; s++) {         i = s;         for (f = s + 1; f < n; f++) {           while (i < f && dp[s][i] < aa[f] - aa[i]) i++;           dq[s][f] = aa[f] - aa[i - 1];           if (dq[s][f] > dp[s][i]) dq[s][f] = dp[s][i];         }       }       tmp = dp;       dp = dq;       dq = tmp;     }     printf( %lld n , v);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int ans;   inline int f(int n) {     int rt = 0;     for (int i = 0; n / pow(k, i) != 0; i++) rt += n / pow(k, i);     return rt;   }   void bin_search() {     int s = 1, e = n;     int m;     while (s <= e) {       m = (s + e) / 2;       if (f(m) >= n) {         e = m - 1;         ans = m;       } else         s = m + 1;     }   }   int main() {     cin >> n >> k;     bin_search();     cout << ans << endl;     return 0;   }