malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int l, s, cnt, last, b[100005];   char a[100005];   int main() {     int i, j;     scanf( %s , a);     l = strlen(a);     for (i = 0; i < strlen(a); i++) {       if (a[i] ==  ( )         s++;       else if (a[i] ==  ) )         s--;       else if (a[i] ==  # ) {         s--;         cnt++;       }       if (s < 0) {         puts( -1 );         return 0;       }     }     for (i = 0; i < cnt; i++) {       b[i] = 1;     }     b[cnt - 1] += s;     s = 0;     for (i = 0, j = 0; i < strlen(a); i++) {       if (a[i] ==  ( )         s++;       else if (a[i] ==  ) )         s--;       else if (a[i] ==  # )         s -= b[j++];       if (s < 0) {         puts( -1 );         return 0;       }     }     for (i = 0; i < cnt; i++) {       printf( %d  , b[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, first, last, ans, flag;     cin >> n;     if (n <= 2) {       cout << 0 << endl;       return 0;     }     ans = flag = 0;     first = 1;     last = n;     for (int i = 1; i < n; i++) {       ans += (first + last) % (n + 1);       if (!flag) {         first++;         swap((first), last);       } else {         first--;         swap((first), last);       }       flag = 1 - flag;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int MAX = 1e5 + 55;   const int inf = 1e9 + 77;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-7;   int main() {     long long n;     scanf( %I64d , &n);     long long div = 3;     while (n % div == 0) div *= 3;     n /= div;     ++n;     printf( %I64d , n);     return 0;   }
#include <bits/stdc++.h>   #define ll long long      using namespace std;      void solve(){       ll n, i;       cin >> n;       ll u, r, d, l;       ll u1=0, r1=0, d1=0, l1=0;       cin >> u >> r >> d >> l;       if(u==n) r1++,l1++;       if(d==n) r1++,l1++;       if(r==n) u1++,d1++;       if(l==n) u1++,d1++;          if(u==n-1){           if(r1<r) r1++;           else l1++;       }       if(d==n-1){           if(r1<r) r1++;           else l1++;       }       if(r==n-1){           if(u1<u) u1++;           else d1++;       }       if(l==n-1){           if(u1<u) u1++;           else d1++;       }       if(u>=u1 and r>=r1 and l>=l1 and d>=d1) cout <<  YES n ;       else cout <<  NO n ;   }   int main(){       ios_base::sync_with_stdio(false); cin.tie(NULL);       ll t;       cin >> t;       while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int x;     cin >> x;     cin.ignore();     string input;     getline(cin, input);     int len = input.length();     int cnt[3] = {0};     for (int i = 0; i < len; i++) {       if (input[i] ==  0 )         cnt[0]++;       else if (input[i] ==  1 )         cnt[1]++;       else if (input[i] ==  2 )         cnt[2]++;     }     int max = len / 3;     cnt[0] = max - cnt[0];     cnt[1] = max - cnt[1];     cnt[2] = max - cnt[2];     if (cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0) {       std::cout << input <<   n ;     } else {       for (int i = 0; i < len && cnt[0] > 0; i++) {         if (input[i] ==  1  && cnt[1] < 0) {           input[i] =  0 ;           cnt[1]++;           cnt[0]--;         } else if (input[i] ==  2  && cnt[2] < 0) {           input[i] =  0 ;           cnt[2]++;           cnt[0]--;         }       }       for (int i = len - 1; cnt[2] > 0; i--) {         if (input[i] ==  1  && cnt[1] < 0) {           input[i] =  2 ;           cnt[1]++;           cnt[2]--;         } else if (input[i] ==  0  && cnt[0] < 0) {           input[i] =  2 ;           cnt[0]++;           cnt[2]--;         }       }       for (int i = 0; i < len && cnt[1] > 0 && cnt[2] < 0; i++) {         if (input[i] ==  2 ) {           input[i] =  1 ;           cnt[1]--;           cnt[2]++;         }       }       for (int i = len - 1; i >= 0 && cnt[1] > 0 && cnt[0] < 0; i--) {         if (input[i] ==  0 ) {           input[i] =  1 ;           cnt[1]--;           cnt[2]++;         }       }       std::cout << input <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[120], b[120], c[120], d[120];   map<int, int> mp;   vector<int> ans;   int main() {     memset(b, -1, sizeof(b));     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d %d , &x, &y);       b[x] = y;       mp[x] = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       ans.clear();       memcpy(c, a, sizeof(c));       memcpy(d, b, sizeof(d));       for (int q = 1; q <= m; q++) {         int choose = -1, hp = 2000000000;         for (int j = 1; j <= n; j++) {           if (d[j] == -1) continue;           int tmp = d[j], ok = 1;           if (j <= i) {             for (int k = j; k <= i; k++) {               tmp += c[k];               if (tmp < 0) {                 ok = 0;                 break;               }             }           } else {             for (int k = j; k >= i; k--) {               tmp += c[k];               if (tmp < 0) {                 ok = 0;                 break;               }             }           }           if (!ok) continue;           if (tmp < hp) {             choose = j;             hp = tmp;           }         }         if (choose == -1) break;         for (int j = min(i, choose); j <= max(i, choose); j++) c[j] = 0;         d[choose] = -1;         ans.push_back(choose);       }       if (ans.size() == m) {         printf( %d n , i);         for (int j = 0; j < ans.size(); j++) printf( %d  , mp[ans[j]]);         return 0;       }     }     printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 5;   long double x[maxN], y[maxN], r[maxN], val[maxN];   long double f(long double xx, long double yy) {     for (int i = 0; i < 3; ++i) {       val[i] = sqrt((x[i] - xx) * (x[i] - xx) + (y[i] - yy) * (y[i] - yy)) / r[i];     }     val[3] = val[0];     long double answer = 0;     for (int i = 0; i < 3; ++i)       answer += (val[i] - val[i + 1]) * (val[i] - val[i + 1]);     return answer;   }   int main() {     for (int i = 0; i < 3; ++i) cin >> x[i] >> y[i] >> r[i];     long double pX = (x[0] + x[1] + x[2]) / 3., pY = (y[0] + y[1] + y[2]) / 3.;     long double qq = 1.;     while (qq > 1e-5) {       if (f(pX - qq, pY) < f(pX, pY))         pX -= qq;       else if (f(pX + qq, pY) < f(pX, pY))         pX += qq;       else if (f(pX, pY - qq) < f(pX, pY))         pY -= qq;       else if (f(pX, pY + qq) < f(pX, pY))         pY += qq;       else         qq *= 0.777777777;     }     if (f(pX, pY) > 1e-5) return 0;     cout << fixed << setprecision(15) << pX <<     << pY << endl;     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-9;   const double PI = acos(-1.0);   const long long int mod = 1e9 + 7;   const int MAXN = 2e3 + 5;   using namespace std;   vector<vector<int>> adj(MAXN);   int mxd;   void dfs(int u, int d) {     mxd = max(mxd, d);     for (int v : adj[u]) dfs(v, d + 1);   }   void cp() {     int n;     cin >> n;     vector<int> roots;     for (int i = 0; i < n; i++) {       int p;       cin >> p;       if (p == -1)         roots.push_back(i);       else         adj[p - 1].push_back(i);     }     for (int u : roots) dfs(u, 1);     cout << mxd <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int power(long long int x, long long int y) {     long long int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   bool prime_check(long long int n) {     long long int i, j;     if (n == 1) {       return false;     }     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long int fact(long long int n) {     long long int prod = 1;     for (long long int i = 1; i <= n; i++) {       prod = (prod * i) % 1000000007;     }     return prod;   }   bool vowl(char c) {     return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, i;       cin >> n;       int a[n + 3];       multiset<int, greater<int>> ms;       for (i = 0; i < n; i++) {         cin >> a[i];         ms.insert(a[i]);       }       bool flag = 0;       int x = *ms.begin();       --x;       ms.erase(ms.begin());       while (!ms.empty()) {         int first = *ms.begin();         --first;         ms.erase(ms.begin());         if (x) ms.insert(x);         x = first;         flag = 1 - flag;       }       if (!flag)         cout <<  T               <<   n ;       else         cout <<  HL               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char nchar() {     static const int bufl = 1 << 20;     static char buf[bufl], *a = NULL, *b = NULL;     return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF                                                                           : *a++;   }   inline int read() {     int x = 0, f = 1;     char c = nchar();     for (; !isdigit(c); c = nchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = nchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int maxn = 1e5 + 1;   int n, m;   namespace sgt {   struct D {     double s, j;     D(double s = 0, double j = 0) : s(s), j(j) {}     inline void set() {       int x = read(), y = read();       double d = (double)x / y;       d = (1 - d) / d;       s = (j = d) + 1;     }     inline friend D operator+(D a, D b) {       return D(a.s + a.j * (b.s - 1), a.j * b.j);     }   } t[maxn << 1];   inline int ID(int l, int r) { return l + r | l != r; }   void build(int l, int r) {     int x = ID(l, r);     if (l == r) {       t[x].set();       return;     }     int mid = l + r >> 1;     build(l, mid), build(mid + 1, r);     t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)];   }   void reset(int l, int r, int p) {     int x = ID(l, r);     if (l == r) {       t[x].set();       return;     }     int mid = l + r >> 1;     p <= mid ? reset(l, mid, p) : reset(mid + 1, r, p);     t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)];   }   void reset(int p) { reset(1, n, p); }   D query(int L, int R, int l, int r) {     if (L == l && R == r) return t[ID(L, R)];     int mid = L + R >> 1;     if (r <= mid) return query(L, mid, l, r);     if (l > mid) return query(mid + 1, R, l, r);     return query(L, mid, l, mid) + query(mid + 1, R, mid + 1, r);   }   double query(int l, int r) {     D d = query(1, n, l, r);     return 1. / d.s;   }   }  // namespace sgt   int main() {     n = read(), m = read();     sgt::build(1, n);     while (m--) {       int o = read();       if (o == 1)         sgt::reset(read());       else {         int l = read(), r = read();         double ans = sgt::query(l, r);         printf( %.12lf n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 9223372036854775807LL;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroint-loops )   long long int power(long long int a, long long int b, long long int m) {     long long int res = 1;     while (b) {       if (b & 1) res = ((res % m) * (a % m)) % m;       a = ((a % m) * (a % m)) % m;       b >>= 1;     }     return res;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   void solve() {     long long int a, b, c, d, x, y;     cin >> a >> b >> c >> d >> x >> y;     if (abs(c - a) % x == 0 and abs(d - b) % y == 0) {       long long int xx = abs(c - a) / x;       long long int yy = abs(d - b) / y;       if ((xx & 1 and yy & 1) or (xx & 1 ^ 1 and yy & 1 ^ 1))         cout <<  YES ;       else         cout <<  NO ;     } else       cout <<  NO ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tt = 1;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[10000] = {0}, d[10000] = {0};   int main() {     int n, m, i;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       c[x]++;       d[y]++;     }     int ans = 0, j, kc = 0, kd = 0;     for (i = 2; i <= n - 1; i++) {       if (!c[i]) ans++;       if (!d[i]) ans++;     }     if (n % 2 == 1 && !c[(n + 1) / 2] && !d[(n + 1) / 2]) ans--;     printf( %d n , ans);     return 0;   }
#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 x = a[0], j = 0;     vector<int> pol(n, 0);     pol[0] = 1;     for (int i = 1; i < n; i++) {       if (a[i] == x)         pol[j]++;       else {         j++;         pol[j]++;         x = a[i];       }     }     bool same = 1;     for (int i = 1; i <= j; i++)       if (pol[i] != pol[i - 1]) same = false;     if (same)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int visited[200001];   int colour[200001];   vector<int> adj_list[200001];   int* graph[1000001];   int* finalcolour[1000001];   int size[1000001];   int check;   int count1 = 0;   int k[9];   int l[9];   int dp[9][1001];   int A[9][11];   int c[9][10];   bool pairCompare(const pair<int, int>& firstElem,                    const pair<int, int>& secondElem) {     return firstElem.first > secondElem.first;   }   int solve(int cards, int coins) {     int i;     if (cards <= 0) return 0;     if (dp[cards][coins] != -1) return dp[cards][coins];     int ret = A[cards][l[cards]] + solve(cards - 1, coins);     int use = 0;     int coins_left = coins;     for (i = l[cards] + 1; i <= k[cards]; i++) {       coins_left = coins_left - c[cards][i - 1];       if (coins_left >= 0)         ret = max(ret, A[cards][i] + solve(cards - 1, coins_left));       else         break;     }     dp[cards][coins] = ret;     return ret;   }   long long powe(long long a, long long b, long long k) {     if (b == 0) return 1;     long long temp = powe(a, b / 2, k);     temp *= temp;     if (temp >= k) temp %= k;     if (b % 2 == 1) temp *= a;     if (temp >= k) temp %= k;     return temp;   }   void dfs(int x) {     int i;     visited[x] = 1;     for (i = 0; i < adj_list[x].size(); i++) {       if (visited[adj_list[x][i]] == 0) {         printf( %d  , x);         if (colour[x] == -1) {           colour[x] = 1;         } else {           colour[x] = -1;         }         dfs(adj_list[x][i]);         if (colour[adj_list[x][i]] == -1) {           printf( %d %d  , x, adj_list[x][i]);           colour[adj_list[x][i]] = 1;           if (colour[x] == -1) {             colour[x] = 1;           } else {             colour[x] = -1;           }         }       }     }     printf( %d  , x);     if (colour[x] == -1) {       colour[x] = 1;     } else {       colour[x] = -1;     }   }   int main() {     int n, i, count = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &colour[i]);       visited[i] = 0;       if (colour[i] == 1) count++;     }     for (i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj_list[x].push_back(y);       adj_list[y].push_back(x);     }     if (count == n) {       printf( 1 n );       return 0;     }     if (colour[1] == -1)       colour[1] = 1;     else       colour[1] = -1;     dfs(1);     if (colour[1] == -1) {       printf( %d 1 %d  , adj_list[1][0], adj_list[1][0]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long inf = 4e18, mod = 1e9 + 7;   vector<pair<pair<long long, long long>, pair<long long, long long>>> v;   int segt[4 * 6000000 + 5], lazy[4 * 6000000 + 5];   void push(int v, int l, int r) {     segt[v] += lazy[v];     if (l != r) {       lazy[2 * v] += lazy[v];       lazy[2 * v + 1] += lazy[v];     }     lazy[v] = 0;   }   void update_range(int v, int l, int r, int qs, int qe, int x) {     push(v, l, r);     if (l > qe || r < qs) return;     if (qs <= l && r <= qe) {       lazy[v] += x;       push(v, l, r);       return;     }     int m = (l + r) / 2;     update_range(2 * v, l, m, qs, qe, x);     update_range(2 * v + 1, m + 1, r, qs, qe, x);     segt[v] = max(segt[2 * v], segt[2 * v + 1]);   }   int query(int v, int l, int r, int qs, int qe) {     push(v, l, r);     if (l > qe || r < qs) return 0;     if (qs <= l && r <= qe) return segt[v];     int m = (l + r) / 2;     int val1 = query(2 * v, l, m, qs, qe);     int val2 = query(2 * v + 1, m + 1, r, qs, qe);     return max(val1, val2);   }   void solve() {     int n, r;     cin >> n >> r;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       int X = x + y, Y = y - x;       int lx, ly, ux, uy;       lx = X - r, ux = X + r, ly = Y - r, uy = Y + r;       lx += 3000000;       ux += 3000000;       ly += 3000000;       uy += 3000000;       v.push_back({{ly, 0}, {lx, ux}});       v.push_back({{uy, 1}, {lx, ux}});     }     sort(v.begin(), v.end());     int res = 0;     for (auto it : v) {       if (it.first.second == 0)         update_range(1, 0, 6000000, it.second.first, it.second.second, 1);       else         update_range(1, 0, 6000000, it.second.first, it.second.second, -1);       int val = query(1, 0, 6000000, 0, 6000000);       res = max(res, val);     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   bool m[1001][1001];   bool ff[1001][1001];   int n, num;   int ans;   int main() {     cin >> n >> num;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= i + num; j++)         if (!m[i][(j - 1) % n + 1]) {           m[i][(j - 1) % n + 1] = true;           m[(j - 1) % n + 1][i] = true;           ff[i][(j - 1) % n + 1] = true;         } else {           cout << -1 << endl;           return 0;         }     if (n == 1) {       cout << -1 << endl;       return 0;     }     cout << num * n << endl;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (ff[i][j]) printf( %d %d n , i, j);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int a[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t, i, j, n, m, l, r;     cin >> n;     for (i = 0; i < n; i++) {       cin >> l;       a[l] = 1;     }     l = r = 0;     if (a[1] == 1) l++;     if (a[(int)1e6] == 1) l++;     for (i = 2, j = 1e6 - 1; i < j && l < n; i++, j--, r++) {       if (a[i] == 1) l++;       if (a[j] == 1) l++;     }     cout << r <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int AbsDifference(int a, int b) {     if (a >= b) return a - b;     return b - a;   }   long long AbsDifference(long long a, long long b) {     if (a >= b) return a - b;     return b - a;   }   const int mod = 1000000007;   const int mod2 = 1000000009;   const int inf = 1 << 30;   const long long infLL = 1ll << 62;   const int impossible = -1;   struct stoyan_point {     int x, y;     int id;   };   struct stoyan_pointLL {     long long x, y;     int id;   };   struct stoyan_segment {     stoyan_point first, second;     int lenght;     bool type;     int id;   };   struct stoyan_segmentLL {     stoyan_pointLL first, second;     long long lenght;     bool type;     int id;   };   string translate(int number, int lenght, int k) {     string ans;     while (number) {       ans += char(( 1 ) + number & 1);       number >>= 1;     }     reverse(ans.begin(), ans.end());     return ans;   }   vector<int> find_divisors(long long number) {     vector<int> ans;     int sq = sqrt(number), j;     for (j = 1; j <= sq; j++) {       if (number % j == 0) {         ans.push_back(j);         if (j * j != number) ans.push_back(number / j);       }     }     sort(ans.begin(), ans.end());     return ans;   }   int cnt_divisors(long long number) {     int ans = 0;     int sq = sqrt(number), j;     for (j = 1; j <= sq; j++) {       if (number % j == 0) {         ans++;         if (j * j != number) ans++;       }     }     return ans;   }   int n;   string s;   int x, y;   int where_last = 0;   int AnswerProblem;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     cin >> s;     for (int i = 0; i < int(s.size()); i++) {       if (s[i] ==  R )         x++;       else         y++;       if (y > x) {         if (where_last == -1) {           AnswerProblem++;         }         where_last = 1;       }       if (y < x) {         if (where_last == 1) {           AnswerProblem++;         }         where_last = -1;       }     }     cout << AnswerProblem << endl;     return 0;   }
#include <bits/stdc++.h>   int t[10000];   int main() {     int n, m, k;     std::cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         std::cin >> t[100 * i + j];       }     }     int ans = 1000000;     if (n > k) {       for (int j = 0; j < n; j++) {         int dc = 0;         for (int j2 = 0; j2 < m; j2++) {           int c = 0;           for (int i = 0; i < n; i++) {             if (t[100 * i + j] == t[100 * i + j2]) c++;           }           dc += std::min(c, n - c);         }         ans = std::min(ans, dc);       }     } else {       for (int j = 0; j < (1 << n); j++) {         int dc = 0;         for (int j2 = 0; j2 < m; j2++) {           int c = 0;           for (int i = 0; i < n; i++) {             if (((int)(bool)(j & (1 << i))) == t[100 * i + j2]) c++;           }           dc += std::min(c, n - c);         }         ans = std::min(ans, dc);       }     }     if (ans > k) {       std::cout << -1;     } else {       std::cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   char c[101];   int n, ans;   int check(int k) {     int cnt = 0, sum = 0;     for (int i = 0; i < n; i++) {       sum += c[i] -  0 ;       if (sum > k) return 0;       if (sum == k) sum = 0, cnt++;     }     return (sum == 0 && cnt > 1) ? 1 : 0;   }   int main() {     scanf( %d , &n);     scanf( %s , c);     for (int i = 0; i <= 1000; i++) {       if (check(i)) {         printf( YES );         return 0;       }     }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   int main() {     long long t, i, l, k, j, b[23132], s, n;     char ch[1000000];     while (gets(ch)) {       l = strlen(ch);       for (k = 0; k < 124; k++) b[k] = 0;       for (k = 0; k < l; k++) {         b[ch[k] - 48]++;       }       s = 0;       for (j = 0; j < 124; j++) {         if (0 < b[j]) s += b[j] * b[j];       }       printf( %lld n , s);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long w, m, k;   int main() {     scanf( %I64d%I64d%I64d , &w, &m, &k);     w /= k;     if (!w) {       puts( 0 );       return 0;     }     long long cnt = 0;     long long tmp = m;     while (tmp) {       cnt++;       tmp /= 10;     }     tmp = 1;     for (int i = 0; i < cnt; i++) tmp *= 10;     long long x = m - 1, y = tmp - 1;     while (w) {       if (w < cnt) break;       if (w >= (y - x) * cnt) {         w -= (y - x) * cnt;         x = y;         y = y * 10 + 9;         cnt++;       } else {         x += w / cnt;         w = 0;         break;       }     }     cout << x - m + 1 << endl;   }