#include const int len = 100100; int B,D[len],F[len]; char S[len]; bool chk(int l) { l--; for (int i=0;i= 0) break; D[j] += B; D[j+1]--; } } int l = 1, r = len; while (l + 1 < r){ int m = (l + r) / 2; if (chk(m)) l = m; else r = m; } chk(l); int p = 0; for (int i=len-1;i>=0;i--){ p = (p * B + F[i]) % l; } F[0] -= p; for (int i=0;;i++){ if (F[i] >= 0) break; while (F[i] < 0){ F[i] += B; F[i+1]--; } } for (int i=len-1;i>=0;i--){ if (i) F[i-1] += F[i] % l; F[i] /= l; } l--; F[l]++; printf ("%d\n",F[l-p]); return 0; }