malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 80005, maxe = 3000005, maxs = 80005, INF = 0x3f3f3f3f;   int n, q, N, m, S, T, a[maxn];   struct event {     int x, l, r, f;     event(int _x = 0, int _l = 0, int _r = 0, int _f = 0)         : x(_x), l(_l), r(_r), f(_f) {}     bool operator<(const event &b) const {       return x < b.x || x == b.x && f > b.f;     }   } E[maxs];   int son[maxe], nxt[maxe], lnk[maxn], flw[maxe], cap[maxe], tot = 1;   inline void add(int x, int y, int f) {     son[++tot] = y;     nxt[tot] = lnk[x];     lnk[x] = tot;     flw[tot] = 0;     cap[tot] = f;     son[++tot] = x;     nxt[tot] = lnk[y];     lnk[y] = tot;     flw[tot] = 0;     cap[tot] = 0;   }   int d[maxn], que[maxn], pos[maxn];   bool bfs() {     memset(d, 63, sizeof(d));     int hed = 0, til = 1;     que[1] = S;     d[S] = 0;     while (hed != til) {       int x = que[++hed];       for (int j = lnk[x]; j; j = nxt[j])         if (d[son[j]] == INF && flw[j] < cap[j])           d[que[++til] = son[j]] = d[x] + 1;     }     return d[T] != INF;   }   int dfs(int x, int flow) {     if (x == T || flow == 0) return flow;     int res = 0, f;     for (int &j = pos[x]; j; j = nxt[j])       if (d[son[j]] == d[x] + 1 &&           (f = dfs(son[j], min(flow, cap[j] - flw[j]))) > 0) {         flw[j] += f;         flw[j ^ 1] -= f;         res += f;         flow -= f;         if (flow == 0) break;       }     return res;   }   int dinic() {     int ans = 0;     while (bfs()) {       memcpy(pos, lnk, sizeof(lnk));       ans += dfs(S, INF);     }     return ans;   }   int ls[maxs], rs[maxs], Rx, Ry;   void build(int &x, int l, int r, int d) {     x = ++N;     if (l == r) {       if (d)         add(x, T, 1);       else         add(S, x, 1);       return;     }     int mid = l + r >> 1;     build(ls[x], l, mid, d);     build(rs[x], mid + 1, r, d);     if (d)       add(x, ls[x], INF), add(x, rs[x], INF);     else       add(ls[x], x, INF), add(rs[x], x, INF);   }   void qry(int x, int l, int r, int ql, int qr, int z, int d) {     if (ql <= l && r <= qr) {       if (d)         add(z, x, INF);       else         add(x, z, INF);       return;     }     if (qr < l || r < ql) return;     int mid = l + r >> 1;     qry(ls[x], l, mid, ql, qr, z, d);     qry(rs[x], mid + 1, r, ql, qr, z, d);   }   void cover(int x, int l, int r) {     for (int i = l; i <= r; i++) a[i] = x;   }   void work(int x, int l, int r) {     for (int i = l, j = l; i <= r; i = j) {       while (j <= r && a[i] == a[j]) j++;       N++;       qry(Rx, 1, n, a[i] + 1, x, N, 0);       qry(Ry, 1, n, i, j - 1, N, 1);     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= q; i++) {       int x, y, xx, yy;       scanf( %d%d%d%d , &x, &y, &xx, &yy);       E[++m] = event(x - 1, y, yy, 0);       E[++m] = event(xx, y, yy, 1);     }     S = ++N;     T = ++N;     build(Rx, 1, n, 0);     build(Ry, 1, n, 1);     sort(E + 1, E + 1 + m);     for (int i = 1; i <= m; i++)       if (E[i].f)         cover(E[i].x, E[i].l, E[i].r);       else         work(E[i].x, E[i].l, E[i].r);     work(n, 1, n);     printf( %d , dinic());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-8;   const int N = 1e5 + 10;   int n, q;   int sgn(long double x) { return x < -EPS ? -1 : x > EPS; }   struct Point {     Point() {}     long double x, y;     Point(long double x, long double y) : x(x), y(y) {}     void read() { cin >> x >> y; }     Point operator-(const Point& p) { return Point(x - p.x, y - p.y); }     long double operator*(const Point& p) { return x * p.x + y * p.y; }     long double operator^(const Point& p) { return x * p.y - y * p.x; }     long double length() { return hypotl(x, y); }   } poly[N];   using Vec = Point;   long double getIntersection(Point p, Vec v, Point q, Vec w) {     return (w ^ (p - q)) / (v ^ w);   }   long double work(Point p, Vec v) {     long double ret = 0;     vector<pair<long double, int> > pos;     for (int i = 1; i <= n; i++) {       int s1 = sgn(v ^ (poly[i] - p));       int s2 = sgn(v ^ (poly[i + 1] - p));       if (s1 == s2) continue;       long double o = getIntersection(p, v, poly[i], poly[i + 1] - poly[i]);       if (s1 > s2)         pos.push_back({o, s1 && s2 ? 2 : 1});       else         pos.push_back({o, s1 && s2 ? -2 : -1});     }     sort(pos.begin(), pos.end());     int flag = 0;     for (int i = 0; i + 1 < pos.size(); i++) {       flag += pos[i].second;       if (flag) ret += pos[i + 1].first - pos[i].first;     }     return ret * v.length();   }   int main() {     ios ::sync_with_stdio(false);     cin >> n >> q;     for (int i = 1; i <= n; i++) poly[i].read();     poly[n + 1] = poly[1];     while (q--) {       Point a, b;       a.read();       b.read();       cout << fixed << setprecision(20) << work(a, b - a) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int i, n, k;       string s;       cin >> n;       cin >> s;       vector<pair<string, int> > ans;       for (i = 0; i < n; i++) {         string sl = s.substr(0, i);         string sr = s.substr(i, n - i);         if (i % 2 != n % 2) reverse(sl.begin(), sl.end());         ans.push_back(make_pair(sr + sl, i + 1));       }       sort(ans.begin(), ans.end());       cout << ans[0].first << endl << ans[0].second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string n, m;     int w = 0, b[10000];     cin >> n;     for (int i = 0; i < n.length(); i++) {       if (n.substr(i, 1) ==  r ) cout << i + 1 << endl;     }     for (int i = n.length() - 1; i >= 0; i--) {       if (n.substr(i, 1) ==  l ) cout << i + 1 << endl;     }     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned int max_ID(long long int a[], long long int b[], unsigned int n) {     unsigned int max_ID;     unsigned long long int max;     max_ID = 0;     max = pow(a[0] - b[0], 2);     for (unsigned int i = 1; i < n; i++) {       if (pow(a[i] - b[i], 2) > max) {         max_ID = i;         max = pow(a[i] - b[i], 2);       }     }     return max_ID;   }   int main() {     unsigned int n, k1, k2, ID;     unsigned long long int sum = 0;     cin >> n >> k1 >> k2;     long long int a[n], b[n];     for (unsigned int i = 0; i < n; i++) cin >> a[i];     for (unsigned int i = 0; i < n; i++) cin >> b[i];     while (k1 > 0 || k2 > 0) {       ID = max_ID(a, b, n);       if (pow((a[ID] - 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) {         if (k1 > 0) {           a[ID]--;           k1--;           continue;         }       }       if (pow(a[ID] - (b[ID] + 1), 2) < pow(a[ID] - b[ID], 2)) {         if (k2 > 0) {           b[ID]++;           k2--;           continue;         }       }       if (pow(a[ID] - (b[ID] - 1), 2) < pow(a[ID] - b[ID], 2)) {         if (k2 > 0) {           b[ID]--;           k2--;           continue;         }       }       if (pow((a[ID] + 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) {         if (k1 > 0) {           a[ID]++;           k1--;           continue;         }       }       if (pow(a[ID] - b[ID], 2) == 0) {         if (k1 > 0) {           a[ID]++;           k1--;         } else if (k2 > 0) {           b[ID]++;           k2--;         }       }     }     for (unsigned int i = 0; i < n; i++) {       sum += pow(a[i] - b[i], 2);     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   template <class T>   void Swap(T& a, T& b) {     a ^= b;     b ^= a;     a ^= b;   }   template <class type>   void show(type name) {     for (auto& nm : name) cerr << nm <<    ;     cerr <<   n ;   }   using lng = long long;   using ivec = vector<int>;   const int mxn = 10;   int check(ivec& nums, int n) {     int ans = 1e9;     for (int i = 0; i < (1 << (int)nums.size()); ++i) {       int cnt = 0;       for (int j = 0; j < (int)nums.size(); ++j) {         if ((i & (1 << j)) > 0) cnt += ceil(pow(3, nums[j]));       }       if (cnt >= n) ans = min(ans, cnt);     }     return ans;   }   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       ivec nums(min(n, mxn) + 1);       iota(begin(nums), end(nums), 0);       cout << check(nums, n) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     int c[2];     c[0] = c[1] = 0;     const int m[] = {2, 1};     for (int i = 0; i < s.size(); i++) {       int d = s[i] -  0 ;       cout << ((c[d]++ * m[d]) % 4) + 1 <<     << d + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void __p(T a) {     cout << a;   }   template <typename T, typename F>   void __p(pair<T, F> a) {     cout <<  { ;     __p(a.first);     cout <<  , ;     __p(a.second);     cout <<  } n ;   }   template <typename T>   void __p(std::vector<T> a) {     cout <<  { ;     for (auto it = a.begin(); it < a.end(); it++)       __p(*it), cout <<  ,} n [it + 1 == a.end()];   }   template <typename T, typename... Arg>   void __p(T a1, Arg... a) {     __p(a1);     __p(a...);   }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cout << name <<   :  ;     __p(arg1);     cout <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     int bracket = 0, i = 0;     for (;; i++)       if (names[i] ==  ,  && bracket == 0)         break;       else if (names[i] ==  ( )         bracket++;       else if (names[i] ==  ) )         bracket--;     const char *comma = names + i;     cout.write(names, comma - names) <<   :  ;     __p(arg1);     cout <<   |  ;     __f(comma + 1, args...);   }   void setIO(string s =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(cin.failbit);     if (((int)(s).size())) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   const int dx[] = {1, 0, 0, -1};   const int dy[] = {0, -1, 1, 0};   const char C[] = { D ,  L ,  R ,  U };   signed main() {     setIO();     int n, m, K;     cin >> n >> m >> K;     if (K & 1) return cout <<  IMPOSSIBLE , 0;     char a[n][m];     int dis[n][m];     int si = -1, sj = -1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         dis[i][j] = 1e9;         if (a[i][j] ==  X ) {           si = i, sj = j;           dis[si][sj] = 0;         }       }     }     priority_queue<pair<int, array<int, 2> > > q;     q.push({0, {si, sj}});     while (((int)(q).size())) {       int res = -q.top().first, i = q.top().second[0], j = q.top().second[1];       q.pop();       if (res != dis[i][j]) continue;       for (int k = 0; k < 4; ++k) {         int ni = i + dx[k], nj = j + dy[k];         if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) {           if (dis[ni][nj] > dis[i][j] + 1) {             dis[ni][nj] = dis[i][j] + 1;             q.push({-dis[ni][nj], {ni, nj}});           }         }       }     }     int i = si, j = sj;     string ans;     for (int x = K - 1; x >= 0; --x) {       for (int k = 0; k < 4; ++k) {         int ni = i + dx[k], nj = j + dy[k];         if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) {           if (dis[ni][nj] <= x) {             i = ni, j = nj;             ans.push_back(C[k]);             break;           }         }       }     }     if (((int)(ans).size()) < K) {       return cout <<  IMPOSSIBLE , 0;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<string> v(n);       string s;       for (int i = 0; i < n; ++i) {         cin >> v[i];         for (int j = 0; j < v[i].size(); ++j) {           if (v[i][j] >=  A  && v[i][j] <=  Z ) v[i][j] = v[i][j] -  A  +  a ;         }       }       cin >> s;       string ans = s;       for (int j = 0; j < s.size(); ++j) {         if (s[j] >=  A  && s[j] <=  Z ) s[j] = s[j] -  A  +  a ;       }       char lovable;       cin >> lovable;       if (lovable >=  A  && lovable <=  Z ) lovable = lovable -  A  +  a ;       vector<pair<int, int> > segments;       for (int i = 0; i < n; ++i)         for (int j = 0; j + v[i].size() <= s.size(); ++j)           if (s.substr(j, v[i].size()) == v[i])             segments.push_back(make_pair(j, j + v[i].size() - 1));       sort(segments.begin(), segments.end());       vector<pair<int, int> > final_segments;       for (int i = 0; i < segments.size();) {         pair<int, int> curr = segments[i];         int j = i;         while (j < segments.size() && segments[j].first <= curr.second) {           curr.second = max(curr.second, segments[j].second);           ++j;         }         final_segments.push_back(curr);         i = j;       }       for (int i = 0; i < final_segments.size(); ++i) {         for (int j = final_segments[i].first; j <= final_segments[i].second;              ++j) {           char c = ans[j];           if (c >=  A  && c <=  Z ) c = c -  A  +  a ;           if (c == lovable) {             char c_inv;             for (int i = 0; i < 26; ++i) {               if ( a  + i != lovable) {                 c_inv =  a  + i;                 break;               }             }             if (ans[j] >=  A  && ans[j] <=  Z )               ans[j] = c_inv -  a  +  A ;             else               ans[j] = c_inv;           } else {             if (ans[j] >=  A  && ans[j] <=  Z )               ans[j] = lovable -  a  +  A ;             else               ans[j] = lovable;           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   struct heap {     int heapsize;     int arr[100009];   };   void max_heapify(struct heap *c, int i, int *array) {     if (c->heapsize == 0) return;     int smallest, tmp;     if (((2 * i) <= c->heapsize) && (array[c->arr[2 * i]] > array[c->arr[i]]))       smallest = 2 * i;     else       smallest = i;     if (((2 * i + 1) <= c->heapsize) &&         (array[c->arr[2 * i + 1]] > array[c->arr[smallest]]))       smallest = 2 * i + 1;     if (smallest == i) return;     tmp = c->arr[i];     c->arr[i] = c->arr[smallest];     c->arr[smallest] = tmp;     max_heapify(c, smallest, array);     return;   };   int extract_max(struct heap *c, int *array) {     if (c->heapsize == 0) return 0;     int max;     max = c->arr[1];     c->arr[1] = c->arr[c->heapsize];     (c->heapsize)--;     max_heapify(c, 1, array);     return max;   };   void insert(struct heap *c, int *array, int key) {     int tmp;     c->heapsize = c->heapsize + 1;     c->arr[c->heapsize] = key;     int j = c->heapsize;     while (j > 1) {       if (array[c->arr[j]] > array[c->arr[j / 2]]) {         tmp = c->arr[j];         c->arr[j] = c->arr[j / 2];         c->arr[j / 2] = tmp;         j = j / 2;       } else         return;     }     return;   };   int main() {     int n, i, j, tmp;     scanf( %d , &n);     int array[n + 5];     struct heap aux;     aux.heapsize = 0;     char a[n + 5];     for (i = 1; i <= n; i++) {       scanf( %d , &array[i]);       a[i] = 48;     }     for (i = 1; i <= n; i++) {       if (array[i] != 0) {         insert(&aux, array, i);       } else if (array[i] == 0) {         j = 3;         while (j--) {           tmp = extract_max(&aux, array);           if (tmp > 0) a[tmp] = 49;         }         aux.heapsize = 0;       }     }     int count = 0;     for (i = 1; i <= n; i++) {       if (array[i] > 0 && a[i] == 49) {         count = count + 1;         if (count % 3 == 1)           printf( pushStack n );         else if (count % 3 == 2)           printf( pushQueue n );         else if (count % 3 == 0)           printf( pushFront n );       } else if (array[i] > 0 && a[i] == 48)         printf( pushBack n );       else if (array[i] == 0) {         if (count == 0)           printf( 0 n );         else if (count == 1) {           printf( 1 popStack n );           count = count - 1;         } else if (count == 2) {           printf( 2 popStack popQueue n );           count = count - 2;         } else if (count >= 3) {           printf( 3 popStack popQueue popFront n );           count = count - 3;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e18 + 10;   long long n, L, k;   string s, ans[N];   int ptr;   void doIt(int l, int r) {     if (l + 1 == r) {       while (ans[l].size() < L) ans[l] += s[ptr], ptr++;       return;     }     char last = s[ptr];     while (1) {       for (int i = l; i < r; i++) {         if (s[ptr] != last) {           doIt(i, r);           return;         }         if (ans[i].size() == L) return;         ans[i] += s[ptr];         last = s[ptr];         ptr++;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> L >> k >> s;     sort(s.begin(), s.end());     doIt(0, k);     for (int i = 0; i < n; i++)       while (ans[i].size() < L) ans[i] += s[ptr], ptr++;     sort(ans, ans + n);     for (int i = 0; i < n; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[100100];   int d[100100];   map<int, vector<int> > p;   int cntd[202] = {0};   int main(int argc, char** argv) {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> d[i];     for (int i = 0; i < n; i++) {       cntd[d[i]]++;       p[l[i]].push_back(d[i]);     }     int sumcnt = 0;     int sumval = 0;     int ans = 1e9;     int m = n;     for (map<int, vector<int> >::reverse_iterator it = p.rbegin(); it != p.rend();          it++) {       int j = 0;       for (int i = 0; i < it->second.size(); i++) {         cntd[it->second[i]]--;       }       j = 0;       int need = m - (2 * (it->second.size())) + 1;       int deleted = 0;       while (j <= 201 && need > 0) {         if (cntd[j] != 0) {           deleted += ((min(need, cntd[j])) * j);           need -= min(need, cntd[j]);         }         j++;       }       ans = min(ans, sumval + deleted);       m -= it->second.size();       for (int i = 0; i < it->second.size(); i++) {         sumval += (it->second[i]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void solve() {     long long int a, s;     cin >> a >> s;     vector<long long int> b;     while (s) {       long long int x = a % 10;       long long int y = s % 10;       if (y >= x) {         b.push_back(y - x);       } else {         s /= 10;         y += 10 * (s % 10);         if (y > x && y <= 18 && y >= 10) {           b.push_back(y - x);         } else {           cout << -1 <<   n ;           return;         }       }       s /= 10;       a /= 10;     }     if (a) {       cout << -1 <<   n ;       return;     }     while (b.back() == 0) b.pop_back();     reverse((b).begin(), (b).end());     for (long long int x : b) cout << x;     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     cin >> T;     for (long long int i = 1; i <= T; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n, p;       scanf( %d%d , &n, &p);       for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 1) % n + 1);       for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 2) % n + 1);       int k = 3;       while (p) {         for (int i = 0; i < n && p + 0; i++) {           p--;           printf( %d %d n , i + 1, (i + k) % n + 1);         }         k++;       }     }   }
#include <bits/stdc++.h>   const double EPS = 0.0000000001;   const long long mod1 = 998244353;   const long long mod2 = 1000000007;   const long long mod3 = 1000000009;   const long long mod4 = 228228227;   const long long inf = 100000000000000;   using namespace std;   signed main() {     long long t;     cin >> t;     for (long long q = 0; q < t; q++) {       long long n, a, b;       cin >> n >> a >> b;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       sort(v.begin(), v.end());       long long dp[n];       dp[0] = v[0];       for (long long i = 1; i < n; i++) {         dp[i] = inf;         if ((i - b) == -1) {           dp[i] = v[i];         }         if ((i - b) >= 0) dp[i] = dp[i - b] + v[i];         dp[i] = min(dp[i], dp[i - 1] + v[i]);       }       for (long long i = n - 1; i >= 0; i--) {         if (dp[i] <= a) {           cout << i + 1 << endl;           break;         }       }       if (dp[0] > a) cout << 0 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   class Triplet {    public:     long long x;     long long y;     long long gcd;   };   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   Triplet extendedEuclid(long long a, long long b) {     if (b == 0) {       Triplet ans;       ans.gcd = a;       ans.x = 1;       ans.y = 0;       return ans;     }     Triplet smallAns = extendedEuclid(b, a % b);     Triplet ans;     ans.gcd = smallAns.gcd;     ans.x = smallAns.y;     ans.y = smallAns.x - (a / b) * smallAns.y;     return ans;   }   long long modulo(long long a, long long m) {     Triplet ans = extendedEuclid(a, m);     return ans.x;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, a;       cin >> n >> a;       long long arr[n];       long long maxi = 0;       bool found = false;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         if (found) continue;         if (a % arr[i] == 0) {           if (a / arr[i] == 1) {             found = true;             maxi = arr[i];           }         }         maxi = max(maxi, arr[i]);       }       if (found) {         cout <<  1 n ;         continue;       } else {         if (maxi > a) {           cout <<  2 n ;           continue;         } else {           long long ans = (a / maxi);           if (a % maxi != 0) ans++;           cout << ans << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       long long pos;       cin >> pos;       if (pos == 1) {         cout << 1 << endl;         continue;       }       long long total = 0;       long long ant = 0;       long long desloc = 1;       long long vezes = 1;       while (true) {         ant += desloc;         if (total + ant > pos) break;         total += ant;         vezes++;         if (vezes == 10 or vezes == 100 or vezes == 1000 or vezes == 10000 or             vezes == 100000 or vezes == 1000000 or vezes == 10000000)           desloc++;       }       if (total == pos) {         cout << (vezes - 1) % 10 << endl;       } else {         bool ok = false;         for (int j = vezes;; j++) {           for (int i = 1; i <= vezes; i++) {             long long digitos = log10(i) + 1;             if (total + digitos < pos) {               total += digitos;             } else {               string base = to_string(i);               for (long long i = 0; i < base.size(); i++) {                 if (i + 1LL + total == pos) {                   ok = true;                   cout << base[i] << endl;                   break;                 }               }             }             if (ok) break;           }           if (ok) break;         }       }     }     return 0;   }