-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABA.cpp
55 lines (47 loc) · 906 Bytes
/
ABA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define S string
#define vi vector<int>
#define V vector
#define usii unordered_set<int,int>
#define umii unordered_map<int,int>
#define um unordered_map
#define us unordered_set
#define bg begin()
#define ed end()
#define pb push_back
#define forloop for(int i=0;i<n;i++)
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
void solve()
{
S s;
cin >> s;
int n = s.size();
vi count(26, 0);
vi prefixSum(26, 0);
int result = 0;
for (int j = 0; j < n; j++)
{
int idx = s[j] - 'A';
result += prefixSum[idx];
for (int i = 0; i < 26; i++)
{
prefixSum[i] += count[i];
}
count[idx]++;
}
cout << result << nl;
}
signed main()
{
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}