fork download
  1. #include <cstdio>
  2. #include <cstring>
  3. #define mod 10007
  4. #define MN 100005
  5. int plus(int x, int y) {
  6. if (x+y < mod) return x+y;
  7. return (x+y)-mod;
  8. }
  9. int d[MN], pos[26], n;
  10. char S[MN];
  11. int main() {
  12. scanf("%s",S+1);
  13. n = strlen(S+1);
  14. for (int i = 1; i <= n; i++) {
  15. int k = (int)(S[i]-'a');
  16. if (pos[k] == 0) d[i]++;
  17. else d[i] = plus(d[i], d[pos[k]]);
  18. for (int j = pos[k]+1; j < i; j++) d[i] = plus(d[i], d[j]);
  19. pos[k] = i;
  20. }
  21. int res = 0;
  22. for (int i = 1; i <= n; i++) res = plus(res, d[i]);
  23. printf("%d",res);
  24. }
Success #stdin #stdout 0s 3788KB
stdin
Standard input is empty
stdout
Standard output is empty