Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python2 | m_count = 0
a_count = 0
r_count = 0
c_count = 0
h_count = 0
n = input()
for i in range(n):
name = raw_input()
if name[0] == 'M':
m_count += 1
elif name[0] == 'A':
a_count += 1
elif name[0] == 'R':
r_count += 1
elif name[0] == 'C':
c_count += 1
elif name[0] == 'H':
h_count += 1
count = 0
count += m_count * a_count * r_count
count += m_count * r_count * c_count
count += m_count * c_count * h_count
count += a_count * r_count * c_count
count += a_count * c_count * h_count
count += r_count * c_count * h_count
count += m_count * a_count * c_count
count += m_count * a_count * h_count
count += m_count * r_count * h_count
print count
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
long long to;
long long cost;
};
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
int N;
cin >> N;
long long cnt = 0;
unordered_map<char, int> mp{};
for (int i = 0; i < (int)(N); i++) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
continue;
}
mp[s[0]]++;
}
long long ans = 0;
for (int i = 0; i < (int)(3); i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += mp[c[i]] * mp[c[j]] * mp[c[k]];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
long long solve(const int pos, vector<int> &acc,
const vector<long long> &cnts) {
if (acc.size() == 3) {
printf("%d, %d, %d\n", acc[0], acc[1], acc[2]);
return cnts[acc[0]] * cnts[acc[1]] * cnts[acc[2]];
}
if (pos >= 5) {
return 0LL;
}
long long sum = 0LL;
for (int i = pos; i < 5; i++) {
acc.push_back(i);
sum += solve(i + 1, acc, cnts);
acc.pop_back();
}
return sum;
}
int main(void) {
int N;
cin >> N;
long long cnt_m = 0;
long long cnt_a = 0;
long long cnt_r = 0;
long long cnt_c = 0;
long long cnt_h = 0;
for (int i = 0; i < N; i++) {
string name;
cin >> name;
switch (name[0]) {
case 'M':
cnt_m++;
break;
case 'A':
cnt_a++;
break;
case 'R':
cnt_r++;
break;
case 'C':
cnt_c++;
break;
case 'H':
cnt_h++;
break;
default:
break;
}
}
vector<long long> cnts = {cnt_m, cnt_a, cnt_r, cnt_c, cnt_h};
vector<int> acc;
cout << solve(0, acc, cnts) << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a[10];
long long sol(int i, int j, int k, int a[]) { return a[i] * a[j] * a[k]; }
int main() {
int N;
string s;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M')
a[0]++;
else if (s[0] == 'A')
a[1]++;
else if (s[0] == 'R')
a[2]++;
else if (s[0] == 'C')
a[3]++;
else if (s[0] == 'H')
a[4]++;
}
long long ans = 0;
ans += sol(0, 1, 2, a);
ans += sol(0, 1, 3, a);
ans += sol(0, 1, 4, a);
ans += sol(0, 2, 3, a);
ans += sol(0, 2, 4, a);
ans += sol(0, 3, 4, a);
ans += sol(1, 2, 3, a);
ans += sol(1, 2, 4, a);
ans += sol(1, 3, 4, a);
ans += sol(2, 3, 4, a);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> march(5, 0);
int n;
long long ans = 0;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
march[0]++;
} else if (s[0] == 'A') {
march[1]++;
} else if (s[0] == 'R') {
march[2]++;
} else if (s[0] == 'C') {
march[3]++;
} else if (s[0] == 'H') {
march[4]++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
string s = "MARCH";
int c[5] = {0};
for (int i = 0; i < (n); i++) {
string tmp;
cin >> tmp;
for (int j = 0; j < (n); j++) {
if (tmp[0] == s[j]) {
c[j]++;
}
}
}
long long anser = 0;
for (int i = 0; i < (3); i++) {
for (int j = i + 1; j < (5); j++) {
for (int k = j + 1; k < (5); k++) {
anser += c[i] * c[j] * c[k];
}
}
}
cout << anser << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m=0,a=0,r=0,c=0,h=0,sum=0;
cin>>n;
string s[n+1];
for(int i=1;i<=n;i++)
{
cin>>s[i];
switch(s[i][1])
{
case 'M':m++;break;
case 'A':a++;break;
case 'R':r++;break;
case 'C':c++;break;
case 'H':h++;break;
}
}
int a[6]={0,m,a,r,c,h};
for(int i=1;i<=3;i++)
for(int j=i+1;j<=4;j++)
for(int k=j+1;k<=5;k++)
{
sum+=a[i]*a[j]*a[k];
}
cout<<sum;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int s[100] = {0};
for (int i = 0; i < n; i++) {
string v;
cin >> v;
s[v[0]]++;
}
int ss[5] = {s['M'], s['A'], s['R'], s['C'], s['H']};
long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += ss[i] * ss[j] * ss[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string t[1000];
long long c[10];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t[i];
if (t[i][0] == 'M') c[0]++;
if (t[i][0] == 'A') c[1]++;
if (t[i][0] == 'R') c[2]++;
if (t[i][0] == 'C') c[3]++;
if (t[i][0] == 'H') c[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) ans += (c[i] * c[j] * c[k]);
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string tmp;
int num[5] = {};
int n;
char tmpm[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int x = 0; x < 5; x++) {
if (tmp[0] == tmpm[x]) {
num[x]++;
break;
}
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | #include <bits/stdc++.h>
using namespace std;
int N;
long long NM, NA, NR, NC, NH;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
char s[12];
scanf("%s", s);
if (s[0] == 'M')
NM += 1;
else if (s[0] == 'A')
NA += 1;
else if (s[0] == 'R')
NR += 1;
else if (s[0] == 'C')
NC += 1;
else if (s[0] == 'H')
NH += 1;
}
NM = (NM == 0) ? 1 : NM;
NA = (NA == 0) ? 1 : NA;
NR = (NR == 0) ? 1 : NR;
NC = (NC == 0) ? 1 : NC;
NH = (NH == 0) ? 1 : NH;
cout << NM * NA * NR * NC * NH << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main(void) {
long long N;
cin >> N;
string S;
vector<char> key(N);
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
cin >> S;
key.at(i) = S.at(0);
if (key.at(i) == 'M') {
m++;
}
if (key.at(i) == 'A') {
a++;
}
if (key.at(i) == 'R') {
r++;
}
if (key.at(i) == 'C') {
c++;
}
if (key.at(i) == 'H') {
h++;
}
}
long long ans = 0;
vector<int> count{m, a, r, c, h};
for (int d = 0; d < 10; d++) {
ans += count.at(P[d]) * count.at(Q[d]) * count.at(R[d]);
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int num, i = 0, p;
long long ans = 0, a[5] = {0};
cin >> num;
string s, march = "MARCH";
for (; i < num; i++) {
cin >> s;
p = march.find(s[0]);
a[p]++;
}
ans += a[0] * a[1] * (a[2] + a[3] + a[4]);
ans += a[2] * a[3] * (a[0] + a[1] + a[4]);
ans += a[0] * a[4] * (a[2] + a[3]);
ans += a[1] * a[2] * a[4];
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder
{
class Program
{
static void Main(string[] args)
{
var Instance = new Question();
Instance.Exec();
}
}
public class Question
{
public void Exec()
{
List<string> names = new List<string>();
long n = long.Parse(Console.ReadLine());
for (var i = 0; i < n; ++i) {
names.Add(Console.ReadLine());
}
Func<char, bool> checker = c => {
if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
return true;
} else {
return false;
}
};
Func<List<char>, bool> checker2 = c2 => {
bool ok = checker(c2[0]) && checker(c2[1]) && checker(c2[2]);
ok = ok && (c2[0] != c2[1] && c2[0] != c2[2] && c2[1] != c2[2]);
return ok;
};
int count = 0;
for (var i = 0; i < names.Count; ++i) {
for (var j = i + 1; j < names.Count; ++j) {
for (var k = j + 1; k < names.Count; ++k) {
List<char> chars = new List<char>() { names[i][0], names[j][0], names[k][0] };
if (checker2(chars)) {
++count;
}
}
}
}
Console.WriteLine($"{count}");
Console.ReadKey();
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string s = "MARCH";
int c[5] = {0, 0, 0, 0, 0};
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < 5; j++) {
if (t[0] == s[j]) {
c[j]++;
}
}
}
long long ans = 0L;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans = ans + c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N;
double M=0,A=0,R=0,C=0,H=0;
ArrayList<Integer> numlist = new ArrayList<>();
N = sc.nextInt();
for (int a = 0; a < N; a++) {
String name = sc.next();
if(name.indexOf('M')==0){
M++;
}
else if(name.indexOf('A')==0){
A++;
}
else if(name.indexOf('R')==0){
R++;
}
else if(name.indexOf('C')==0){
C++;
}
else if(name.indexOf('H')==0){
H++;
}
}
numlist.add(M);
numlist.add(A);
numlist.add(R);
numlist.add(C);
numlist.add(H);
double num =0;
for(int a=0;a<3;a++){
for(int b=a+1;b<4;b++){
for(int c=b+1;c<5;c++){
if(numlist.get(a)!=0&&numlist.get(b)!=0&&numlist.get(c)!=0)
num =+(numlist.get(a)*numlist.get(b)*numlist.get(c));
}
}
}
System.out.println(num);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int i, ans = 1, x = 0;
string name[10000];
cin >> i;
for (; i > 0; i--) {
cin >> name[i];
if (name[i][0] == 'M' || name[i][0] == 'A' || name[i][0] == 'R' ||
name[i][0] == 'C' || name[i][0] == 'H') {
x++;
}
}
for (; x > 3; x--) {
ans *= x;
}
ans /= 2;
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
int d[5] = {m, a, r, c, h};
int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
long long ans = 0;
for (int i = 0; i < 10; i++) {
ans += (d[x[i]] * d[y[i]] * d[z[i]]);
}
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string *str;
str = new string[N];
int number[5];
for (int i = 0; i < 5; i++) number[i] = 0;
for (int i = 0; i < N; i++) {
cin >> str[i];
if (str[i][0] == 'M')
number[0]++;
else if (str[i][0] == 'A')
number[1]++;
else if (str[i][0] == 'R')
number[2]++;
else if (str[i][0] == 'C')
number[3]++;
else if (str[i][0] == 'H')
number[4]++;
}
int p, q, r, s, t;
p = number[0];
q = number[1];
r = number[2];
s = number[3];
t = number[4];
long answer = (long)(p * (q * (r + s + t) + r * (s + t) + s * t) +
q * (r * (s + t) + s * t) + r * s * t);
cout << answer << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
int[][] perm = new int[10][3];
int ind;
public void solve(int testNumber, InputReader in, PrintWriter out) {
//generatePermutation(new int[]{0,1,2},3,3);
getCombination(new int[]{0, 1, 2, 3, 4}, 5, 3);
int n = in.i();
int[] d = new int[5];
for (int i = 0; i < n; i++) {
String s = in.s();
if (s.charAt(0) == 'M') d[0]++;
if (s.charAt(0) == 'A') d[1]++;
if (s.charAt(0) == 'R') d[2]++;
if (s.charAt(0) == 'C') d[3]++;
if (s.charAt(0) == 'H') d[4]++;
}
long ans = 0;
for (int i = 0; i < 10; i++) {
ans += d[perm[i][0]] * d[perm[i][1]] * d[perm[i][2]];
}
out.println(ans);
}
void getCombination(int[] a, int n, int r) {
int[] data = new int[n];
combinationUtil(a, n, r, 0, data, 0);
}
private void combinationUtil(int[] a, int n, int r, int index, int[] data, int i) {
if (index == r) {
perm[ind++] = Arrays.copyOf(data, r);
return;
}
if (i >= n) return;
data[index] = a[i];
combinationUtil(a, n, r, index + 1, data, i + 1);
combinationUtil(a, n, r, index, data, i + 1);
}
}
static class InputReader {
InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0;
public int ptrbuf = 0;
public InputReader(InputStream is) {
this.is = is;
}
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String s() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int i() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
int N;
std::cin >> N;
std::vector<int> vs(N);
char march[] = {'M', 'A', 'R', 'C', 'H'};
int marchNum[5] = {0};
for (int i = 0; i < N; i++) {
std::string str;
std::cin >> str;
for (int j = 0; j < 5; j++) {
if (str[0] == march[j]) marchNum[j]++;
}
}
long long comNum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
comNum += marchNum[i] * marchNum[j] * marchNum[k];
}
}
}
std::cout << comNum << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | function Main(input) {
input = input.split("\n")
var namesN = input[0]
var names = input.slice(1)
var nameInitialCounts = {}
for(var name of names) {
nameInitialCounts[name.charAt(0)]
= ++nameInitialCounts[name.charAt(0)] || 1;
}
var cases = k_combinations(["M", "A", "R", "C", "H"], 3)
var result = 0
for(var c of cases) {
result += (nameInitialCounts[c[0]] || 0) * (nameInitialCounts[c[1]] || 0) * (nameInitialCounts[c[2]] || 0)
}
console.log(JSON.stringify(cases) + " : " + result)
}
function k_combinations(set, k) {
var i, j, combs, head, tailcombs;
// There is no way to take e.g. sets of 5 elements from
// a set of 4.
if (k > set.length || k <= 0) {
return [];
}
// K-sized set has only one K-sized subset.
if (k == set.length) {
return [set];
}
// There is N 1-sized subsets in a N-sized set.
if (k == 1) {
combs = [];
for (i = 0; i < set.length; i++) {
combs.push([set[i]]);
}
return combs;
}
// Assert {1 < k < set.length}
// Algorithm description:
// To get k-combinations of a set, we want to join each element
// with all (k-1)-combinations of the other elements. The set of
// these k-sized sets would be the desired result. However, as we
// represent sets with lists, we need to take duplicates into
// account. To avoid producing duplicates and also unnecessary
// computing, we use the following approach: each element i
// divides the list into three: the preceding elements, the
// current element i, and the subsequent elements. For the first
// element, the list of preceding elements is empty. For element i,
// we compute the (k-1)-computations of the subsequent elements,
// join each with the element i, and store the joined to the set of
// computed k-combinations. We do not need to take the preceding
// elements into account, because they have already been the i:th
// element so they are already computed and stored. When the length
// of the subsequent list drops below (k-1), we cannot find any
// (k-1)-combs, hence the upper limit for the iteration:
combs = [];
for (i = 0; i < set.length - k + 1; i++) {
// head is a list that includes only our current element.
head = set.slice(i, i + 1);
// We take smaller combinations from the subsequent elements
tailcombs = k_combinations(set.slice(i + 1), k - 1);
// For each (k-1)-combination we join it with the current
// and store it to the set of k-combinations.
for (j = 0; j < tailcombs.length; j++) {
combs.push(head.concat(tailcombs[j]));
}
}
return combs;
}
//*この行以降は編集しないでください(標準入出力から一度に読み込み、Mainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8")); |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
input! {
n: usize,
s: [Chars; n]
}
let (mut m, mut a, mut r, mut c, mut h) = (0, 0, 0, 0, 0);
for i in 0..n {
if s[i][0] == 'M' {
m += 1
}
if s[i][0] == 'A' {
a += 1
}
if s[i][0] == 'R' {
r += 1;
}
if s[i][0] == 'C' {
c += 1;
}
if s[i][0] == 'H' {
h += 1;
}
}
let d = [m, a, r, c, h];
let p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
let q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
let r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
let mut ans = 0;
for i in 0..10 {
ans += d[p[i]] * d[q[i]] * d[r[i]];
}
println!("{}", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 999999999999999;
ll kaijo(ll n) {
if (n == 0) return 1;
return n * kaijo(n - 1);
}
int main() {
ll n;
cin >> n;
string m = "MARCH";
vector<ll> cnt(5);
vector<string> s(n);
map<char, bool> chek;
for (ll i = 0; i < n; ++i) {
cin >> s.at(i);
for (ll j = 0; j < 5; ++j) {
if (s.at(i).at(0) == m.at(j)) {
cnt.at(j)++;
chek[m.at(j)] = true;
}
}
}
ll num = chek.size();
if (num < 3) {
cout << 0 << endl;
return 0;
}
ll ans = kaijo(num) / kaijo(3) / kaijo(num - 3);
for (ll i = 0; i < 5; ++i) {
if (cnt.at(i) > 1) {
ans += kaijo(num - 1) / kaijo(2) / kaijo(num - 1 - 2);
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int names[5] = {};
for (int i = 0; i < N; i++) {
string name;
cin >> name;
if (name[0] == 'M') {
names[0]++;
} else if (name[0] == 'A') {
names[1]++;
} else if (name[0] == 'R') {
names[2]++;
} else if (name[0] == 'C') {
names[3]++;
} else if (name[0] == 'H') {
names[4]++;
}
}
long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
if (names[i] > 0 && names[j] > 0 && names[k] > 0) {
ans += names[i] * names[j] * names[k];
}
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long sum = 0;
vector<string> name;
string temp;
for (int i = 0; i < n; i++) {
cin >> temp;
name.push_back(temp);
}
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (auto& na : name) {
if (na[0] == 'M') {
m++;
} else if (na[0] == 'A') {
a++;
} else if (na[0] == 'R') {
r++;
} else if (na[0] == 'C') {
c++;
} else if (na[0] == 'H') {
h++;
}
}
sum += m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h;
sum += a * r * c + a * r * h + a * c * h;
sum += r * c * h;
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N;
int M=0,A=0,R=0,C=0,H=0;
ArrayList<Integer> numlist = new ArrayList<>();
N = sc.nextInt();
for (int a = 0; a < N; a++) {
String name = sc.next();
if(name.indexOf("M")==0){
M++;
}
else if(name.indexOf("A")==0){
A++;
}
else if(name.indexOf("R")==0){
R++;
}
else if(name.indexOf("C")==0){
C++;
}
else if(name.indexOf("H")==0){
H++;
}
}
numlist.add(M);
numlist.add(A);
numlist.add(R);
numlist.add(C);
numlist.add(H);
int num =0;
for(int a=0;a<3;a++){
for(int b=a+1;b<4;b++){
for(int c=b+1;c<5;c++){
if(numlist.get(a)!=0&&numlist.get(b)!=0&&numlist.get(c)!=0)
num = num+(numlist.get(a)*numlist.get(b)*numlist.get(c));
}
}
}
System.out.println(num);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char check[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
long long n;
cin >> n;
long long num[n];
fill(num, num + n, 0);
string tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int j = 0; j < 5; j++) {
if (tmp[0] == check[j]) num[j]++;
}
}
long long sum = 0;
for (int i = 0; i < (1 << 5); i++) {
bool alt[5];
long long hoge = 0;
for (int j = 0; j < 5; j++) alt[j] = ((i & (1 << j)) != 0);
for (int j = 0; j < 5; j++)
if (alt[j]) hoge++;
if (hoge != 3) continue;
hoge = 1;
for (int j = 0; j < 5; j++) {
if (alt[j]) hoge *= num[j];
}
sum += hoge;
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 1e5;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
int n;
cin >> n;
string s;
string F = "MARCH";
long long ans = 0;
int count[5] = {};
for (int i = 0; i < (n); i++) {
cin >> s;
for (int j = 0; j < (5); j++) {
if (s[0] == F[j]) {
count[j]++;
break;
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
s = [input() for _ in range(N)]
print(s)
Mx,Ax,Rx,Cx,Hx=0,0,0,0,0
for n in range(N):
if s[n][0] =="M":
Mx += 1
elif s[n][0] =="A":
Ax += 1
elif s[n][0] =="R":
Rx += 1
elif s[n][0] =="C":
Cx += 1
elif s[n][0] =="H":
Hx += 1
MAR = Mx * Ax * Rx
MAC = Mx * Ax * Cx
MAH = Mx * Ax * Hx
MRC = Mx * Rx * Cx
MRH = Mx * Rx * Hx
MCH = Mx * Cx * Hx
ARC = Ax * Rx * Cx
ARH = Ax * Rx * Hx
ACH = Ax * Cx * Hx
RCH = Rx * Cx * Hx
print(MAR+MAC+MAH+MRC+MRH+MCH+ARC+ARH+ACH+RCH) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = [input()[0] for i in range(N)]
B = {}
for c in S:
if c not in 'MARCH':
continue
B[c] = B.get(c, 0) + 1
A = sum(B.values())
ans = A*(A-1)*(A-2)//6
for c1 in B:
for c2 in B:
if not c1 < c2:
continue
ans -= B[c1] * (B[c1]-1) * B[c2] // 2
ans -= B[c2] * (B[c2]-1) * B[c1] // 2
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int MARCH[5] = {};
for (int i = 0; i < n; i++) {
cin >> s;
switch (s[0]) {
case 'M':
MARCH[0]++;
break;
case 'A':
MARCH[1]++;
break;
case 'R':
MARCH[2]++;
break;
case 'C':
MARCH[3]++;
break;
case 'H':
MARCH[4]++;
break;
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string MARCH = "MARCH";
cin.tie(0);
ios::sync_with_stdio(false);
int N;
string s[5];
long long c[5] = {0};
cin >> N;
for (int i = 0, i_len = (N); i < i_len; ++i) {
cin >> s[i];
for (int j = 0, j_len = (MARCH.length()); j < j_len; ++j) {
if (s[i][0] == MARCH[j]) {
c[j]++;
break;
}
}
}
long long ans = 0;
for (int i = 0, i_len = (5); i < i_len; ++i) {
for (int j = i + 1, j_len = (5); j < j_len; ++j) {
for (int k = j + 1, k_len = (5); k < k_len; ++k) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int M, A, R, C, H, I, N, G;
char s[15];
int main() {
cin >> N;
for (I = 0; I < N; ++I) {
scanf("%s", s);
switch (*s) {
case 65:
++A;
break;
case 67:
++C;
break;
case 72:
++H;
break;
case 77:
++M;
break;
case 82:
++R;
break;
}
}
G = M * (A * (R + C + H) + R * (C + H)) + A * (R * (C + H) + C * H) +
R * C * H;
cout << G << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
long long mod(long long val, long long m) {
long long res = val % m;
if (res < 0) res += m;
return res;
}
long long gcd(ll a, ll b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
long long lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll factorial(ll n) {
ll res = 1;
for (ll i = 1; i <= n; i++) {
res *= i;
}
return res;
}
int main() {
int n;
cin >> n;
vector<int> s(5, 0);
int p[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int r[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int i = 0; i < (n); i++) {
string tmp;
cin >> tmp;
if (tmp[0] == 'M') {
s[0]++;
}
if (tmp[0] == 'A') {
s[1]++;
}
if (tmp[0] == 'R') {
s[2]++;
}
if (tmp[0] == 'C') {
s[3]++;
}
if (tmp[0] == 'H') {
s[4]++;
}
}
ll ans = 0;
for (int i = 0; i < (10); i++) {
ans += s[p[i]] * s[q[i]] * s[r[i]];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
int N, zero = 0;
long long ans = 0;
int cnt[5];
char S[10001][11];
char march[] = {'M', 'A', 'R', 'C', 'H'};
int M[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%s", S[i]);
for (int j = 0; j < 5; j++) {
if (S[i][0] == march[j]) cnt[j]++;
}
}
for (int i = 0; i < 10; i++) {
ans += cnt[M[i]] * cnt[Q[i]] * cnt[R[i]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
string S;
long MARCH[5] = {0};
for (int i = 0; i < N; i++) {
cin >> S;
switch (S[0]) {
case 'M':
MARCH[0]++;
break;
case 'A':
MARCH[1]++;
break;
case 'R':
MARCH[2]++;
break;
case 'C':
MARCH[3]++;
break;
case 'H':
MARCH[4]++;
break;
}
}
int count = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
count += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int N = Integer.parseInt(sc.next());
String S[] = new String[N];
int num[] = new int[5];
Arrays.fill(num, 0);
for(int i = 0; i < N; i++) {
S[i] = sc.next();
if(S[i].substring(0, 1).equals("M")) {
num[0]++;
}
if(S[i].substring(0, 1).equals("A")) {
num[1]++;
}
if(S[i].substring(0, 1).equals("R")) {
num[2]++;
}
if(S[i].substring(0, 1).equals("C")) {
num[3]++;
}
if(S[i].substring(0, 1).equals("H")) {
num[4]++;
}
}
long ans = 0;
int P[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for(int i = 0; i < 10; i++) {
ans += num[P[i]] * num[Q[i]] * num[R[i]];
}
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
name=[]
for i in range(N):
name.append(input())
M=0
A=0
R=0
C=0
H=0
letters=['M','A','R','C','H']
for i in range(N):
for j in letters:
if N[i][0]==j:
if j=='M':
M+=1
elif j=='A':
A+=1
elif j=='R':
R+=1
elif j=='C':
C+=1
elif j=='H':
H+=1
kazu=!
if M==0:
M+=1
if A==0:
A+=1
if C==0:
C+=1
if R==0:
R+=1
if H==0:
H+=1
print(M*A*C*R*H) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> v(5, 0);
for (ll i = 0; i < ll(N); i++) {
string s;
cin >> s;
if (s[0] == 'M') v[0]++;
if (s[0] == 'A') v[1]++;
if (s[0] == 'R') v[2]++;
if (s[0] == 'C') v[3]++;
if (s[0] == 'H') v[4]++;
}
ll sum = 0;
for (ll i = 0; i <= ll(4); i++)
for (ll j = i + 1; j <= ll(4); j++)
for (ll k = j + 1; k <= ll(4); k++) sum += v[i] * v[j] * v[k];
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long i, j, n, ans;
int m = 0, a = 0, r = 0, c = 0, h = 0;
string s[100001];
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n; i++) {
if (s[i][0] == 'M') {
m++;
}
if (s[i][0] == 'A') {
a++;
}
if (s[i][0] == 'R') {
r++;
}
if (s[i][0] == 'C') {
c++;
}
if (s[i][0] == 'H') {
h++;
}
}
ans = (m * a * r) + (m * a * c) + (m * a * h) + (m * r * c) + (m * r * h) +
(m * c * h) + (a * r * c) + (a * r * h) + (a * c * h) + (r * c * h);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
num = [0,0,0,0,0]
for i in range(N):
name = list(input())
if name[0] == "M":
num[0] = num[0]+1
elif name[0] == "A":
num[1] = num[1]+1
elif name[0] == "R":
num[2] = num[2]+1
elif name[0] == "C":
num[3] = num[3]+1
elif name[0] == "H":
num[4] = num[4]+1
for n in range(len(num)):
if num[n] == 0:
num[n] = 1
out = num[0] * num[1] *num[2] * num[3] * num[4]
print(out) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll INF = (1LL<<60);
const int INFi = (1<<29);
/*素数判定*/
bool is_prime(ll n){
if(n==1) return false;
for(ll i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}
/*約数列挙*/
vll enum_divisors(ll n){
vll l;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
l.push_back(i);
if(n/i != i) l.push_back(n/i);
}
}
sort(all(l));
return l;
}
/*素因数分解*/
vector<P> prime_factorize(ll n){
vector<P> l;
for(ll i=2;i*i<=n;i++){
if(n%i!=0) continue;
ll e = 0;
while(n%i==0){
e++;
n /= i;
}
l.push_back({i, e});
}
if(n!=1) l.push_back({n, 1});
return l;
}
/*階乗*/
ll factorial(ll n){
ll ret;
for(ret=1;n>0;n--){
ret *= n;
}
return ret;
}
/*最小公倍数*/
ll lcm(ll a, ll b){
return a*b/__gcd(a,b);
}
/*最大公約数*/
ll gcd(ll a, ll b){
return __gcd(a,b);
}
#define C(n, r) factorial((n))/(factorial((r))*factorial((n)-(r)))
int main(){
ll n; cin >> n;
map<char, ll> mp;
string in;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
rep(i, n){
cin >> in;
mp[in[0]]++;
}
ll sum = mp['M'] + mp['A'] + mp['R'] + mp['C'] + mp['H'];
ll ans = C(sum, 3);
ll sub = 0;
for(auto x:{'M', 'A', 'R', 'C', 'H'}){
if(mp[x]>1){
sub += C(mp[x], 2)*(sum-2);
}
}
cout << ans-sub << endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n=int(input())
s=[input() for i in range(n)]
dic={}
for i in s:
if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
if i[0] in dic:
dic[i[0]]+=1
else:
dic[i[0]]=1
if len(dic)<3:
ans=0
else:
if len(dic)==3:
ans = 1
for i in dic.values():
ans *=i
elif len(dic)==4:
li4 = []
for i in dic.values():
li4.append(i)
ans = li4[0]*li4[1]*li4[2]+li4[0]*li4[1]*li4[3]+li4[0]*li4[2]*li4[3]+li4[1]*li4[2]*li4[3]
else:
li4 = []
for i in dic.values():
li5.append(i)
ans =li5[0]*li5[1]*li5[2]+li5[0]*li5[1]*li5[3]+li5[0]*li5[1]*li5[4]+li5[0]*li5[2]*li5[3]+li5[0]*li5[2]*li5[4]+li5[0]*li5[3]*li5[4]+li5[1]*li5[2]*li5[3]+li5[1]*li5[2]*li5[4]+li5[1]*li5[3]*li5[4]+li5[2]*li5[3]*li5[4]
print(ans)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
names_dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
FIRST = ('M', 'A', 'R', 'C', 'H')
for _ in range(N):
nams = input()
if name[0] in FIRST:
names_dic[name[0]] += 1
ans = 0
for i in range(5):
for j in range(i+1, 5):
for k in range(j+1, 5):
ans += names_dic[FIRST[i]]*names_dic[FIRST[j]]*names_dic[FIRST[k]]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
char a[20];
int sum[10] = {0};
int n;
int flag = 1;
double ans;
int main() {
int cnt = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", a);
int len = strlen(a);
if (a[0] == 'M') sum[1]++;
if (a[0] == 'A') sum[2]++;
if (a[0] == 'R') sum[3]++;
if (a[0] == 'C') sum[4]++;
if (a[0] == 'H') sum[5]++;
}
if (n < 3) flag = 0;
sort(sum + 1, sum + 1 + 5);
for (int i = 1; i <= 5; i++) {
if (sum[i] == 0) cnt++;
if (cnt >= 3) {
flag = 0;
break;
}
}
for (int i = 1; i <= n; i++) {
if (cnt == 2) {
ans = sum[3] * sum[4] * sum[5];
}
if (cnt == 1) {
ans = sum[2] * sum[3] * (sum[4] + sum[5]) + sum[2] * sum[4] * sum[5] +
sum[3] * sum[4] * sum[5];
}
if (cnt == 0) {
ans = sum[1] * sum[2] * (sum[3] + sum[4] + sum[5]) +
sum[1] * sum[3] * (sum[4] + sum[5]) + sum[1] * sum[4] * sum[5] +
sum[2] * sum[3] * (sum[4] + sum[5]) + sum[2] * sum[4] * sum[5] +
sum[3] * sum[4] * sum[5];
}
}
if (flag == 1) printf("%.0lf\n", ans);
if (flag == 0) printf("0\n");
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Asakatsu20200320C.Input;
namespace Asakatsu20200320C
{
static class Input
{
/// <summary>
/// 1行の入力をTに応じてリストに変換する関数を返す
/// </summary>
static Func<string, List<T>> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList();
/// <summary>
/// 1行の入力をTに応じて変換する関数を返す
/// </summary>
static Func<string, T> Convert<T>()
{
Type t = typeof(T);
if (t == typeof(string)) return _ => (T) (object) _;
if (t == typeof(int)) return _ => (T) (object) int.Parse(_);
if (t == typeof(long)) return _ => (T) (object) long.Parse(_);
if (t == typeof(double)) return _ => (T) (object) double.Parse(_);
if (t == typeof(List<string>)) return _ => (T) (object) Cast<string>()(_);
if (t == typeof(List<int>)) return _ => (T) (object) Cast<int>()(_);
if (t == typeof(List<long>)) return _ => (T) (object) Cast<long>()(_);
if (t == typeof(List<double>)) return _ => (T) (object) Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
static T Convert<T>(string s) => Convert<T>()(s);
static string String() => Console.ReadLine();
static List<string> String(long rowNumber) => new bool[rowNumber].Select(_ => String()).ToList();
/// <summary>
/// 1行の値の入力
/// </summary>
public static void Cin<T>(out T a) => a = Convert<List<T>>(String())[0];
public static void Cin<T1, T2>(out T1 a1, out T2 a2)
{
var v = Convert<List<string>>(String());
a1 = Convert<T1>(v[0]);
a2 = Convert<T2>(v[1]);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3)
{
var v = Convert<List<string>>(String());
a1 = Convert<T1>(v[0]);
a2 = Convert<T2>(v[1]);
a3 = Convert<T3>(v[2]);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3, out T4 a4)
{
var v = Convert<List<string>>(String());
a1 = Convert<T1>(v[0]);
a2 = Convert<T2>(v[1]);
a3 = Convert<T3>(v[2]);
a4 = Convert<T4>(v[3]);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5)
{
var v = Convert<List<string>>(String());
a1 = Convert<T1>(v[0]);
a2 = Convert<T2>(v[1]);
a3 = Convert<T3>(v[2]);
a4 = Convert<T4>(v[3]);
a5 = Convert<T5>(v[4]);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5, out T6 a6)
{
var v = Convert<List<string>>(String());
a1 = Convert<T1>(v[0]);
a2 = Convert<T2>(v[1]);
a3 = Convert<T3>(v[2]);
a4 = Convert<T4>(v[3]);
a5 = Convert<T5>(v[4]);
a6 = Convert<T6>(v[5]);
}
/// <summary>
/// 複数行の値の入力
/// </summary>
public static void Cin<T>(long n, out List<T> l) => l = String(n).Select(Convert<T>()).ToList();
public static void Cin<T1, T2>(long n, out List<T1> l1, out List<T2> l2)
{
l1 = new List<T1>();
l2 = new List<T2>();
foreach (List<string> l in String(n).Select(Convert<List<string>>()))
{
l1.Add(Convert<T1>(l[0]));
l2.Add(Convert<T2>(l[1]));
}
}
public static void Cin<T1, T2, T3>(long n, out List<T1> l1, out List<T2> l2, out List<T3> l3)
{
l1 = new List<T1>();
l2 = new List<T2>();
l3 = new List<T3>();
foreach (List<string> l in String(n).Select(Convert<List<string>>()))
{
l1.Add(Convert<T1>(l[0]));
l2.Add(Convert<T2>(l[1]));
l3.Add(Convert<T3>(l[2]));
}
}
public static void Cin<T1, T2, T3, T4>(long n, out List<T1> l1, out List<T2> l2, out List<T3> l3,
out List<T4> l4)
{
l1 = new List<T1>();
l2 = new List<T2>();
l3 = new List<T3>();
l4 = new List<T4>();
foreach (List<string> l in String(n).Select(Convert<List<string>>()))
{
l1.Add(Convert<T1>(l[0]));
l2.Add(Convert<T2>(l[1]));
l3.Add(Convert<T3>(l[2]));
l4.Add(Convert<T4>(l[3]));
}
}
/// <summary>
/// 1行に書かれた複数の値の入力
/// </summary>
public static void Cin<T>(out List<T> lArr) => lArr = Convert<List<T>>(String());
/// <summary>
/// h行の行列の入力
/// </summary>
public static void Cin<T>(long h, out List<List<T>> map) => map = String(h).Select(Convert<List<T>>()).ToList();
}
class Program
{
public static void Main(string[] args)
{
StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug()
{
new Solver().Solve();
}
}
class Solver
{
private long N;
private List<string> S;
public void Solve()
{
Cin(out N);
Cin(N, out S);
Dictionary<char, int> cnt = new Dictionary<char, int>();
for (int i = 0; i < 26; i++)
{
cnt.Add((char) ('A' + i), 0);
}
for (int i = 0; i < N; i++)
{
cnt[S[i][0]]++;
}
long ans = 0;
string[] pattern =
{
"MAR",
"MAC",
"MAH",
"MRC",
"MRH",
"MCH",
"ARC",
"ARH",
"ACH",
"RCH",
};
foreach (string p in pattern)
{
ans += cnt[p[0]] * cnt[p[1]] * cnt[p[2]];
}
Console.WriteLine(ans);
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long n, m;
long long quick_mod(long long a, long long b) {
long long ans = 1;
a %= MOD;
while (b) {
if (b & 1) {
ans = ans * a % MOD;
b--;
}
b >>= 1;
a = a * a % MOD;
}
return ans;
}
long long C(long long n, long long m) {
if (m > n) return 0;
long long ans = 1;
for (int i = 1; i <= m; i++) {
long long a = (n + i - m) % MOD;
long long b = i % MOD;
ans = ans * (a * quick_mod(b, MOD - 2) % MOD) % MOD;
}
return ans;
}
long long Lucas(long long n, long long m) {
if (m == 0) return 1;
return C(n % MOD, m % MOD) * Lucas(n / MOD, m / MOD) % MOD;
}
int main() {
int n;
string s[100005];
while (scanf("%d", &n) != EOF) {
int m1 = 0, a1 = 0, r1 = 0, c1 = 0, h1 = 0;
int m2 = 0, a2 = 0, r2 = 0, c2 = 0, h2 = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'm') {
m1 = 1;
m2++;
} else if (s[i][0] == 'M') {
m1 = 1;
m2++;
} else if (s[i][0] == 'A') {
a1 = 1;
a2++;
} else if (s[i][0] == 'R') {
r1 = 1;
r2++;
} else if (s[i][0] == 'C') {
c1 = 1;
c2++;
} else if (s[i][0] == 'H') {
h1 = 1;
h2++;
}
}
int sum1 = 0, sum2 = 0, sum3 = 0;
if (m1 == 1 && m2 == 1)
sum1++;
else if (m1 == 1 && m2 > 1) {
sum2 += m2;
sum3++;
}
if (a1 == 1 && a2 == 1)
sum1++;
else if (a1 == 1 && a2 > 1) {
sum2 += a2;
sum3++;
}
if (r1 == 1 && r2 == 1)
sum1++;
else if (r1 == 1 && r2 > 1) {
sum2 += r2;
sum3++;
}
if (c1 == 1 && c2 == 1)
sum1++;
else if (c1 == 1 && c2 > 1) {
sum2 += c2;
sum3++;
}
if (h1 == 1 && h2 == 1)
sum1++;
else if (h1 == 1 && h2 > 1) {
sum2 += h2;
sum3++;
}
long long ans1 = Lucas(sum1, 2) * sum2;
long long ans2 = 0, ans3 = 0;
if (sum1 >= 3) {
ans2 = Lucas(sum1, 3);
}
if (sum3 >= 3) {
ans3 = m2 * a2 * r2 * c2 * h2;
}
long long ans = ans1 + ans2 + ans3;
printf("%lld\n", ans);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, set;
char head;
int node[5] = {0, 0, 0, 0, 0};
string S;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
head = S[0];
if (head == 'M') node[0] = 1;
if (head == 'A') node[1] += 1;
if (head == 'R') node[2] += 1;
if (head == 'C') node[3] += 1;
if (head == 'H') node[4] += 1;
}
set = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; j > k; k++) {
set += node[i] * node[j] * node[k];
}
}
}
cout << set << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | # -*- coding: utf-8 -*-
N = int(input())
lines = []
for i in range(N):
lines.append(input())
def recl(persons, tmp, count):
if len(tmp) == 3 and len(list(set(tmp))) == 3:
count[0] += 1
return
for idx, person in enumerate(persons):
if len(persons) < 1:break
recl( persons[idx+1:len(persons)] , tmp + [person], count)
count = [0]
recl(list(filter(lambda a:a in ["M","A","R","C","H"], map(lambda a:a[0] ,lines))) ,[] , count)
print(count[0]) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
int main() {
int n;
cin >> n;
string f;
int m[100] = {0};
for (int i = 0; i < n; i++) {
cin >> f;
if (f[0] == 'M') m[0]++;
if (f[0] == 'A') m[1]++;
if (f[0] == 'R') m[2]++;
if (f[0] == 'C') m[3]++;
if (f[0] == 'H') m[4]++;
}
long long ans = 0;
ans += m[0] * m[1] * m[2];
ans += m[0] * m[1] * m[3];
ans += m[0] * m[1] * m[4];
ans += m[0] * m[2] * m[3];
ans += m[0] * m[2] * m[4];
ans += m[0] * m[3] * m[4];
ans += m[1] * m[2] * m[3];
ans += m[1] * m[2] * m[4];
ans += m[1] * m[3] * m[4];
ans += m[2] * m[3] * m[4];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
ll ans = 0;
map<char, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
mp[s[0]]++;
}
string str = "MARCH";
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j <= 4; j++) {
for (int k = j + 1; k <= 5; k++) {
ans += mp[str[i]] * mp[str[j]] * mp[str[k]];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, r;
long long ans;
string s;
map<char, int> m;
long long sum(char a, char b, char c) { return m[a] * m[b] * m[c]; }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
m[s[0]]++;
}
ans += sum('M', 'A', 'R');
ans += sum('M', 'A', 'C');
ans += sum('M', 'A', 'H');
ans += sum('M', 'R', 'C');
ans += sum('M', 'R', 'H');
ans += sum('M', 'C', 'H');
ans += sum('A', 'R', 'C');
ans += sum('A', 'R', 'H');
ans += sum('A', 'C', 'H');
ans += sum('R', 'C', 'H');
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> S(5);
for (int i = 0; i < (N); ++i) {
string s;
cin >> s;
if (s[0] == 'M') {
S[0]++;
} else if (s[0] == 'A') {
S[1]++;
} else if (s[0] == 'R') {
S[2]++;
} else if (s[0] == 'C') {
S[3]++;
} else if (s[0] == 'H') {
S[4]++;
}
}
long long ans = (S[0] * S[1] * (S[2] + S[3] + S[4])) +
(S[0] * S[2] * (S[3] + S[4])) + (S[0] * S[3] * S[4]);
ans += (S[1] * S[2] * (S[3] + S[4])) + (S[1] * S[3] * S[4]) +
(S[2] * S[3] * S[4]);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
#define size N
string s[size];
for (int i = 0; i < N; i++) {
cin >> s[i];
}
int march[5];
for (int i = 0; i < 5; i++) {
march[i] = 0;
}
for (int i = 0; i < N; i++) {
switch(s[i][0]) {
case 'M': march[0]++; break;
case 'A': march[1]++; break;
case 'R': march[2]++; break;
case 'C': march[3]++; break;
case 'H': march[4]++; break;
default: break;
}
}
int ans = 0;
int p[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2}
int q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3}
int r[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4}
for (int i = 0; i < 10) {
ans += march[p[i]] * march[q[i]] * march[r[i]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
long long int cnt[5];
for (int i = (0); i < (5); ++i) cnt[i] = 0;
string S;
char march[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = (0); i < (N); ++i) {
cin >> S;
for (int i = (0); i < (5); ++i)
if (S[0] == march[i]) cnt[i]++;
}
long long int ans = 0;
int comb = (1 << 3) - 1;
while (comb < 1 << 5) {
long long int tmp = 1;
for (int i = (0); i < (5); ++i)
if (comb & (1 << i)) tmp *= cnt[i];
int x = comb & -comb, y = comb + x;
comb = (((comb & ~y) / x) >> 1) | y;
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s[] = new String [n];
for(int i = 0;i < n;i++){
s[i] = sc.next();
}
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for(int i = 0;i < n;i++){
if(s[i].indexOf('M') == 0){
m++;
}
if(s[i].indexOf('A') == 0){
a++;
}
if(s[i].indexOf('R') == 0){
r++;
}
if(s[i].indexOf('C') == 0){
c++;
}
if(s[i].indexOf('H') == 0){
h++;
}
}
long sum = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
System.out.println(sum);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
int x;
string s;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') {
m++;
} else if (s[0] == 'A') {
a++;
} else if (s[0] == 'R') {
r++;
} else if (s[0] == 'C') {
c++;
} else if (s[0] == 'H') {
h++;
}
}
x = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << x << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
unsigned long long d[5];
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') d[0]++;
if (s[0] == 'A') d[1]++;
if (s[0] == 'R') d[2]++;
if (s[0] == 'C') d[3]++;
if (s[0] == 'H') d[4]++;
}
unsigned long long sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += d[i] * d[j] * d[k];
}
}
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int D[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
if (s[0] == 'M') D[0]++;
if (s[0] == 'A') D[1]++;
if (s[0] == 'R') D[2]++;
if (s[0] == 'C') D[3]++;
if (s[0] == 'H') D[4]++;
}
vector<int> v(5);
for (int i = 0; i < 5; ++i) v[i] = i;
int res = 0;
do {
res += D[v[0]] * D[v[1]] * D[v[2]] / 12;
} while (next_permutation(v.begin(), v.end()));
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = unsigned long long;
int main() {
int n, c[26] = {0};
char s[11];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
c[s[0] - 'A']++;
}
int comp[5];
comp[0] = c['M' - 'A'];
comp[1] = c['A' - 'A'];
comp[2] = c['R' - 'A'];
comp[3] = c['C' - 'A'];
comp[4] = c['H' - 'A'];
ll total = 0;
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++) total += comp[i] * comp[j] * comp[k];
printf("%llu\n", total);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<char, int> m;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
m[s[0]] += 1;
}
if (!m.size()) {
cout << "0" << endl;
return 0;
}
string a = "MARCH";
int64_t count = 0;
for (int i = 0; i < m.size(); ++i)
for (int j = i + 1; j < m.size(); ++j)
for (int k = j + 1; k < m.size(); ++k)
count += m[a[i]] * m[a[j]] * m[a[k]];
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | var
n,cnt_m,cnt_a,cnt_r,cnt_c,cnt_h,ans,i: Longint;
s: String;
begin
readln(n);
for i := 1 to n do
begin
readln(s);
if s[1]='M' then
begin
inc(cnt_m);
end
else if s[1]='A' then
begin
inc(cnt_a);
end
else if s[1]='R' then
begin
inc(cnt_r);
end
else if s[1]='C' then
begin
inc(cnt_c);
end
else if s[1]='H' then
begin
inc(cnt_h);
end;
end;
ans:=cnt_m*cnt_a*(cnt_r+cnt_c+cnt_h)+cnt_m*cnt_r*(cnt_c+cnt_h)+
cnt_m*cnt_c*cnt_h+cnt_a*cnt_r*(cnt_c+cnt_h)+cnt_a*cnt_c*cnt_h+
cnt_r*cnt_c*cnt_h;
writeln(ans);
end. |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long countn[5] = {0, 0, 0, 0, 0};
int N;
void read() {
char S[15];
scanf("%s", S);
if (S[0] == 'M') countn[0]++;
if (S[0] == 'A') countn[1]++;
if (S[0] == 'C') countn[2]++;
if (S[0] == 'R') countn[3]++;
if (S[0] == 'H') countn[4]++;
}
int main() {
int i, j, k, ans = 0;
scanf("%d", &N);
for (i = 0; i < N; i++) read();
for (i = 0; i <= 2; i++) {
for (j = i + 1; j <= 3; j++) {
for (k = j + 1; k <= 4; k++) {
ans += countn[i] * countn[j] * countn[k];
}
}
}
printf("%d\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
int m=0,a=0,r=0,c=0,h=0;
for(int i=0;i<N;i++){
string name;
cin>>name;
std::string cap=name.at(0);
if(cap=="M"){m++;}
else if(cap=="A"){a++;}
else if(cap=="R"){r++;}
else if(cap=="C"){c++;}
else if(cap=="H"){h++;}
else{continue;}
}
int sum=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
cout<<sum<<endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int h[5];
int main() {
int n, num = 0;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') h[0]++;
if (s[i][0] == 'A') h[1]++;
if (s[i][0] == 'R') h[2]++;
if (s[i][0] == 'C') h[3]++;
if (s[i][0] == 'H') h[4]++;
}
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++) num += h[i] * h[j] * h[k];
cout << num << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> str(N);
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int64_t i = 0; i < N; i++) {
cin >> str.at(i);
}
for (int64_t i = 0; i < N; i++) {
if (str.at(i).at(0) == 'M') {
M++;
} else if (str.at(i).at(0) == 'A') {
A++;
} else if (str.at(i).at(0) == 'R') {
R++;
} else if (str.at(i).at(0) == 'C') {
C++;
} else if (str.at(i).at(0) == 'H') {
H++;
}
}
int count = 0;
count = M + A + R + C + H;
cout << (count) * (count - 1) * (count - 2) / 6 << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;
using p = pair<char, ll>;
int n, m;
int main() {
cin >> n;
auto s = map<string, int>();
for (int i = 0; i < n; i++) {
string ss;
cin >> ss;
if (s.find(ss) != s.end()) {
s[ss]++;
} else {
s[ss] = 0;
}
}
auto m = vector<ll>(5, 0);
for (auto i : s) {
if (i.second != 0) continue;
if (i.first[0] == 'M') {
m[0]++;
} else if (i.first[0] == 'A') {
m[1]++;
} else if (i.first[0] == 'R') {
m[2]++;
} else if (i.first[0] == 'C') {
m[3]++;
} else if (i.first[0] == 'H') {
m[4]++;
}
}
s.clear();
auto _max = 0;
if (m[0] != 0 && m[1] != 0 && m[2] != 0) {
_max += m[0] * m[1] * m[2];
}
if (m[0] != 0 && m[1] != 0 && m[3] != 0) {
_max += m[0] * m[1] * m[3];
}
if (m[0] != 0 && m[1] != 0 && m[4] != 0) {
_max += m[0] * m[1] * m[4];
}
if (m[0] != 0 && m[2] != 0 && m[3] != 0) {
_max += m[0] * m[2] * m[3];
}
if (m[0] != 0 && m[2] != 0 && m[4] != 0) {
_max += m[0] * m[2] * m[4];
}
if (m[0] != 0 && m[3] != 0 && m[4] != 0) {
_max += m[0] * m[3] * m[4];
}
if (m[1] != 0 && m[2] != 0 && m[3] != 0) {
_max += m[1] * m[2] * m[3];
}
if (m[1] != 0 && m[2] != 0 && m[4] != 0) {
_max += m[1] * m[2] * m[4];
}
if (m[1] != 0 && m[3] != 0 && m[4] != 0) {
_max += m[1] * m[3] * m[4];
}
if (m[2] != 0 && m[3] != 0 && m[4] != 0) {
_max += m[2] * m[3] * m[4];
}
cout << _max;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<char, int> m;
for (int i = 0; i < N; ++i) {
string S;
cin >> S;
++m[S[0]];
}
long long ans = 0;
const string F = "MARCH";
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += m[F[i]] * m[F[j]] * m[F[k]];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 5;
char a[MaxN];
long long vis[200];
long long p[200];
void Check(char x) {
if (x == 'M')
vis[x]++;
else if (x == 'A')
vis[x]++;
else if (x == 'R')
vis[x]++;
else if (x == 'C')
vis[x]++;
else if (x == 'H')
vis[x]++;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf(" %s", &a);
Check(a[0]);
}
int t = 0;
for (char i = 'A'; i <= 'Z'; i++) {
if (vis[i]) t++;
}
int cnt = 0;
for (char i = 'A'; i <= 'Z'; i++)
if (vis[i]) p[++cnt] = vis[i];
long long ans = p[1] * p[2];
long long sum = ans * p[3] + ans * p[4] + ans * p[5];
ans = p[1] * p[3];
sum = sum + ans * p[4] + ans * p[5];
ans = p[2] * p[3];
sum = sum + ans * p[4] + sum * p[5];
sum = sum + p[2] * p[4] * p[5] + p[3] * p[4] * p[5] + p[1] * p[4] * p[5];
printf("%lld\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b = 0, e = 0;
string s;
cin >> a;
int test[5] = {0};
for (int h = 1; h <= a; h++) {
cin >> s;
if (s[0] == 'M') {
test[0]++;
}
if (s[0] == 'A') {
test[1]++;
}
if (s[0] == 'R') {
test[2]++;
}
if (s[0] == 'C') {
test[3]++;
}
if (s[0] == 'H') {
test[4]++;
}
}
for (int s = 0; s < 4; s++) {
for (int t = s + 1; t < 5; t++) {
if (test[t] > test[s]) {
int hjk = test[t];
test[t] = test[s];
test[s] = hjk;
}
}
}
for (int h = 0; h < 5; h++) {
if (test[h] == 0) {
b++;
}
}
if (b >= 3) {
cout << '0' << endl;
} else if (b == 2) {
cout << test[0] * test[1] * test[2] << endl;
} else if (b == 1) {
e += test[0] * test[1] * test[2];
e += test[0] * test[1] * test[3];
e += test[0] * test[2] * test[3];
e += test[1] * test[2] * test[3];
cout << e << endl;
} else {
e += test[0] * test[1] * test[2];
e += test[0] * test[1] * test[3];
e += test[0] * test[2] * test[3];
e += test[1] * test[2] * test[3];
e += test[0] * test[1] * test[4];
e += test[0] * test[2] * test[4];
e += test[0] * test[3] * test[4];
e += test[1] * test[2] * test[4];
e += test[1] * test[3] * test[4];
e += test[2] * test[3] * test[4];
cout << e << endl;
}
cin >> e;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int main(){
ll n;
cin>>n;
ll o=1;
int nm[5];
rep(i,5){nm[i]=0;}
for(int i=0;i<n;i++){
string s;
cin>>s;
if(s[0]=='M'){
nm[0]++;
}else if(s[0]=='A'){
nm[1]++;
}else if(s[0]=='R'){
nm[2]++;
}else if(s[0]=='C'){
nm[3]++;
}else if(s[0]=='H'){
nm[4]++;
}
}
int kazu=0;
rep(i,5){if(nm[i]!=0)kazu++;}
if(kazu<=2){cout<<0<<endl;return 0;}
ll ans=0;
vector<int> v;
if(kazu==3){
rep(i,5){
if(nm[i]!=0){
v.push_back(nm[i]);
}
}
ans+=v[0]*v[1]*v[2];
}
if(kazu==4){
rep(i,5){
if(nm[i]!=0){
v.push_back(nm[i]);
}
}
ans+=v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[2]*v[3]+v[1]*v[2]*v[3];
}
if(kazu==5){
rep(i,5){
if(nm[i]!=0){
v.push_back(nm[i]);
}
}
ans+=v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[1]*v[4]+v[0]*v[2]*v[3]+v[0]*v[2]*v[4]+v[0]*v[3]*[4]+v[1]*v[2]*v[3]+v[1]*v[2]*v[4]+v[1]*v[3]*v[4]+v[2]*v[3]*v[4];
}
cout<<ans<<endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
march = ['M','A','R','C','H']
dic = {}
for i in range(n):
s = str(input())
if s[0] in march:
dic.setdefault(s[0],0)
dic[s[0]] += 1
#print(dic)
ans = 0
if len(dic) in [3,4,5]:
vl = list(dic.values())
print(vl)
for i in range(len(vl)-2):
for j in range(i+1,len(vl)-1):
for k in range(j+1,len(vl)):
#print(vl[i],vl[j],vl[k])
ans += vl[i]*vl[j]*vl[k]
print(ans)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s.at(i);
}
vector<int> count(6);
for (int i = 0; i < n; i++) {
if (s.at(i).at(0) == 'M') count.at(1)++;
if (s.at(i).at(0) == 'A') count.at(2)++;
if (s.at(i).at(0) == 'R') count.at(3)++;
if (s.at(i).at(0) == 'C') count.at(4)++;
if (s.at(i).at(0) == 'H') count.at(5)++;
}
for (int i = 1; i < 6; i++) {
count.at(0) += count.at(i);
}
int num = 0, ans = 0;
for (int i = 1; i < 6; i++) {
num += (count.at(i) * (count.at(i) - 1) / 2) * (count.at(0) - count.at(i)) +
(count.at(i) * (count.at(i) - 1) * (count.at(i) - 2) / 6);
}
ans += (count.at(0) * (count.at(0) - 1) * (count.at(0) - 2) / 6) - num;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string name;
map<char, int> mp;
cin >> n;
char cc[] = {'M', 'A', 'R', 'C', 'H'};
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
for (int i = 0; i < n; i++) {
cin >> name;
if (name[0] == 'M' || name[0] == 'A' || name[0] == 'R' || name[0] == 'C' ||
name[0] == 'H') {
mp[name[0]]++;
}
}
long long sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
int a = mp[cc[i]] * mp[cc[j]] * mp[cc[k]];
sum += a;
}
}
}
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int n;
long long head[5] = {};
long long ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M') {
head[0]++;
} else if (str[0] == 'A') {
head[1]++;
} else if (str[0] == 'R') {
head[2]++;
} else if (str[0] == 'C') {
head[3]++;
} else if (str[0] == 'H') {
head[4]++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
int temp = 1;
for (int k = 0; k < 5; k++) {
if (k != i && k != j) {
temp *= head[k];
}
}
ans += temp;
}
}
cout << ans << endl;
return (0);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int m, a, r, c, h;
int main(void) {
int N;
long long int ans;
cin >> N;
string S[N];
char s[N];
for (int i = 0; i < N; i++) {
cin >> S[i];
s[i] = S[i][0];
if (s[i] == 'M') {
m++;
}
if (s[i] == 'A') {
a++;
}
if (s[i] == 'R') {
r++;
}
if (s[i] == 'C') {
c++;
}
if (s[i] == 'H') {
h++;
}
}
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long N;
cin >> N;
map<char, ll> S;
for (size_t i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
S[s[0]]++;
}
ll comb = 0;
if (S.size() < 3)
cout << 0 << endl;
else {
cerr << S.size() << endl;
ll Ssize = S.size();
vector<char> march = {'M', 'A', 'R', 'C', 'H'};
for (ll i = 0; i < march.size(); i++) {
for (ll j = i + 1; j < march.size(); j++) {
for (ll k = j + 1; k < march.size(); k++) {
comb += S[march[i]] * S[march[j]] * S[march[k]];
}
}
}
}
cout << comb << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
int n;
cin >> n;
int march[5] = {};
for (int i = 0; i < n; i++) {
string a;
cin >> a;
if (a[0] == 'M') march[0]++;
if (a[0] == 'A') march[1]++;
if (a[0] == 'R') march[2]++;
if (a[0] == 'C') march[3]++;
if (a[0] == 'H') march[4]++;
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | l=[0]*5
n=int(input())
for i in range(n):
s=input()
a=s[0]
if a=='M':
l[0]+=1
elif a=='A':
l[1]+=1
elif a=='R':
l[2]+=1
elif a=='C':
l[3]+=1
elif a=='H':
l[4]+=1
if n==4 and sum(l)==0:
exit()
print(l[0]*l[1]*l[2]
+l[0]*l[1]*l[3]
+l[0]*l[1]*l[4]
+l[0]*l[2]*l[3]
+l[0]*l[2]*l[4]
+l[0]*l[3]*l[4]
+l[1]*l[2]*l[3]
+l[1]*l[2]*l[4]
+l[1]*l[3]*l[4]
+l[2]*l[3]*l[4]) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int f[5] = {};
long long ans = 0;
void solve(int i, int cnt, int num[]) {
if (cnt == 3) {
ans += f[num[0]] * f[num[1]] * f[num[2]];
return;
}
if (i == 5)
return;
else {
solve(i + 1, cnt, num);
num[cnt] = i;
solve(i + 1, cnt + 1, num);
}
return;
}
int main() {
int n;
cin >> n;
for (int i = (0); i < (int)(n); i++) {
string s;
cin >> s;
char c = s[0];
if (c == 'M')
f[0]++;
else if (c == 'A')
f[1]++;
else if (c == 'R')
f[2]++;
else if (c == 'C')
f[3]++;
else if (c == 'H')
f[4]++;
else
continue;
}
int num[3] = {};
solve(0, 0, num);
cout << (ans) << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int m = 0;
int y;
int k1(string a) {
if (a == "M") {
m++;
return 1;
} else if (a == "A") {
m++;
return 2;
} else if (a == "R") {
m++;
return 3;
} else if (a == "C") {
m++;
return 4;
} else if (a == "H") {
m++;
return 5;
} else {
return 0;
}
}
int main() {
long int n;
cin >> n;
vector<string> s(n);
vector<int> x(n);
for (int i = 0; i < (n); i++) {
cin >> s[i];
string a = s[i];
a = a[0];
x[i] = k1(a);
}
if (m < 3) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
long int ans = 0;
for (int i = 0; i < (n); i++) {
if (x[i] == 0) {
continue;
}
for (int j = (i) + 1; j < (n); j++) {
if (x[j] == 0 || x[j] == x[i]) {
continue;
}
for (int k = (j) + 1; k < (n); k++) {
if (x[k] == 0) {
continue;
} else if (x[k] == x[i] || x[k] == x[j]) {
continue;
}
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
char X[5] = {'M', 'A', 'R', 'C', 'H'};
long long a[5] = {0, 0, 0, 0, 0};
long long k;
k = 0;
long long N;
cin >> N;
string S[N];
for (int i = 0; i < N; i++) {
cin >> S[i];
for (int j = 0; j < 5; j++) {
if (S[i][0] == X[j]) {
a[j]++;
}
}
}
for (int i = 0; i < 5; i++) {
if (a[i] > 0) {
k++;
}
}
long long sum1 = 0;
long long sum2 = 0;
long long sum3 = 0;
for (int i = 0; i < N; i++) {
sum1 += a[i];
sum2 += a[i] * a[i];
sum3 += a[i] * a[i] * a[i];
}
if (k < 3) {
cout << 0 << endl;
} else {
cout << (sum1 * sum1 * sum1 + 2 * sum3 - 3 * sum1 * sum2) / 6 << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
string S;
int MARCH[5] = {0};
for (int i = 0; i < N; i++) {
cin >> S;
switch (S[0]) {
case 'M':
MARCH[0]++;
break;
case 'A':
MARCH[1]++;
break;
case 'R':
MARCH[2]++;
break;
case 'C':
MARCH[3]++;
break;
case 'H':
MARCH[4]++;
break;
}
}
int count = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
count += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int n;string s;map<char,long>a;
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>s,a[s[0]]++;
long m=a['M'],a=a['A'],r=a['R'],c=a['C'],h=a['H'];
cout<<m*a*(r+c+h)+(m+a+r)*c*h+(m+a)*r*(c+h);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
a[n + 1] = 0;
int total = 0;
for (int i = 0; i < n + 1; i++) {
total += abs(a[i + 1] - a[i]);
}
for (int i = 1; i <= n; i++) {
int temp = total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
abs(a[i + 1] - a[i - 1]);
cout << temp << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, cnt = 0;
long long M = 0, A = 0, R = 0, C = 0, H = 0;
string tmp;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> tmp;
if (tmp[0] == 'M')
M++;
else if (tmp[0] == 'A')
A++;
else if (tmp[0] == 'R')
R++;
else if (tmp[0] == 'C')
C++;
else
H++;
}
cnt += M * A * R;
cnt += A * R * C;
cnt += R * C * H;
cnt += C * H * M;
cnt += H * M * A;
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int INF = 1e9;
const long long MX = 1e18;
const long long MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const double PI = acos(-1);
const long long MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (long long i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(long long n, long long k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
COMinit();
long long n;
cin >> n;
map<char, int> mp;
long long ans = 0;
long long cnt = 0;
for (long long i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' && s[0] != 'H')
continue;
mp[s[0]]++;
cnt++;
}
if (mp.size() < 3) {
cout << 0 << endl;
return 0;
}
ans = cnt * (cnt - 1) * (cnt - 2) / 6;
for (auto x : mp) {
if (x.second == 2) {
ans -= cnt - 2;
}
if (x.second >= 3) {
ans -= (cnt - x.second) * (x.second) * (x.second - 1) / 2;
ans -= x.second * (x.second - 1) * (x.second - 2) / 6;
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::cmp::{max, min};
#[allow(unused_macros)]
macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
input_inner!{iter, $($r)*}
};
($($r:tt)*) => {
let s = {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
s
};
let mut iter = s.split_whitespace();
input_inner!{iter, $($r)*}
};
}
#[allow(unused_macros)]
macro_rules! input_inner {
($iter:expr) => {};
($iter:expr, ) => {};
($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($iter, $t);
input_inner!{$iter $($r)*}
};
}
#[allow(unused_macros)]
macro_rules! read_value {
($iter:expr, ( $($t:tt),* )) => {
( $(read_value!($iter, $t)),* )
};
($iter:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
};
($iter:expr, chars) => {
read_value!($iter, String).chars().collect::<Vec<char>>()
};
($iter:expr, usize1) => {
read_value!($iter, usize) - 1
};
($iter:expr, $t:ty) => {
$iter.next().unwrap().parse::<$t>().expect("Parse error")
};
}
fn main() {
input! {
n: usize,
s:[chars; n],
}
let mut D = vec![0; 5];
let mut P = vec![0,0,0,0,0,0,1,1,1,2];
let mut Q = vec![1,1,1,2,2,3,2,2,3,3];
let mut R = vec![2,3,4,3,4,4,3,4,4,4];
let mut m = 0;
let mut a = 0;
let mut r = 0;
let mut c = 0;
let mut h = 0;
for i in 0..n {
if s[i][0] == 'M' {m+=1;}
if s[i][0] == 'A' {a+=1;}
if s[i][0] == 'R' {r+=1;}
if s[i][0] == 'C' {c+=1;}
if s[i][0] == 'H' {h+=1;}
}
D[0]=m;D[1]=a;D[2]=r;D[3]=c;D[4]=h;
let mut res = 0;
for d in 0..10 {
res+=D[P[d]] * D[Q[d]] * D[R[d]];
}
println!("{}", res);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s[N];
for (int i = 0; i < N; ++i) cin >> s[i];
int a[5] = {0};
for (int i = 0; i < N; ++i) {
if (s[i][0] == 'M') a[0]++;
if (s[i][0] == 'A') a[1]++;
if (s[i][0] == 'R') a[2]++;
if (s[i][0] == 'C') a[3]++;
if (s[i][0] == 'H') a[4]++;
}
long long res = 0;
res += a[0] * a[1] * a[2];
res += a[0] * a[1] * a[3];
res += a[0] * a[1] * a[4];
res += a[0] * a[2] * a[3];
res += a[0] * a[2] * a[4];
res += a[0] * a[3] * a[4];
res += a[1] * a[2] * a[3];
res += a[1] * a[2] * a[4];
res += a[1] * a[3] * a[4];
res += a[2] * a[3] * a[4];
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long m = 0;
long a = 0;
long r = 0;
long c = 0;
long h = 0;
for (int i = 0; i < n; i++) {
char fc = sc.next().charAt(0);
switch (fc) {
case 'm':
m++;
break;
case 'a':
a++;
break;
case 'r':
r++;
break;
case 'c':
c++;
break;
case 'h':
h++;
break;
}
}
System.out.println(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h +r*c*h);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String march="MARCH";
int[] a=new int[6];
for(int i=0;i<n;i++){
a[march.indexOf(sc.next().charAt(0))+1]++;
}
long ans=0;
for(int i=1;i<=3;i++){
for(int j=i+1;j<=4;j++){
for(int k=j+1;k<=5;k++){
ans+=a[i]*a[j]*a[k];
}
}
}
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | def main():
N = int(input())
M = A = R = C = H = 0
for i in range(N):
name = input()
if name[0] == "M":
M = M + 1
elif name[0] == "A":
A = A + 1
elif name[0] == "R":
R = R + 1
elif name[0] == "C":
C = C + 1
elif name[0] == "H":
H = H + 1
ans = M*A*R
ans = ans + M*A*C
ans = ans + M*A*H
ans = ans + M*R*C
ans = ans + M*R*H
ans = ans + A*R*C
ans = ans + A*R*H
ans = ans + R*C*H
print(ans)
if __name__ == '__main__':
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <stdio.h>
#include <string.h>
main()
{
long a[5] = {0,0,0,0,0};
int N;
scanf("%d", &N);
int k;
for(k = 1; k <= N; k++);
{
char s[11];
scanf("%s", s);
if(s[0] == 'M') a[0]++;
if(s[0] == 'A') a[1]++;
if(s[0] == 'R') a[2]++;
if(s[0] == 'C') a[3]++;
if(s[0] == 'H') a[4]++;
}
int O = 0;
int s, t, r;
for(s=1; s<=3; s++)
{for(t=s+1; t<=4; t++)
{for(r=s+2; r<=5; R++)
O += a[s]*a[t]*a[r]
}}
printf("%d", O);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<char, int> name;
set<char> id = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (id.end() != id.find(s.at(0))) name[s.at(0)] += 1;
}
char p[10] = {'M', 'M', 'M', 'M', 'M', 'M', 'A', 'A', 'A', 'R'};
char q[10] = {'A', 'A', 'A', 'R', 'R', 'R', 'R', 'C', 'C', 'C'};
char r[10] = {'R', 'C', 'H', 'C', 'H', 'C', 'H', 'H', 'H', 'H'};
long long ans = 0;
for (int i = 0; i < 10; i++) {
ans += name[p[i]] * name[q[i]] * name[r[i]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int march[5] = {0};
string name;
for (int i = 0; i < n; i++) {
cin >> name;
if (name.at(0) == 'M') {
march[0]++;
} else if (name[0] == 'A') {
march[1]++;
} else if (name[0] == 'R') {
march[2]++;
} else if (name[0] == 'C') {
march[3]++;
} else if (name[0] == 'H') {
march[4]++;
}
}
long long ans =
march[0] * march[1] * march[2] + march[0] * march[1] * march[3] +
march[0] * march[1] * march[3] + march[0] * march[2] * march[3] +
march[0] * march[2] * march[4] + march[0] * march[3] * march[4] +
march[1] * march[2] * march[3] + march[1] * march[2] * march[4] +
march[1] * march[3] * march[4] + march[2] * march[3] * march[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000009;
signed main() {
long long n;
cin >> n;
long long m[5] = {};
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
m[0]++;
else if (s[0] == 'A')
m[1]++;
else if (s[0] == 'R')
m[2]++;
else if (s[0] == 'C')
m[3]++;
else if (s[0] == 'H')
m[4]++;
}
long long sum = 0;
for (long long i = 0; i < 5; i++)
if (m[i]) sum++;
if (sum == 5) {
long long ans = 0;
for (long long i = 0; i < 5; i++) {
for (long long j = 0; j < 5; j++) {
if (i == j) continue;
long long tmp = 1;
for (long long k = 0; k < 5; k++) {
if (k == i || k == j) continue;
tmp *= m[k];
}
ans += tmp;
}
}
cout << ans << endl;
} else if (sum == 4) {
long long ans = 0;
for (long long i = 0; i < 5; i++) {
if (m[i] == 0) continue;
long long tmp = 1;
for (long long j = 0; j < 5; j++) {
if (i == j || m[j] == 0) continue;
tmp *= m[j];
}
ans += tmp;
}
cout << ans << endl;
} else if (sum == 3) {
long long ans = 1;
for (long long i = 0; i < 5; i++) {
if (m[i]) ans *= m[i];
}
cout << ans << endl;
} else
cout << 0 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, m, a, r, c, h;
string s;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
cout << m * a * r + m * a * c + m * a * h + a * r * c + a * r * h +
r * c * h + m * r * c + m * r * h + m * c * h;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long ans = 0;
int N;
cin >> N;
string st;
vector<pair<char, int> > input(5);
(input[0].first, input[0].second) = ('M', 0);
input[1].first, input[2].second = ("A", 0);
input[2].first, input[2].second = ("R", 0);
input[3].first, input[3].second = ("C", 0);
input[4].first, input[4].second = ("H", 0);
for (int i = 0; i < N; i++) {
cin >> st;
if (st[0] == 'M') input[0].second++;
if (st[0] == 'A') input[1].second++;
if (st[0] == 'R') input[2].second++;
if (st[0] == 'C') input[3].second++;
if (st[0] == 'H') input[4].second++;
}
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
ans += input[i].second * input[j].second * input[k].second;
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<stdio>
int main(){
string s="MARCH";
int c[5] = {0};
int N;
cin>>N;
for(int i=0; i<N; i++){
string t;
cin>>t;
for(int i=0; i<5; i++){
if(t[0] == s[i])
c[i]++;
}
}
int ans = 0;
for(int i=0; i<5; i++){
for(int j=i+1; j<5; j++){
for(int k=j+1; k<5; j++){
ans += c[i]*c[k]*c[j];
}
}
}
cout << ans << endl;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.