malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline long long read(void) {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   int n;   int main() {     n = read();     int l = 0, r = 1000000000;     cout << 1 <<     << 0 << endl;     fflush(stdout);     char ch[10];     scanf( %s , ch + 1);     bool flag = false;     if (ch[1] ==  b ) {       flag = true;     }     for (register int i = 1; i < n; ++i) {       int mid = (l + r + 1) >> 1;       cout << 1 <<     << mid << endl;       fflush(stdout);       scanf( %s , ch + 1);       if (flag) {         ch[1] = (ch[1] ==  w ) ?  b  :  w ;       }       if (ch[1] ==  w ) {         l = mid;       } else {         r = mid;       }     }     printf( 0 %d 2 %d , l, l + 1);     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     std::string name;     std::cin >> name;     bool atFlag = false;     std::string result =   ;     result += name[0];     for (int i = 1; i < name.length(); i++) {       if (!atFlag && name.substr(i, 2) ==  at ) {         result +=  @ ;         ++i;         atFlag = true;       } else if (i + 3 < name.length() && name.substr(i, 3) ==  dot ) {         result +=  . ;         i += 2;       } else {         result += name[i];       }     }     std::cout << result;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, mm, s, it;   int a[200005], r[200005], so[200005], ne[200005];   bool u[200005];   string ss, na[200005];   vector<int> v[200005];   queue<int> q;   map<string, int> m;   inline string sb(string v) {     for (int i = 0; i < v.size(); i++)       if (v[i] <  a ) v[i] += 32;     return v;   }   inline void ope(string &x) {     x = sb(x);     if (m[x]) return;     m[x] = ++s;     for (int i = 0; i < x.size(); i++) r[s] += (x[i] ==  r );     na[s] = x;     so[s] = s;     return;   }   inline bool cmp(int x, int y) {     if (r[x] != r[y]) return r[x] < r[y];     return na[x].size() < na[y].size();   }   inline bool same(int x, int y) {     return r[x] == r[y] && na[x].size() == na[y].size();   }   inline void dfs(int x, int y) {     if (u[x]) return;     u[x] = 1;     ne[x] = y;     for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], y);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ss;       ope(ss);       a[i] = m[ss];     }     m[  ] = 200002;     r[200002] = 2147483640;     cin >> mm;     for (int i = 1; i <= mm; i++) {       string p, q;       cin >> p >> q;       ope(p);       ope(q);       v[m[q]].push_back(m[p]);     }     sort(so + 1, so + s + 1, cmp);     for (int i = 1; i <= s; i++) dfs(so[i], so[i]);     long long rr = 0, ll = 0;     for (int i = 1; i <= n; i++) rr += r[ne[a[i]]], ll += na[ne[a[i]]].size();     cout << rr <<     << ll << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN(1e3 + 10);   int N, M, P[maxN], A[maxN][maxN], C;   void dfs(const int u) {     C++;     for (int v = 1; v <= N; v++)       if (A[u][v] && !P[v]) {         P[v] = u;         dfs(v);       }   }   int main() {     cin >> N >> M;     if (M != N - 1) {       cout <<  no ;       return 0;     }     for (int i = 0; i < M; i++) {       int u, v;       cin >> u >> v;       A[u][v] = A[v][u] = 1;     }     P[1] = -1;     dfs(1);     cout << (C == N ?  yes  :  no );   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a, x, y;     cin >> a >> x >> y;     if (y % a == 0)       cout << -1;     else {       long long ratio = (long long)(y / a);       if (ratio > 0) {         if (((long long)(y / a)) % 2 == 1) {           if (2 * abs(x) < a)             cout << 2 * ratio - (long long)(ratio / 2);           else             cout << -1;         } else {           if (x != 0 && abs(x) < a && x < 0)             cout << 2 * ratio - (ratio / 2);           else if (x != 0 && abs(x) < a && x > 0)             cout << 2 * ratio - (ratio / 2) + 1;           else             cout << -1;         }       } else if (2 * abs(x) < a)         cout << 1;       else         cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   int tmp;   string s;   char a[3][10] = {{ q ,  w ,  e ,  r ,  t ,  y ,  u ,  i ,  o ,  p },                    { a ,  s ,  d ,  f ,  g ,  h ,  j ,  k ,  l ,  ; },                    { z ,  x ,  c ,  v ,  b ,  n ,  m ,  , ,  . ,  / }};   char Tinh(char c) {     for (int i = 0; i < 3; i++)       for (int j = 0; j < 10; j++)         if (a[i][j] == c) return a[i][j + tmp];   }   int main() {     char ss;     cin >> ss;     if (ss ==  R )       tmp = -1;     else       tmp = 1;     cin >> s;     string res =   ;     for (int i = 0; i < s.length(); i++) {       res += Tinh(s[i]);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 100;   int n, k;   struct node {     int sz;     int mn[15], mx[15];     void init(int a) {       sz = 0;       for (int i = 1; i <= k; i++) {         mx[i] = mn[i] = a;       }     }     void unit(node a) {       sz += a.sz;       for (int i = 1; i <= k; i++) {         mn[i] = min(mn[i], a.mn[i]);         mx[i] = max(mx[i], a.mx[i]);       }     }     bool operator<(const node& p) const {       for (int i = 1; i <= k; i++) {         if (mx[i] > p.mn[i]) return false;       }       return true;     }   };   set<node> s;   vector<set<node>::iterator> del;   int main() {     scanf( %d %d , &n, &k);     node now;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= k; j++) scanf( %d , &now.mn[j]), now.mx[j] = now.mn[j];       now.sz = 1;       set<node>::iterator l, r, iter;       r = s.upper_bound(now);       l = s.lower_bound(now);       for (iter = l; iter != r; iter++) {         now.unit(*iter);         del.push_back(iter);       }       for (int j = 0; j < del.size(); j++) {         s.erase(del[j]);       }       del.clear();       s.insert(now);       iter = s.end();       iter--;       printf( %d n , iter->sz);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       int n;       cin >> n;       int a[n], f[1005] = {0};       for (int i = 0; i < n; i++) {         cin >> a[i];         f[a[i]]++;       }       int h = 0, t = 0;       for (int i = 0; i < 1005; i++) {         if (f[i]) t++;         h = max(h, f[i]);       }       cout << h <<     << t;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   pair<int, int> fff(const string &s, char x) {     pair<int, int> res;     int cc = 0;     for (int i = 0; i < s.length(); i++)       if (s[i] == x) cc++;     if (cc >= k) {       res.first = 0;       res.second = 0;       return res;     }     int cost = 0;     for (int i = 1; i <= 9; i++)       for (int j = 0; j < s.length(); j++)         if (abs(s[j] - x) == i) {           cc++;           cost += abs(s[j] - x);           if (cc == k) {             res.first = cost;             res.second = i;             return res;           }         }   }   string change(string s, char x, int d) {     int cc = 0;     for (int i = 0; i < s.length(); i++)       if (abs(s[i] - x) < d) {         cc++;         s[i] = x;       }     if (cc == k) return s;     for (int i = 0; i < s.length(); i++)       if (s[i] - x == d) {         s[i] = x;         cc++;         if (cc == k) return s;       }     for (int i = s.length(); i-- > 0;)       if (x - s[i] == d) {         s[i] = x;         cc++;         if (cc == k) return s;       }   }   const string &min(const string &s, const string &t) {     if (s > t) return t;     return s;   }   int main() {     scanf( %d%d , &n, &k);     cin >> s;     int cost = 1000000000;     string res =   ;     for (char x =  0 ; x <=  9 ; x++) {       pair<int, int> a = fff(s, x);       if (cost > a.first) {         cost = a.first;         res = change(s, x, a.second);       } else if (cost == a.first)         res = min(res, change(s, x, a.second));     }     cout << cost << endl << res;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using v = vector<T>;   const ll K = 1000;   const ll N = 1e5;   const ll B = N / K + 1;   ll n;   ll arr[N + 1];   ll cnt[N + 1];   ll bin[B + 1];   ll greedy(ll k) {     fill(begin(cnt), end(cnt), 0);     v<ll> dif;     ll bits = 0;     for (ll i = 1; i <= n; i++) {       ll val = arr[i];       if (cnt[val] == 0) {         if ((ll)dif.size() == k) {           for (const auto& color : dif) {             cnt[color] = 0;           }           dif.clear();           bits++;         }         dif.push_back(val);       }       cnt[val]++;     }     if (dif.size() > 0) {       bits++;     }     return bits;   }   int main(int argc, char const* argv[]) {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     cin >> n;     for (ll i = 0; i < n; i++) {       cin >> arr[i + 1];     }     v<ll> resarr(n + 1, -1);     for (ll k = 1; k <= min(K, n); k++) {       resarr[k] = greedy(k);     }     fill(begin(bin), end(bin), 1);     for (ll b = 1; b <= B; b++) {       ll lo = 1;       ll hi = (b > 1) ? bin[b - 1] : n;       while (lo != hi) {         ll mid = (lo + hi) / 2;         ll curbits = greedy(mid);         if (curbits <= b) {           hi = mid;         } else {           lo = mid + 1;         }       }       bin[b] = lo;     }     for (ll k = K + 1; k <= n; k++) {       ll lo = 1;       ll hi = resarr[k - 1];       while (lo != hi) {         ll mid = (lo + hi) / 2;         if (bin[mid] <= k) {           hi = mid;         } else {           lo = mid + 1;         }       }       resarr[k] = lo;     }     for (ll i = 1; i <= n; i++) {       cout << resarr[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const long long mod = 1e9 + 7;   const int inf = 1 << 30;   const int maxn = 600500;   const double EPS = 1e-7;   void solve() {     int q;     scanf( %d , &q);     while (q--) {       long long n;       scanf( %lld , &n);       int a, b;       scanf( %d%d , &a, &b);       if (b < 2LL * a) {         printf( %lld n , (n / 2LL) * 1LL * b + a * (n % 2));       } else         printf( %lld n , a * 1LL * n);     }   }   int main() {     int tc = 1;     for (int tt = 0; tt < (int)(tc); ++tt) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print_array(T arr[], int size_arr) {     for (int i = (0); i < (size_arr); i++) {       cout << arr[i];       if (i == size_arr - 1)         cout << endl;       else         cout <<    ;     }   }   template <typename T>   void print_vector(vector<T> v) {     for (int i = (0); i < (v.size()); i++) {       cout << v[i];       if (i == v.size() - 1)         cout << endl;       else         cout <<    ;     }   }   template <typename T>   void memset_array(T arr[], T value, int size_arr) {     for (int i = (0); i < (size_arr); i++) {       arr[i] = value;     }   }   bool compare_lexical_string(string a, string b) {     for (int i = (0); i < (min(a.length(), b.length())); i++) {       if (a[i] != b[i]) return a[i] < b[i];     }     return a.length() < b.length();   }   struct lex_string {     bool operator()(string a, string b) { return compare_lexical_string(a, b); }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long b, d, s;     cin >> b >> d >> s;     long long max_num, min_num;     max_num = max(b, max(d, s));     min_num = min(b, min(d, s));     if (max_num == min_num)       cout << 0 << endl;     else {       if (max_num == b) {         long long count = 0;         if (d < b) count += b - 1 - d;         if (s < b) count += b - 1 - s;         cout << count << endl;       } else if (max_num == d) {         if (d == s)           cout << d - 1 - b << endl;         else {           cout << 2 * d - 2 - b - s << endl;         }       } else {         cout << s - 1 - b + s - 1 - d << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x = 0, y = 0, z = 0;       int ar[4];       for (int i = 0; i < 4; i++) {         cin >> ar[i];       }       x = ar[1];       y = ar[2];       z = ar[2];       cout << x <<     << y <<     << z << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int N = (int)3e5 + 2;   int n;   bool a[N << 1];   int ans, ansl, ansr;   inline long long read() {     long long x = 0;     char ch = getchar();     for (; ch >  9  || ch <  0 ; ch = getchar())       ;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + (ch ^ 48);     return x;   }   int main() {     n = read();     int cnt = 0, mn = 0, pos = -1;     for (int i = 0; i < n; ++i) {       char ch = getchar();       if (ch ==  ( )         ++cnt;       else         a[i] = a[i + n] = 1, --cnt;       if (mn > cnt)         mn = cnt, pos = i, ans = 1;       else if (mn == cnt)         ++ans;     }     if (cnt) {       printf( 0 n1 1 );       return 0;     }     int I = n + ++pos, num[2] = {0, 0}, l[2], tmp = ans;     for (int i = pos; i < I; ++i) {       if (!a[i]) {         ++cnt;         if (cnt == 1)           ++num[0], l[0] = i;         else if (cnt == 2)           ++num[1], l[1] = i;       } else {         --cnt;         if (!cnt) {           if (num[0] > ans) {             ans = num[0];             ansl = l[0];             ansr = i;           }           num[0] = 0;         } else if (cnt == 1) {           if (tmp + num[1] > ans) {             ans = tmp + num[1];             ansl = l[1];             ansr = i;           }           ++num[0];           num[1] = 0;         } else if (cnt == 2)           ++num[1];       }     }     printf( %d n%d %d , ans, ansl % n + 1, ansr % n + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937_64 rng(61378913);   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   long long n, m, k, q, l, r, x, y, z;   const long long template_array_size = 1e6 + 8432;   long long a[template_array_size];   long long b[template_array_size];   long long c[template_array_size];   string second, t;   long long ans = 0;   void solve(int tc = 0) {     bool dead[10] = {0};     long long v = 0;     cin >> n;     for (long long i = 0; i < n; i++) {       char c;       cin >> c >> x;       if (c ==  | ) {         for (long long j = 0; j < 10; j++) {           if (x & (1 << j)) dead[j] = 1;         }         v |= x;       } else if (c ==  & ) {         for (long long j = 0; j < 10; j++) {           if (!(x & (1 << j))) dead[j] = 1;         }         v &= x;       } else {         v ^= x;       }     }     long long ov = 0;     for (long long i = 0; i < 10; i++) {       if (!dead[i]) ov += (1 << i);     }     cout << 2 <<   n ;     cout <<  &   << ov <<   n ;     cout <<  ^   << v <<   n ;   }   int main() {     { ios_base::sync_with_stdio(false); }     { cin.tie(NULL); }     cout << setprecision(12) << fixed;     int tc = 1;     for (int t = 0; t < tc; t++) solve(t);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b, t;     cin >> t;     int arr[t];     for (int i = 0; i < t; i++) {       cin >> a >> b;       arr[i] = a + b;     }     for (int i = 0; i < t; i++) {       cout << arr[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     string a1(b.size(),  0 );     string b1(a.size(),  0 );     a1 = a1 + a;     b1 = b1 + b;     if (a1 > b1) cout <<  >  << endl;     if (a1 == b1) cout <<  =  << endl;     if (a1 < b1) cout <<  <  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000009;   map<pair<int, int>, int> in, id;   set<int> S;   int X[100010], Y[100010];   bool check(pair<int, int> P) {     int x = P.first, y = P.second + 1;     for (int dx = x - 1; dx <= x + 1; dx++) {       if (in.count(make_pair(dx, y)) && in[make_pair(dx, y)] == 1) return 0;     }     return 1;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       X[i] = x, Y[i] = y;       in[make_pair(x, y)] = 0, id[make_pair(x, y)] = i;     }     for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end();          it++) {       int x = it->first.first, y = it->first.second - 1;       for (int dx = x - 1; dx <= x + 1; dx++) {         if (in.count(make_pair(dx, y))) {           in[it->first]++;         }       }     }     for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end();          it++) {       if (check(it->first)) S.insert(id[it->first]);     }     long long ans = 0;     for (int it = 0; it < n; it++) {       if (it & 1) {         int v = *S.begin();         S.erase(S.begin());         int y = Y[v] + 1;         id.erase(make_pair(X[v], Y[v]));         in[make_pair(X[v], Y[v])] = 0;         for (int x = X[v] - 1; x <= X[v] + 1; x++) {           if (!id.count(make_pair(x, y))) continue;           in[make_pair(x, y)]--;         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         ans = (ans * n + v) % mod;       } else {         int v = *(--S.end());         S.erase(--S.end());         int y = Y[v] + 1;         id.erase(make_pair(X[v], Y[v]));         in[make_pair(X[v], Y[v])] = 0;         for (int x = X[v] - 1; x <= X[v] + 1; x++) {           if (!id.count(make_pair(x, y))) continue;           in[make_pair(x, y)]--;         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         ans = (ans * n + v) % mod;       }     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   #include<algorithm>   #include<iostream>   #include<cstdio>   #include<cmath>   #include<cstring>   #include<stack>   #include<queue>   using namespace std;   typedef long long ll;   const ll INF=0x7f7f7f7f;   const int maxn=2e5+7;   const ll mod=1e9+7;   ll read(){       ll f=0,x=0;char ch=getchar();       while(!isdigit(ch)){if(ch== - ) f=1;ch=getchar();}       while(isdigit(ch)){x=x*10+ch- 0 ;ch=getchar();}       return !f?x:-x;   }   int tt,n,s[maxn];   bool check(int x,int y){       if(x==3){           if(s[y]>=s[y+1]&&s[y+1]>=s[y+2]) return false;           if(s[y]<=s[y+1]&&s[y+1]<=s[y+2]) return false;           return true;       }       else{           for(int i=0;i<4;i++){               for(int j=i+1;j<4;j++){                   for(int k=j+1;k<4;k++){                       if(s[y+i]>=s[y+j]&&s[y+j]>=s[y+k]) return false;                       if(s[y+i]<=s[y+j]&&s[y+j]<=s[y+k]) return false;                   }               }           }           return true;       }   }   int main(){       scanf( %d ,&tt);       while(tt--){           ll ans=0;           scanf( %d ,&n);           for(int i=1;i<=n;i++){               scanf( %d ,&s[i]);           }           ans+=2*n-1;           for(int i=3;i<=4;i++){               for(int j=1;j<=n-i+1;j++){                   if(check(i,j)) ans++;               }           }           printf( %lld n ,ans);       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans, dp[8][8];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       dp[l][r] = dp[r][l] = 1;     }     if (n <= 6)       cout << m;     else {       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           int res = 0;           for (int k = 1; k <= n; k++)             if (dp[i][k] && dp[j][k]) res++;           ans = max(ans, m - res);         }       cout << ans;     }   }
#include <bits/stdc++.h>      using std::cin;   using std::cout;   using std::vector;   using std::swap;      int main() {    int t;    cin >> t;        while (t--) {     int n, x;     cin >> n >> x;     vector<int> a(n);     for (auto& it : a) cin >> it;     int cnt = 0;     for (int i = 0; i < n && !is_sorted(a.begin(), a.end()); ++i) {      if (a[i] > x) {       swap(a[i], x);       cnt++;      }     }     cout << (!is_sorted(a.begin(), a.end()) ? -1 : cnt) <<   n ;    }        return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 303;   int n, m, d;   int a[maxn], b[maxn], t[maxn];   int dt[maxn];   long long que[150001];   int id[150001];   long long dp[150001][2];   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , a + i, b + i, t + i);       dt[i] = t[i] - t[i - 1];     }     dt[1] = n;     for (int ii = 1; ii <= m; ++ii) {       int i = ii % 2;       int l = 1, r = 1, nl = 1, nr = 1;       int lt, rt;       for (int j = 1; j <= n; ++j) {         lt = max(1ll, 1ll * j - 1ll * dt[ii] * d);         rt = min(1ll * n, 1ll * j + 1ll * dt[ii] * d);         while (nr <= rt) {           while (r > l && dp[nr][1 - i] >= que[r - 1]) r--;           que[r] = dp[nr][1 - i];           id[r] = nr;           r++;           nr++;         }         while (r > l && id[l] < lt) l++;         dp[j][i] = que[l] + 1ll * b[ii] - 1ll * abs(a[ii] - j);       }     }     long long ans = dp[1][m % 2];     for (int i = 2; i <= n; ++i) {       ans = max(ans, dp[i][m % 2]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   long long p;   int k;   namespace solver1 {   void main() {     std::vector<int> ans;     int i;     for (i = 0; p; i++) {       if (i & 1)         ans.push_back(((p - 1) / k + 1) * k - p), p = (p - 1) / k + 1;       else         ans.push_back(p % k), p /= k;     }     printf( %d n , (int)ans.size());     for (auto i : ans) {       printf( %d  , i);     }     printf(  n );   }   }  // namespace solver1   int main() {     std::cin >> p >> k;     solver1::main();   }