Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("sdistante.in");
- ofstream fout("sdistante.out");
- const int mod = 1e9 + 7;
- int N;
- long long fr[52], last[52], presum[52], Sol, S;
- string s;
- int numar(const char &c)
- {
- if(c >= 'a')
- return c - 'a';
- return c - 'A' + 26;
- }
- int main()
- {
- fin>>s;
- N=s.size();
- for(int i=0; i<52; ++i)
- last[i]=N;
- for(int i=N-1; i>=0; --i)
- {
- int ch=numar(s[i]);
- presum[ch]+=(last[ch]-i)*fr[ch];
- ++fr[ch];
- last[ch]=i;
- Sol+=(i+1)*((N-i)*(N-i-fr[ch])-S+presum[ch]);
- if(Sol>= 1e17L)
- Sol%=mod;
- S+=N-i;
- }
- fout<<Sol%mod<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement