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 | cpp | #include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::unordered_map<char, int> um;
for (int i = 0; i < n; i++) {
std::string t;
std::cin >> t;
if (t[0] == 'M' || t[0] == 'A' || t[0] == 'R' || t[0] == 'C' ||
t[0] == 'H') {
um[t[0]]++;
}
}
int ans = 0;
ans += um['M'] * um['A'] * um['R'];
ans += um['M'] * um['A'] * um['C'];
ans += um['M'] * um['A'] * um['H'];
ans += um['M'] * um['R'] * um['C'];
ans += um['M'] * um['R'] * um['H'];
ans += um['M'] * um['C'] * um['H'];
ans += um['A'] * um['R'] * um['C'];
ans += um['A'] * um['R'] * um['H'];
ans += um['A'] * um['C'] * um['H'];
ans += um['R'] * um['C'] * um['H'];
std::cout << ans << std::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;
string name;
std::vector<string> names;
for (int i = 0; i < n; i++) {
cin >> name;
names.push_back(name);
}
std::sort(names.begin(), names.end());
names.erase(unique(names.begin(), names.end()), names.end());
int* a_ = new int[26];
for (int i = 0; i < 26; i++) {
a_[i] = 0;
}
for (string name : names) {
++a_[name[0] - 'A'];
}
int a[5] = {a_['M' - 'A'], a_['A' - 'A'], a_['R' - 'A'], a_['C' - 'A'],
a_['H' - 'A']};
int num = 0;
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
++num;
}
}
if (num < 3) {
cout << "0" << endl;
} else {
int64_t comb = 0;
for (int i = 0; i < 3; i++) {
if (a[i] == 0) continue;
int i_inner = 0;
for (int j = i + 1; j < 4; j++) {
if (a[j] == 0) continue;
int j_inner = 0;
for (int k = j + 1; k < 5; k++) {
j_inner += a[k];
}
i_inner += a[j] * j_inner;
}
comb += a[i] * i_inner;
}
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;
const int maxn = 100010;
char s[maxn][10 + 5];
int march[5 + 5];
int main() {
int n, ans;
cin >> n;
memset(s, 0, sizeof(s));
for (int i = 0; i < n; i++) cin >> s[i];
ans = 0;
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') march[0]++;
if (s[i][0] == 'A') march[1]++;
if (s[i][0] == 'R') march[2]++;
if (s[i][0] == 'C') march[3]++;
if (s[i][0] == 'H') march[4]++;
}
ans = march[0] * march[1] * march[2] + march[0] * march[1] * march[3] +
march[0] * march[1] * march[4] + 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 | python3 | n = int(input())
A = []
B = ['M', 'A', 'R', 'C', 'H']
C = []
for i in range(n):
S = input()
if(S[0] in B):
A.append(S)
C.append(S[0])
a = int(len(C) * (len(C) - 1) * (len(C) - 2) / 3 / 2)
for j in B:
ans = C.count(j)
if(ans == 2):
a = a - (len(C) - ans)
elif(ans >= 3):
a = a - int(ans*(ans - 1) / 2)
if(n < 3 or len(C) == 0):
print(0)
else:
print(a) |
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> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
int cm = 0;
int ca = 0;
int cr = 0;
int cc = 0;
int ch = 0;
vector<pair<char, int>> l;
for (int i = 0; i < N; i++) {
if (p[i][0] == 'M') cm++;
}
if (cm > 0) l.push_back(make_pair('M', cm));
for (int i = 0; i < N; i++) {
if (p[i][0] == 'R') cr++;
}
if (cr > 0) l.push_back(make_pair('R', cr));
for (int i = 0; i < N; i++) {
if (p[i][0] == 'A') ca++;
}
if (ca > 0) l.push_back(make_pair('A', ca));
for (int i = 0; i < N; i++) {
if (p[i][0] == 'C') cc++;
}
if (cc > 0) l.push_back(make_pair('C', cc));
for (int i = 0; i < N; i++) {
if (p[i][0] == 'H') ch++;
}
if (ch > 0) l.push_back(make_pair('H', ch));
long long c = 0;
if (l.size() >= 3) {
for (int i = 0; i < l.size(); i++) {
for (int j = i + 1; j < l.size(); j++) {
for (int k = j + 1; k < l.size(); k++) {
c += l[i].second * l[j].second * l[k].second;
}
}
}
cout << c << endl;
} else
cout << 0 << 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() {
unsigned int i, ans = 1, x = 0;
unsigned int ini[5] = {0};
string name[1000000];
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++;
}
if (name[i][0] == 'M') {
ini[0]++;
}
if (name[i][0] == 'A') {
ini[1]++;
}
if (name[i][0] == 'R') {
ini[2]++;
}
if (name[i][0] == 'C') {
ini[3]++;
}
if (name[i][0] == 'H') {
ini[4]++;
}
}
for (; x > 3; x--) {
ans *= x;
}
ans /= 2;
for (int j = 0; j < 5; j++) {
if (ini[j] > 1) 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;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
vector<string> s(n);
vector<int> march(5);
for (int i = 0; i < n; i++) {
cin >> s.at(i);
for (int j = 0; j < 5; j++)
if (s.at(i).at(0) == c[j]) march.at(j)++;
}
long long o = 0;
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++)
o += march.at(i) * march.at(j) * march.at(k);
cout << o << 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;
void call() {
int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0;
cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
if (s[0] == 'M') {
c1++;
} else if (s[0] == 'A') {
c2++;
} else if (s[0] == 'R') {
c3++;
} else if (s[0] == 'C') {
c4++;
} else if (s[0] == 'H') {
c5++;
}
}
cout << c1 * c2 * c3 + c1 * c2 * c4 + c1 * c2 * c5 + c1 * c3 * c4 +
c1 * c3 * c5 + c1 * c4 * c5 + c2 * c3 * c4 + c2 * c3 * c5 +
c2 * c4 * c5 + c3 * c4 * c5;
return;
}
int main() {
int t;
t = 1;
for (int i = 0; i < t; ++i) {
call();
}
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> march(5, 0);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
char c = s.at(0);
if (c == 'M') {
march.at(0)++;
} else if (c == 'A') {
march.at(1)++;
} else if (c == 'R') {
march.at(2)++;
} else if (c == 'C') {
march.at(3)++;
} else if (c == 'H') {
march.at(4)++;
}
}
long long int res = 0;
for (int f = 0; f < 3; f++) {
for (int s = f + 1; s < 4; s++) {
for (int t = s + 1; t < 5; t++) {
res += march.at(f) * march.at(s) * march.at(t);
}
}
}
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 | 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]]++;
}
int ans = 0;
string march = "MARCH";
for (int i = 0; i + 2 < 5; i++) {
for (int j = i + 1; j + 1 < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += m[march[i]] * m[march[j]] * m[march[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;
long long fact(long long k) {
if (k == 0) return 1;
return k * fact(k - 1);
}
int main() {
long long N;
cin >> N;
map<char, long long> word;
map<char, bool> check;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' || S[i][0] == 'C' ||
S[i][0] == 'H') {
word[S[i][0]]++;
}
}
if (word.size() < 3) {
cout << 0 << endl;
return 0;
}
long long sum;
sum = fact(word.size()) / 6;
long long minus[3] = {0, 3, 16};
long long i = 0;
if (word.size() == 4)
i = 1;
else if (word.size() == 5)
i = 2;
if (word['M'] > 1) sum += (word['M'] - 1) * minus[i];
if (word['A'] > 1) sum += (word['A'] - 1) * minus[i];
if (word['R'] > 1) sum += (word['R'] - 1) * minus[i];
if (word['C'] > 1) sum += (word['C'] - 1) * minus[i];
if (word['H'] > 1) sum += (word['H'] - 1) * minus[i];
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() {
long long n;
cin >> n;
string s;
vector<pair<char, long long>> v(n);
vector<char> c = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) {
v[i].first = c[i];
}
for (int i = 0; i < n; i++) {
cin >> s;
char ini = s[0];
for (int j = 0; j < 5; j++) {
if (v[j].first == ini) {
v[j].second++;
break;
}
}
}
long long sum = 0;
for (int i = 0; i < 3; i++) {
long long a = v[i].second;
for (int j = i + 1; j < 4; j++) {
long long b = v[j].second;
for (int k = j + 1; k < 5; k++) {
long long c = v[k].second;
sum += a * b * c;
}
}
}
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;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
ll n;
cin >> n;
string s;
vector<ll> march(5, 0);
for (int i = 0; i < (int)(n); ++i) {
cin >> s;
if (s[0] == 'M') ++march.at(0);
if (s[0] == 'A') ++march.at(1);
if (s[0] == 'R') ++march.at(2);
if (s[0] == 'C') ++march.at(3);
if (s[0] == 'H') ++march.at(4);
}
ll pis = 1;
ll zerocnt = 0;
for (int i = 0; i < (int)(5); ++i) {
if (march.at(i) != 0)
pis *= march.at(i);
else
++zerocnt;
}
ll ans = 0;
if (zerocnt > 2) ans = 0;
if (zerocnt == 2) ans = pis;
if (zerocnt == 1) {
for (int i = 0; i < (int)(5); ++i) {
if (march.at(i) != 0) ans += pis / march.at(i);
}
}
if (zerocnt == 0) {
for (int i = 0; i < (int)(4); ++i)
for (int j = i + 1; j < 5; ++j) {
ans += pis / march.at(i) / march.at(j);
}
}
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;
unsigned long long int func(unsigned long long int l, long long int r) {
if (l < r) return 0;
unsigned long long int ret = 1;
for (long long int i = l; i >= l - r + 1; i--) {
ret *= l;
}
for (int i = r; i >= 1; i--) {
ret /= r;
}
return ret;
}
void solve() {
unsigned long long int n;
cin >> n;
map<char, int> mp;
unsigned long long int sum = 0;
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') {
mp[s[0]]++;
sum++;
}
}
if (sum < 3) {
cout << 0 << endl;
return;
}
unsigned long long int ans;
ans = sum * (sum - 1) * (sum - 2) / (3 * 2);
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
if (itr->second == 1) continue;
ans -= (sum - itr->second) * func(itr->second, 2) + func(itr->second, 3);
}
cout << ans << endl;
return;
}
int main() {
solve();
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 | #include <bits/stdc++.h>
int main() {
int i, j, n;
scanf("%d", &n);
char s[12];
int m = 0, a = 0, r = 0, c = 0, h = 0;
scanf("%c", &s[0]);
for (i = 0; i < n; i++) {
for (j = 0; j < 10; j++) {
scanf("%c", &s[j]);
if (s[j] == '\n') break;
}
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++;
}
long long x = 0;
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;
printf("%lld", x);
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 = [0] * N
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
s[i] = input()
if s[i][0] == "M":
d['M'] += 1
elif s[i][0] == "A":
d['A'] += 1
elif s[i][0] == "R":
d['R'] += 1
elif s[i][0] == "C":
d['C'] += 1
elif s[i][0] == "H":
d['H'] += 1
total = 1
count = 0
del_keys = []
for k, v in d.items():
if v == 0:
del_keys.append(k)
else:
total *= v
count += 1
print(d)
for key in del_keys:
del d[key]
if count < 3:
print(0)
exit()
elif count == 3:
print(total)
exit()
elif count == 4:
ans = 0
for k, v in d.items():
ans += total / v
print(int(ans))
exit()
elif count == 5:
ans = 0
d_lst = list(d)
for i in range(4):
for j in range(i+1, 5):
ans += total / (d_lst[i] * d_lst[j])
print(int(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 | 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++;
}
}
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;
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 p[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
p[0]++;
else if (s[0] == 'A')
p[1]++;
else if (s[0] == 'R')
p[2]++;
else if (s[0] == 'C')
p[3]++;
else if (s[0] == 'H')
p[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 += p[i] * p[j] * p[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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d", &N);
char s[N][10];
for (int i = 0; i < N; i++) {
scanf("%s", &s[i][10]);
}
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int j = 1; j < N + 1; j++) {
if (s[j][0] == 'M') M++;
if (s[j][0] == 'A') A++;
if (s[j][0] == 'R') R++;
if (s[j][0] == 'C') C++;
if (s[j][0] == 'H') H++;
}
int num = 0;
num = 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;
printf("%d", num);
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.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
new Main().solve();
}
void solve() {
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
long a=0;
long b=1;
long c=0;
long d=0;
long e=0;
String S[]=new String[N];
int s[]=new int[5];
Arrays.fill(s,0);
for(int i=0;i<N;i++){
S[i]=sc.next();
}
for(int i=0;i<N;i++){
if(S[i].charAt(0)=='M')s[0]++;
if(S[i].charAt(0)=='A')s[1]++;
if(S[i].charAt(0)=='R')s[2]++;
if(S[i].charAt(0)=='C')s[3]++;
if(S[i].charAt(0)=='H')s[4]++;
}
for(int i=0;i<5;i++){
if(s[i]>0)a++;
if(s[i]>1){
for(int j=s[i];j>0;j--){
c++;
d++;
}
b=b*c;
e=e+d-1;
c=0;
d=0;
}
}
if(a<=3){
System.out.println(C(a)*b);
}else if(a>4){
System.out.println(C(a)*b-(b-1)-e);
}else{
System.out.println(C(a)*b-(b-1));
}
}
long C(long s){
long a=s;
for(long i=s-1;i>1;i--){
a=a*i;
}
return a/6;
}
}
|
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 n, s = 0, i;
long long m = 0, a = 0, r = 0, c = 0, h = 0;
char x[100005][10];
for (i = 0; i < n; i++) {
scanf("%s", &x[i]);
}
for (i = 0; i < n; i++) {
switch (x[i][0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'h':
h++;
break;
default:
break;
}
}
s += 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 << s << 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 = "MARCH";
char D[100001] = {};
long long C[5] = {};
int main() {
cin >> N;
int Total = 0;
for (int i = 0; i < N; i++) {
string str;
cin >> str;
for (int j = 0; j < 5; j++) {
if (str[0] == S[j]) C[j]++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
Total += C[i] * C[j] * C[k];
}
}
}
cout << Total << 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;
char num[5]{'M', 'A', 'R', 'C', 'H'};
void recursive_comb(vector<int> indexes, int s, int rest,
std::function<void(vector<int>)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
vector<int> indexes(k);
recursive_comb(indexes, n - 1, k, f);
}
ll ans = 0;
map<char, int> a;
int main() {
int N;
cin >> N;
vector<string> s(N);
for (int i = 0; i < (N); i++) cin >> s[i];
for (int i = 0; i < (N); i++) {
a[s[i][0]]++;
}
foreach_comb(5, 3, [](vector<int> indexes) {
ans += a[num[indexes[0]]] * a[num[indexes[1]]] * a[num[indexes[2]]];
});
cout << 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 | import math
def combi(a, b):
ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
return ans
N=int(input())
S=[0]*5
for i in range(N):
s=input()
temp=s[0]
if temp=="M":
S[0]+=1
elif temp=="A":
S[1]+=1
elif temp=="R":
S[2]+=1
elif temp=="C":
S[3]+=1
elif temp=="H":
S[4]+=1
c=0
N=0
for i in range(5):
N+=S[i]
if S[i]!=0:
c+=1
if c<=2:
print(0)
else:
for i in range(5):
if S[i]>=3:
NG=combi(S[i],3)+combi(S[i],2)*(N-S[i])
elif S[i]==2:
NG=combi(S[i],2)*(N-S[i])
print(int(combi(N,3)-NG))
|
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 m, a, r, c, h;
m = a = r = c = h = 0;
for (int i = 0; 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++;
}
int d[5];
d[0] = m;
d[1] = a;
d[2] = r;
d[3] = c;
d[4] = h;
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++) {
long long tmp = d[i] * d[j] * d[k];
ans += tmp;
}
}
}
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 | UNKNOWN | package main
import "fmt"
func main() {
var n int
fmt.Scan(&n)
m := make(map[byte]int)
var s string
for i := 0; i < n; i++ {
fmt.Scan(&s)
m[s[0]]++
}
march := []byte{'M', 'A', 'R', 'C', 'H'}
ans := 0
for i := 0; i < n-2; i++ {
for j := i + 1; j < n-1; j++ {
for k := j + 1; k < n; k++ {
ans += m[march[i]] * m[march[j]] * m[march[k]]
}
}
}
fmt.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;
int main(){
int N;
int group[5]={};
long long int ans=0;
string tmp;
cin >> N;
for(int i=0;i<N;i++){
cin>>tmp;
switch(tmp[0]){
case 'M':
group[0]++;
break;
case 'A':
group[1]++;
break;
case 'R':
group[2]++;
break;
case 'C':
group[3]++;
break;
case 'H':
group[4]++;
break;
default:
}
}
for(int i=0;i<N-2;i++){
for(int j=i+1;j<N-1;j++){
for(int k=j+1;k<N;k++){
ans+=group[i]*group[j]*group[k];
}
}
}
printf("%lld\n",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 name;
long long m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
cin >> name;
switch (name[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
int pat;
pat = m * a * c + m * a * r + 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 << pat << "\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 | cpp | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m) {
long long ans = 1;
while (n) {
if (n & 1) {
ans = (ans * a) % m;
}
a = (a * a) % m;
n >>= 1;
}
return ans;
}
long long combi(long long n, long long a) {
long long ans = 1, ans1 = 1;
for (long long i = n - a + 1; i <= n; i++) {
ans *= i % MOD;
ans %= MOD;
}
for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % MOD;
ans1 = modpow(ans1, MOD - 2, MOD);
return ((ans % MOD) * ans1) % MOD;
}
void dfs(string s, char mx, long long N) {
if (s.length() == (size_t)N) {
cout << s.c_str() << endl;
} else {
for (char c = 'a'; c <= mx; c++) {
dfs(s + c, ((c == mx) ? (char)(mx) : mx), N);
}
}
}
int bfs(int a, int b, int h, int w, char tmp[][101]) {
int ans[101][101] = {0};
char c[101][101] = {0};
queue<pair<int, int>> s;
for (int i = 0; i <= h; i++) {
for (int j = 0; j <= w; j++) {
c[i][j] = tmp[i][j];
}
}
s.push(make_pair(a, b));
while (s.size() > 0) {
pair<int, int> tmp = s.front();
s.pop();
c[tmp.first][tmp.second] = '#';
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
if (tmp.first + i < 1 || tmp.first + i > h) {
continue;
}
if (tmp.second + j < 1 || tmp.second + j > w) {
continue;
}
if (i != 0 && j != 0) {
continue;
}
if (i == 0 && j == 0) {
continue;
}
if (c[tmp.first + i][tmp.second + j] == '#') {
continue;
}
c[tmp.first + i][tmp.second + j] = '#';
if (ans[tmp.first + i][tmp.second + j] == 0) {
ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
} else {
ans[tmp.first + i][tmp.second + j] =
min(ans[tmp.first + i][tmp.second + j],
ans[tmp.first][tmp.second] + 1);
}
s.push(make_pair(tmp.first + i, tmp.second + j));
}
}
}
int asd = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
asd = max(a, ans[i][j]);
}
}
return asd;
}
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; }
int main() {
long long n;
cin >> n;
map<char, long long> m;
m['M'] = m['A'] = m['R'] = m['C'] = m['H'] = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
m['M']++;
else if (s[0] == 'A')
m['A']++;
else if (s[0] == 'R')
m['R']++;
else if (s[0] == 'C')
m['C']++;
else if (s[0] == 'H')
m['H']++;
}
long long ss = 0;
long long total = 0;
for (auto i = m.begin(); i != m.end(); ++i) {
if (i->second > 0) {
ss++;
}
total += i->second;
}
if (ss < 3) {
cout << 0 << endl;
return 0;
}
long long ans = combi(total, 3);
for (auto i = m.begin(); i != m.end(); ++i) {
if (i->second > 1) {
if (ss > 3) {
ans -= i->second + 1;
} else {
ans -= i->second;
}
}
}
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 n, h[100005];
long long dp[100005];
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
stack<long long> sta;
queue<long long> que;
set<string> s_set;
void comb(vector<vector<long long> > &v) {
for (long long i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (long long k = 1; k < v.size(); k++) {
for (long long j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
}
}
}
int main() {
long long A, B, C, D, E, F, G, H, I, J, L, N, M, K, O,
pair<long long, long long>, Q, R, S, T, U, V, W, X, Y, Z;
long long ans;
ans = 0;
string s;
long long sum, sum1, sum2, sum3, sum4;
sum = sum1 = sum2 = sum3 = sum4 = 0;
long long flg, flg1, flg2, flg3, flg4, flg5, cnt, cnt1, cnt2, cnt3, cnt4,
cnt5;
flg = flg1 = flg2 = flg3 = flg4 = flg5 = cnt = cnt1 = cnt2 = cnt3 = cnt4 =
cnt5 = 0;
long long max;
long long max1;
max = max1 = 0;
long long min;
long long min1;
min = min1 = 1000000000;
long long work, work1, work2, work3, work4;
work = work1 = work2 = work3 = work4 = 0;
std::cin >> N;
string SS[N];
for (long long i = 0; i < N; i++) {
std::cin >> SS[i];
}
for (long long i = 0; i < N; i++) {
if (SS[i][0] == 'M') {
cnt1++;
if (flg1 == 0) {
sum++;
flg1 = 1;
}
}
if (SS[i][0] == 'A') {
cnt2++;
if (flg2 == 0) {
sum++;
flg2 = 1;
}
}
if (SS[i][0] == 'R') {
cnt3++;
if (flg3 == 0) {
sum++;
flg3 = 1;
}
}
if (SS[i][0] == 'C') {
cnt4++;
if (flg4 == 0) {
sum++;
flg4 = 1;
}
}
if (SS[i][0] == 'H') {
cnt5++;
if (flg5 == 0) {
sum++;
flg5 = 1;
}
}
}
long long NN;
NN = sum;
if (sum < 3) {
puts("0");
return 0;
} else if (sum == 3) {
printf("%lld\n", 1 + (cnt1 + cnt2 + cnt3 + cnt4 + cnt5) - 3);
return 0;
} else if (sum == 4) {
printf("%lld\n", 4 * ((cnt1 + cnt2 + cnt3 + cnt4 + cnt5) - 3) -
(cnt1 + cnt2 + cnt3 + cnt4 + cnt5) + 3 + 1);
return 0;
} else if (sum == 5) {
printf("%lld\n", 10 * ((cnt1 + cnt2 + cnt3 + cnt4 + cnt5) - 4) -
(cnt1 + cnt2 + cnt3 + cnt4 + cnt5) + 4 + 1);
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 S[N];
int i;
int n[5] = {0, 0, 0, 0, 0};
for (i = 0; i < N; i++) {
cin >> S[i];
switch (S[i][0]) {
case 'M':
n[0]++;
break;
case 'A':
n[1]++;
break;
case 'R':
n[2]++;
break;
case 'C':
n[3]++;
break;
case 'H':
n[4]++;
break;
default:
break;
}
}
int a[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int b[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int c[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
long long count = 0;
for (i = 0; i < 10; i++) {
count += n[a[i]] * n[b[i]] * n[c[i]];
}
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, m[5] = {};
cin >> n;
string s[n];
for (long i = 0; i < n; i++) {
cin >> s[i];
switch (s[i][0]) {
case 'M':
m[0]++;
break;
case 'A':
m[1]++;
break;
case 'R':
m[2]++;
break;
case 'C':
m[3]++;
break;
case 'H':
m[4]++;
}
}
sort(m, m + 5);
cout << m[0] * m[1] * (m[2] + m[3] + m[4]) + m[0] * m[2] * (m[3] + m[4]) +
m[0] * m[3] * m[4] + m[1] * m[2] * (m[3] + m[4]) +
m[1] * m[3] * m[4] + m[2] * m[3] * m[4]
<< 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;
bool check(string s) {
for (int i = 0; i < s.size(); i++) {
s[i] = char(tolower(s[i]));
}
for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[5] = {
0,
};
string s;
for (int i = 0; i < n; i++) {
cin >> 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]++;
}
}
long long sum = 0;
for (int i = 0; i < a[0]; i++) {
for (int j = 0; j < a[1]; j++) {
for (int k = 0; k < a[2]; k++) {
sum++;
}
for (int k = 0; k < a[3]; k++) {
sum++;
}
for (int k = 0; k < a[4]; k++) {
sum++;
}
}
for (int j = 0; j < a[2]; j++) {
for (int k = 0; k < a[3]; k++) {
sum++;
}
for (int k = 0; k < a[4]; k++) {
sum++;
}
}
for (int j = 0; j < a[3]; j++) {
for (int k = 0; k < a[4]; k++) {
sum++;
}
}
}
for (int i = 0; i < a[1]; i++) {
for (int j = 0; j < a[2]; j++) {
for (int k = 0; k < a[3]; k++) {
sum++;
}
for (int k = 0; k < a[4]; k++) {
sum++;
}
}
for (int j = 0; j < a[3]; j++) {
for (int k = 0; k < a[4]; k++) {
sum++;
}
}
}
cout << 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 | UNKNOWN | use std::io;
fn main() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let n = buf.trim().parse::<i32>().unwrap();
let mut inum = [0i64; 5];
for _ in 0..n {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let fch = buf.chars().next().unwrap();
match fch {
'M' => inum[0] += 1,
'A' => inum[1] += 1,
'R' => inum[2] += 1,
'C' => inum[3] += 1,
'H' => inum[4] += 1,
_ => (),
}
}
if inum.iter().all(|&x| x == 0) {
println!("0");
return;
}
let n0 = inum.into_iter().filter(|&&x| x != 0)
.map(|&x| x).collect::<Vec<i64>>();
let mut r = 0;
let len = n0.len();
if len == 3 {
r = n0.iter().fold(1, |acc, &x| acc * x)
} else if len == 4 {
r = 0;
for i in 0..4 {
let mut r2 = 1;
for j in 0..4 {
if i != j {
r2 *= n0[j];
}
}
println!("{}", r2);
r += r2;
}
} else if len == 5 {
r = 0;
for i in 0..5 {
for j in (i + 1)..5 {
let mut r2 = 1;
for k in 0..5 {
if i != j && j != k {
r2 *= n0[k];
}
}
r += r2;
}
}
}
println!("{}", r);
}
|
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() {
std::string s = "MARCH";
int i, N, j;
int c[5] = {0};
cin >> N;
for (i = 0; i < N; i++) {
std::string t;
cin >> t;
for (j = 0; j < N; j++) {
if (t[0] == s[j]) c[j]++;
}
}
int ans = 0;
for (i = 0; i < 5; i++) {
for (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() {
int64_t x = 0, m = 0, a = 0, r = 0, c = 0, h = 0;
int D[5], i, N, d;
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 T[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> N;
vector<string> S(N);
for (i = 0; i < N; ++i) {
cin >> S[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;
}
D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
for (d = 0; d < 10; ++d) {
x += D[P[d]] * D[Q[d]] * D[T[d]];
}
cout << x << 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 | import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c=['M','A','R','C','H']
d={}
n=int(input())
for i in range(n):
word=input()
if word[0] in c:
if word[0] in d: d[word[0]]+=1
else: d[word[0]]=1
m = sum(d.values())
max = combinations_count(m,3) if m>=3 else 0
sub = 0
for i in d.values():
if i>=3:
sub += combinations_count(i, 3)
if i>=2:
sub += combinations_count(i, 2) *(len(d)-1)
print(max - sub) |
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 T[26] = {0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
string s;
int m = 0;
for (int i = 0; i < N; ++i) {
cin >> s;
const char c = s[0];
switch (c) {
case 'M':
case 'A':
case 'R':
case 'C':
case 'H':
T[s[0] - 'A']++;
++m;
break;
default:
break;
}
}
long long ans = m * (m - 1) * (m - 2) / 6;
for (auto c : {'M', 'A', 'R', 'C', 'H'}) {
const auto l = T[c - 'A'];
if (l < 2) continue;
ans -= l * (l - 1) * (m - l) / 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() {
int N;
cin >> N;
string s;
int count[5] = {};
for (int i = 0; i < N; i++) {
cin >> s;
switch (s[0]) {
case 'M':
count[0]++;
break;
case 'A':
count[1]++;
break;
case 'R':
count[2]++;
break;
case 'C':
count[3]++;
break;
case 'H':
count[4]++;
break;
}
}
int pos = 0, j = 0, count2[5] = {};
for (int i = 0; i < 5; i++) {
if (count[i] > 0) {
pos++;
count2[j] = count[i];
j++;
}
}
if (count2[2] == 0) {
cout << 0 << endl;
} else if (count2[3] == 0) {
cout << count2[0] * count2[1] * count2[2] << endl;
} else if (count2[4] == 0) {
cout << count2[0] * count2[1] * count2[2] +
count2[0] * count2[1] * count2[3] +
count2[0] * count2[2] * count2[3] +
count2[1] * count2[2] * count2[3]
<< endl;
} else {
cout << count2[0] * count2[1] * count2[2] +
count2[0] * count2[1] * count2[3] +
count2[0] * count2[1] * count2[4] +
count2[0] * count2[2] * count2[3] +
count2[0] * count2[2] * count2[4] +
count2[0] * count2[3] * count2[4] +
count2[1] * count2[2] * count2[3] +
count2[1] * count2[2] * count2[4] +
count2[1] * count2[3] * count2[4] +
count2[2] * count2[3] * count2[4]
<< 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;
int num[5] = {};
int main() {
cin >> N;
string name;
for (int i = 0; i < N; i++) {
cin >> name;
switch (name[0]) {
case 'M':
num[0]++;
break;
case 'A':
num[1]++;
break;
case 'R':
num[2]++;
break;
case 'C':
num[3]++;
break;
case 'H':
num[4]++;
break;
default:
break;
}
}
long long 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 += num[i] * num[j] * num[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 | java | import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
int[] D = new int[5];
int[] x = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int[] y = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int[] z = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for(int i=0; i<N; i++){
String s = sc.next();
if(s.charAt(0)=='M') m++;
if(s.charAt(0)=='A') a++;
if(s.charAt(0)=='R') r++;
if(s.charAt(0)=='C') c++;
if(s.charAt(0)=='H') h++;
}
D[0] = m;
D[1] = a;
D[2] = r;
D[3] = c;
D[4] = h;
long ans = 0L;
for(int i=0; i<10; i++){
ans += 0L + D[x[i]] * D[y[i]] * D[z[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 | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
char init_a[5] = {'M', 'A', 'R', 'C', 'H'};
int n;
cin >> n;
map<char, int> m_cnt;
for (int i = (0); i < (n); i++) {
string s;
cin >> s;
m_cnt[s[0]]++;
}
ll 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 += m_cnt[init_a[i]] * m_cnt[init_a[j]] * m_cnt[init_a[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;
signed main() {
long long cnt[5] = {0};
long long n;
string s;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') cnt[0]++;
if (s[0] == 'A') cnt[1]++;
if (s[0] == 'R') cnt[2]++;
if (s[0] == 'C') cnt[3]++;
if (s[0] == 'H') cnt[4]++;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
for (long long k = j + 1; k < n; k++) {
ans += cnt[i] * cnt[j] * cnt[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>
int main(void) {
int N;
int cnt = 0;
long long int ans = 1;
long long int res = 0;
std::string s[100000];
long long int march[5] = {0};
std::cin >> N;
for (int i = 0; i < N; i++) {
std::cin >> s[i];
if (s[i][0] == 'M') {
march[0]++;
} else if (s[i][0] == 'A') {
march[1]++;
} else if (s[i][0] == 'R') {
march[2]++;
} else if (s[i][0] == 'C') {
march[3]++;
} else if (s[i][0] == 'H') {
march[4]++;
}
}
for (int i = 0; i < 5; i++) {
if (march[i] > 0) {
cnt++;
ans *= march[i];
}
}
if (cnt <= 2) {
printf("0");
return 0;
} else if (cnt == 3) {
printf("%lld", ans);
} else if (cnt == 4) {
for (int i = 0; i < 5; i++) {
if (march[i] != 0) {
res += ans / march[i];
}
}
printf("%lld", res);
return 0;
} else if (cnt == 5) {
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
res += (ans / march[i]) / march[j];
}
}
printf("%lld", res);
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 | import java.lang.*
fun main(args:Array<String>) {
val bm = (0.."11111".toInt(2)).map {
"${java.lang.Integer.toBinaryString(it)}".padStart(5, '0')
}.filter {
it.toList().filter { it == '1' }.size == 3
}
//println(bm)
val n = readLine()!!.toInt()
val m = mutableMapOf<String, Int>()
val march = "MARCH".toList().map { it.toString() }
for( it in (1..n) ) {
val name = readLine()!!
val h = name[0].toString()
if( !march.contains(h) )
continue
if( m.get(h) == null )
m[h] = 0
m[h] = m[h]!! + 1
}
val marchFreq = "MARCH".toList().map { char ->
val h = char.toString()
when {
m.get(h) != null -> Pair(h,m[h]!!)
else -> Pair(h,0)
}
}
var result = 0
for( mask in bm ) {
val comb = mask.toList().zip( marchFreq ).map {
val (bit, pair) = it
val freq = pair.second
//println("${bit.toString().toInt()} ${freq}")
bit.toString().toInt()*freq
}.filter { it != 0 }
if( comb.size == 3 ) {
val min_result = comb.reduce { y,x -> y*x }
result += min_result
//println("${mask} ${marchFreq} ${comb} ${min_result}" )
}
}
println(result)
} |
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;
int64_t ans = 0;
cin >> N;
vector<int> num(5, 0);
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M')
num[0]++;
else if (S[0] == 'A')
num[1]++;
else if (S[0] == 'R')
num[2]++;
else if (S[0] == 'C')
num[3]++;
else if (S[0] == 'H')
num[4]++;
}
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;
}
|
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;
int 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;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int a[5];
int main() {
for (int i = 0; i < 5; i++) a[i] = 0;
long int n;
cin >> n;
for (int i = 0; i < n; i++) {
char tmp[15];
cin >> tmp;
for (int j = 0; j < 5; j++) {
if (tmp[0] == c[j]) {
a[j]++;
}
}
}
long long int out = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
out += a[i] * a[j] * a[k];
}
}
}
cout << out << 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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x7fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e-8
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int MOD=100000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
ll res=1; while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
return res;
}
template<class T>
T minn(T a, T b) {return a<b?a:b;}
template<typename T, typename... Args>
T minn(T a, T b, Args... args){return minn(a>b?a:b, args...);}
bool ispow2(ll x){ return x && (!(x&(x-1))); }
ld pow(ld a, int n) {
if(n == 0) return 1;if(n == 1) return a;
double t = pow(a, n/2);return t * t * pow(a, n%2);
}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout<<fixed; cerr<<fixed;
cout<<setprecision(8); cerr<<setprecision(3);
#ifdef DEBUG
freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
clock_t tStart = clock();
#endif
int v[5]{0,0,0,0,0}, n; cin>>n;
for(int i=0;i<n;++i){
string s; cin>>s;
switch(s[0]){
case 'M': {v[0]++; break;}
case 'A': {v[1]++; break;}
case 'R': {v[2]++; break;}
case 'C': {v[3]++; break;}
case 'H': {v[4]++; break;}
}
}
ull ans=0;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
for(int k=j+1;k<n;++k) ans+=v[i]*v[j]*v[k];
}
}
cout<<ans<<'\n';
#ifdef DEBUG
cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
#endif
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) tmp *= m[k];
}
ans += tmp;
}
}
cout << ans / 2 << 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 | python3 | import itertools
import collections
N = int(input())
MARCH = ['M','A','R','C','H']
array = collections.deque()
cnt = 0
for i in range(N):
s = input()
if s[0] in MARCH:
array.append(s[0])
c = list(itertools.combinations(array,3))
for i in c:
if len(set(i)) == 3:
cnt += 1
print(cnt) |
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 | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
sc.Scan()
n, err := strconv.Atoi(sc.Text())
if err != nil {
panic(err)
}
return n
}
func nextString() string {
sc.Scan()
return sc.Text()
}
func main() {
sc.Split(bufio.ScanWords)
n := nextInt()
c := map[byte]int{
'M': 0,
'A': 0,
'R': 0,
'C': 0,
'H': 0,
}
for i := 0; i < n; i++ {
s := nextString()
if strings.IndexAny(s, "MARCH") != 0 {
continue
}
c[s[0]]++
}
answer := 0
answer += c['M'] * c['A'] * c['R']
answer += c['M'] * c['A'] * c['C']
answer += c['M'] * c['A'] * c['H']
answer += c['M'] * c['R'] * c['C']
answer += c['M'] * c['R'] * c['H']
answer += c['M'] * c['C'] * c['H']
answer += c['A'] * c['R'] * c['C']
answer += c['A'] * c['C'] * c['H']
answer += c['R'] * c['C'] * c['H']
fmt.Println(answer)
}
|
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);
map<char, int> namae;
namae['M'] = 0, namae['R'] = 1, namae['A'] = 2, namae['C'] = 3,
namae['H'] = 4;
vector<int> kazu(5, 0);
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M' || S.at(i).at(0) == 'R' || S.at(i).at(0) == 'A' ||
S.at(i).at(0) == 'C' || S.at(i).at(0) == 'H') {
kazu.at(namae[S.at(i).at(0)])++;
}
}
int64_t ans = 0;
ans += (kazu.at(0) * kazu.at(1) * kazu.at(2));
ans += (kazu.at(0) * kazu.at(1) * kazu.at(3));
ans += (kazu.at(0) * kazu.at(1) * kazu.at(4));
ans += (kazu.at(0) * kazu.at(2) * kazu.at(3));
ans += (kazu.at(0) * kazu.at(2) * kazu.at(4));
ans += (kazu.at(0) * kazu.at(3) * kazu.at(4));
ans += (kazu.at(1) * kazu.at(2) * kazu.at(3));
ans += (kazu.at(1) * kazu.at(2) * kazu.at(4));
ans += (kazu.at(1) * kazu.at(3) * kazu.at(4));
ans += (kazu.at(2) * kazu.at(3) * kazu.at(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 | import itertools
def myAnswer(N:int,S:list) -> int:
ans = 0
dic = {}
for s in S:
if(s[0] in dic.keys()):
dic[s[0]] += 1
else:
dic[s[0]] = 1
for c in itertools.combinations(dic.values(),3):
ans += c[0]*c[1]*c[2]
return ans
def modelAnswer():
return
def main():
N = int(input())
S = [input() for _ in range(N)]
print(myAnswer(N,S[:]))
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> name_count(5, 0);
for (int i = 0; i < (int)(N); i++) {
string S;
cin >> S;
if (S[0] == 'M')
name_count[0]++;
else if (S[0] == 'A')
name_count[1]++;
else if (S[0] == 'R')
name_count[2]++;
else if (S[0] == 'C')
name_count[3]++;
else if (S[0] == 'H')
name_count[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 += name_count[i] * name_count[j] * name_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 | from itertools import combinations
# input
N = int(input())
S = [input()[0] for i in range(N)]
# check
cnt = 0
MARCH = ["M", "A", "R", "C", "H"]
tops = [s for s in S if s in MARCH]
for c in combinations(tops, 3):
if len(set(tops)) == 3:
cnt += 1
print(cnt) |
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, march[5] = {0};
long long int ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M') march[0]++;
if (S[0] == 'A') march[1]++;
if (S[0] == 'R') march[2]++;
if (S[0] == 'C') march[3]++;
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;
int n;
long long ans = 0;
map<char, int> m;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
m[s[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 += m[c[i]] * m[c[j]] * m[c[k]];
}
cout << 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 | UNKNOWN | #include <bits/stdc++.h>
int main() {
int n, i, j;
int count[5] = {0, 0, 0, 0, 0};
int zen = 0;
int gou = 0, ans = 0, kai = 1, koi = 1;
scanf("%d", &n);
char s[11];
for (i = 0; i < n; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
count[0]++;
zen++;
break;
case 'A':
count[1]++;
zen++;
break;
case 'R':
count[2]++;
zen++;
break;
case 'C':
count[3]++;
zen++;
break;
case 'H':
count[4]++;
zen++;
break;
}
}
for (i = 0; i < 5; i++) {
if (count[i] > 0) {
gou++;
}
}
for (i = zen - 2; i <= zen; ++i) {
kai = kai * i;
}
ans = kai / 6;
for (i = 0; i < 5; i++) {
koi = 1;
if (count[i] == 2) {
ans = ans - (zen - count[i]);
} else if (count[i] > 2) {
for (j = count[i] - 1; j <= count[i]; ++j) {
koi = koi * j;
}
ans = ans - (koi / 6);
ans = ans - (koi / 2) * (zen - count[i]);
}
}
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 | python3 | from itertools import combinations
N = int(input())
S = [input()[0] for i in range(N)]
comb = combinations(S, 3)
ans = 0
for i in list(comb):
cnt = 0
if i.count("M") > 1:
continue
if i.count("A") > 1:
continue
if i.count("R") > 1:
continue
if i.count("C") > 1:
continue
if i.count("H") > 1:
continue
cnt += i.count("M")
cnt += i.count("A")
cnt += i.count("R")
cnt += i.count("C")
cnt += i.count("H")
if cnt == 3:
ans += 1
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;
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> cnt(5);
int sum = 0;
for (int i = 0; i < N; i++) {
string T;
cin >> T;
if (T[0] == 'M')
cnt[0]++;
else if (T[0] == 'A')
cnt[1]++;
else if (T[0] == 'R')
cnt[2]++;
else if (T[0] == 'C')
cnt[3]++;
else if (T[0] == 'H')
cnt[4]++;
}
long long int ans = 0;
ans += cnt[0] * cnt[1] * cnt[2];
ans += cnt[0] * cnt[1] * cnt[3];
ans += cnt[0] * cnt[1] * cnt[4];
ans += cnt[0] * cnt[2] * cnt[3];
ans += cnt[0] * cnt[2] * cnt[4];
ans += cnt[0] * cnt[3] * cnt[4];
ans += cnt[1] * cnt[2] * cnt[3];
ans += cnt[1] * cnt[2] * cnt[4];
ans += cnt[1] * cnt[3] * cnt[4];
ans += cnt[2] * cnt[3] * cnt[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 | 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 * r_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
count += m_count * c_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;
int main() {
int n, a[5];
long int ans = 0;
cin >> n;
string s[n];
for (int i = 0; i < 5; i++) {
a[i] = 0;
}
for (long int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'A') {
a[0]++;
}
if (s[i][0] == 'C') {
a[1]++;
}
if (s[i][0] == 'H') {
a[2]++;
}
if (s[i][0] == 'M') {
a[3]++;
}
if (s[i][0] == 'R') {
a[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 += a[i] * a[j] * a[k];
}
}
}
cout << 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, su = 0;
map<char, int> m;
map<string, int> g;
string s;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
cin >> s;
if ((s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') &&
g[s] != -1) {
m[s[0]]++;
g[s] = -1;
}
}
if (m['M'] != 0 && m['A'] != 0 && m['R'] != 0) {
su += (m['M'] * m['A'] * m['R']);
}
if (m['M'] != 0 && m['C'] && m['H']) {
su += (m['M'] * m['C'] * m['H']);
}
if (m['M'] != 0 && m['A'] && m['H']) {
su += (m['M'] * m['A'] * m['H']);
}
if (m['M'] != 0 && m['R'] && m['H']) {
su += (m['M'] * m['H'] * m['R']);
}
if (m['M'] != 0 && m['R'] && m['C']) {
su += (m['M'] * m['R'] * m['C']);
}
if (m['M'] != 0 && m['C'] && m['A']) {
su += (m['M'] * m['C'] * m['A']);
}
if (m['R'] != 0 && m['A'] != 0 && m['C'] != 0) {
su += (m['A'] * m['R'] * m['C']);
}
if (m['A'] != 0 && m['R'] && m['H']) {
su += (m['A'] * m['R'] * m['H']);
}
if (m['C'] != 0 && m['A'] != 0 && m['H'] != 0) {
su += (m['A'] * m['C'] * m['H']);
}
if (m['H'] != 0 && m['C'] != 0 && m['R'] != 0) {
su += (m['R'] * m['C'] * m['H']);
}
{ cout << su << 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 | python3 | n=int(input())
march=[0,0,0,0,0]
for i in range(n):
s=input()
if s[0]=="M":
march[0]+=1
elif s[0]=="A":
march[1]+=1
elif s[0]=="R":
march[2]+=1
elif s[0]=="C":
march[3]+=1
elif s[0]=="H":
march[4]+=1
ans=1
if march.count(0)>3:
print(0)
elif march.count(0)==2:
for i in march:
if i!=0:
ans*=i
print(ans)
elif march.count(0)==1:
ans=4
for i in march:
if i!=0:
ans+=(i-1)*3
print(ans)
elif march.count(0)==0:
ans=10
for i in march:
if i!=0:
ans+=(i-1)*6
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;
using ll = long long;
int main() {
int N;
cin >> N;
string ma = "MARCH";
int c[5] = {0};
vector<string> S(N);
for (int i = 0; i < (N); ++i) {
cin >> S[i];
for (int j = 0; j < 5; ++j) {
if (S[i][0] == ma[j]) {
c[j]++;
}
}
}
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; ++k) {
ans += c[i] * c[j] * 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;
int main() {
int n;
cin >> n;
int cnt[5] = {0, 0, 0, 0, 0};
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') {
cnt[0]++;
} else if (s[i][0] == 'A') {
cnt[1]++;
} else if (s[i][0] == 'R') {
cnt[2]++;
} else if (s[i][0] == 'C') {
cnt[3]++;
} else if (s[i][0] == 'H') {
cnt[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 += cnt[i] * cnt[j] * cnt[k];
}
}
}
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 | python3 | n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
s = input()
if s[0] == "M":
m += 1
if s[0] == "A":
a += 1
if s[0] == "R":
r += 1
if s[0] == "C":
c += 1
if s[0] == "H":
H += 1
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+r*c*h+a*c*h
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())
s = [None for x in range(n) ]
march = "MARCH"
march_list = [0 for x in range(5)]
for i in range(n):
s[i] = input()
if s[i][0] in march:
march_list[march.find(s[i][0])] += 1
ans = 0
for i in range(n):
for j in range(i+1,n+1):
for k in range(j+1,n):
ans += march_list[i] * march_list[j] * march_list[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 | python3 | import itertools
n = int(input())
l = [0]*n
for i in range(n):
s = input()
if s[0] == "M":
l[0] += 1
if s[0] == "A":
l[1] += 1
if s[0] == "R":
l[2] += 1
if s[0] == "C":
l[3] += 1
if s[0] == "H":
l[4] += 1
ans = 0
for a,b,c in list(itertools.combinations(l,3)):
ans += a*b*c
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 m, a, r, c, h;
int d[5];
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() {
string s;
int n;
cin >> n;
for (int i = 0; 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++;
}
d[0] = m, d[1] = a, d[2] = r, d[3] = c, d[4] = h;
int res = 0;
for (int i = 0; i < 10; i++) res += d[p[i]] * d[q[i]] * d[R[i]];
cout << 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 | UNKNOWN | macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}
fn main() {
input! {
n: usize,
_s: [String; n]
}
let s: Vec<_> = _s.iter().map(|x| x.as_bytes()).collect();
let mut march = vec![0; 5];
for &s in s.iter() {
match s[0] {
b'M' => march[0] += 1,
b'A' => march[1] += 1,
b'R' => march[2] += 1,
b'C' => march[3] += 1,
b'H' => march[4] += 1,
_ => (),
}
}
let mut ans = 0;
for i in 0..5 {
for j in i+1..5 {
for k in j+1..5 {
ans += march[i]*march[j]*march[k];
}
}
}
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>
int main() {
int n;
scanf("%d", &n);
char name[11];
unsigned int c[5] = {0, 0, 0, 0, 0};
int i, j, k;
for (i = 0; i < n; i++) {
scanf("%s", name);
switch (name[0]) {
case 'M':
c[0]++;
break;
case 'A':
c[1]++;
break;
case 'R':
c[2]++;
break;
case 'C':
c[3]++;
break;
case 'H':
c[4]++;
break;
default:
break;
}
}
unsigned long long ans = 0;
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
for (k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
printf("%llu\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 | UNKNOWN | use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;
fn main() {
let n: usize = read();
let mut a = [0; 5];
for _ in 0..n {
match read::<String>().chars().next().unwrap() {
'M' => a[0] += 1,
'A' => a[1] += 1,
'R' => a[2] += 1,
'C' => a[3] += 1,
'H' => a[4] += 1,
_ => (),
}
}
let mut ans = 0;
for i in 0..3 {
for j in i + 1..4 {
for k in j + 1..5 {
ans += a[i] * a[j] * a[k];
}
}
}
println!("{}", ans);
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
let stdin = stdin();
let token: String = stdin
.lock()
.bytes()
.map(|b| b.unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().unwrap()
}
|
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 | #icnlude <bits/stdc++.h>
using namespace std;
int main() {
int m,a,r,c,h,n;
cin >> n;
m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
vector<string> name(n);
for(int i=0;i<n;i++){
cin >> name.at(i);
if(name.at(i).at(0) == 'M'){
m++;
}
else if(name.at(i).at(0) == 'A'){
a++;
}
else if(name.at(i).at(0) == 'R'){
r++;
}
else if(name.at(i).at(0) == 'C'){
c++;
}
else if(name.at(i).at(0) == 'H'){
h++;
}
}
long x;
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() {
int N;
cin >> N;
vector<int> S(5);
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
if ('M' == s[0]) {
S[0]++;
} else if ('A' == s[0]) {
S[1]++;
} else if ('R' == s[0]) {
S[2]++;
} else if ('C' == s[0]) {
S[3]++;
} else if ('H' == s[0]) {
S[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 += S[i] * S[j] * S[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 INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> v = {0, 0, 0, 0, 0};
for (int i = 0; i < (int)(n); i++) {
string s;
cin >> s;
if (s.at(0) == 'M') v.at(0)++;
if (s.at(0) == 'A') v.at(1)++;
if (s.at(0) == 'R') v.at(2)++;
if (s.at(0) == 'C') v.at(3)++;
if (s.at(0) == 'H') v.at(4)++;
}
int 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 += (v.at(i) * v.at(j) * v.at(k));
}
}
}
cout << 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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtC
{
class Program
{
static void Main(string[] args)
{
var N = ReadInt();
uint[] namesCount = {0, 0, 0, 0, 0};
List<char> head = new List<char>
{
'M', 'A', 'R', 'C', 'H'
};
for (int i = 0; i < N; i++)
{
var str = ReadString();
var index = head.IndexOf(str[0]);
if (index >= 0) namesCount[index]++;
}
ulong 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 += namesCount[i] * namesCount[j] * namesCount[k];
Out(count);
}
//最小公倍数
static int LCM(int num1, int num2)
{
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
static long LCM(long num1, long num2)
{
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
static int GCD(int num1, int num2)
{
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0)
{
a = b;
b = mod;
}
return b;
}
static long GCD(long num1, long num2)
{
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0)
{
a = b;
b = mod;
}
return b;
}
static int[] ReadIntArray()
{
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt()
{
return int.Parse(Console.ReadLine());
}
static long[] ReadLongArray()
{
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong()
{
return long.Parse(Console.ReadLine());
}
static string ReadString()
{
return Console.ReadLine();
}
static void Out(object o)
{
Console.WriteLine(o);
}
}
static class EnumerableExtension
{
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
{
foreach (var x in enumerable)
{
function(x);
}
}
}
class PriorityQueue<T>
{
}
} |
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 initial[5] = {};
void divide(string s) {
if (s[0] == 'M')
initial[0]++;
else if (s[0] == 'A')
initial[1]++;
else if (s[0] == 'R')
initial[2]++;
else if (s[0] == 'C')
initial[3]++;
else if (s[0] == 'H')
initial[4]++;
}
int main() {
int n;
long long ans = 0;
cin >> n;
string name[n];
for (int i = 0; i < n; i++) cin >> name[i];
for (int i = 0; i < n; i++) divide(name[i]);
for (int i = 1; i < 5; i++) {
for (int j = 0; j < i; j++) {
for (int k = (i + 1); k < 6; k++) {
ans += (initial[i] * initial[j] * initial[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 | int main(){
int N;
cin >> N;
set<char> cset = {'M', 'A', 'R', 'C', 'H'};
map<char, long int> m;
for(int i=0; i<N; ++i){
string s;
cin >> s;
if(cset.find(s[0]) != cset.end()){
if(m.find(s[0]) == m.end()) m[s[0]] = 1;
else m[s[0]]++;
}
}
vector<long int> v;
for(auto x: m){
v.push_back(x.second);
cout << x.first << " " << x.second << endl;
}
long int ans = 0;
for(int i=0; i<v.size(); ++i){
for(int j=i+1; j<v.size(); ++j){
for(int k=j+1; k<v.size(); ++k){
ans += v[i] * v[j] * v[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;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
map<char, int> mp;
vector<char> march = {'M', 'A', 'R', 'C', 'H'};
for (char c : march) mp[c] = 0;
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
mp[s.at(0)]++;
}
ll 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 += mp.at(march.at(i)) * mp.at(march.at(j)) * mp.at(march.at(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 mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < (n); i++) cin >> s[i];
vector<long long int> cnt(5);
for (int i = 0; i < (n); i++) {
string c = s[i];
if (c[0] == 'M') cnt[0]++;
if (c[0] == 'A') cnt[1]++;
if (c[0] == 'R') cnt[2]++;
if (c[0] == 'C') cnt[3]++;
if (c[0] == 'H') cnt[4]++;
}
sort(cnt.begin(), cnt.end());
int z = 0, one = 0;
for (int i = 0; i < (5); i++) {
if (cnt[i] > 0) z++;
if (cnt[i] == 1) one++;
}
long long int ans;
if (z < 3) {
cout << 0 << endl;
return 0;
} else {
if (one == z) {
ans = one * (one - 1) * (one - 2) / (3 * 2);
cout << ans << endl;
return 0;
} else if (one >= 3) {
ans = z * (z - 1) * (z - 2) / 6;
ans = ans * cnt[3] * cnt[4];
ans -= one * (one - 1) * (one - 2) / 6;
cout << ans << endl;
return 0;
} else {
ans = z * (z - 1) * (z - 2) / 6;
for (int i = 0; i < (5); i++) {
if (cnt[i] > 0) ans *= cnt[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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int a = 0, m = 0, r = 0, c = 0, h = 0, i;
long answer, num;
scanf("%d", &num);
char array[10];
for (i = 1; i <= num; i++) {
scanf("%s", &array);
if (array[0] == 'M') m++;
if (array[0] == 'A') a++;
if (array[0] == 'R') r++;
if (array[0] == 'C') c++;
if (array[0] == 'H') h++;
}
answer = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * c * h + r * c * h + a * r * h;
printf("%d", answer);
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 dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
map<char, int> S;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[5];
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
string s;
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;
for (int i = 0; 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];
}
}
}
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;
bool check(int a, int b) { return a > b; }
int solve(int cnt, int x, int y, vector<int> c, vector<int> s, vector<int> f) {
if (cnt > cnt / f[x] * f[x]) {
cnt = cnt / f[x] * f[x] + f[x];
} else {
cnt = cnt / f[x] * f[x];
}
if (cnt < s[x]) {
cnt = s[x];
}
cnt += c[x];
if (x + 1 == y) {
return cnt;
} else {
return solve(cnt, x + 1, y, c, s, f);
}
}
int main() {
long long int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s.begin(), s.end());
long long int cnt[5] = {};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M' || s[i][0] == 'A' || s[i][0] == 'R' || s[i][0] == 'C' ||
s[i][0] == 'H') {
if (i != 0) {
if (s[i] != s[i - 1]) {
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
} else {
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
}
}
long long int ans = 0;
long long int tmp;
for (int i = 0; i < 10; i++) {
tmp = 1;
if (i <= 5) {
if (cnt[0] == 0) {
continue;
}
tmp *= cnt[0];
}
if (i <= 2 || 5 <= i && i <= 7) {
if (cnt[1] == 0) {
continue;
}
tmp *= cnt[1];
}
if (i == 0 || i == 3 || i == 4 || 6 <= i && i <= 7 || i == 9) {
if (cnt[2] == 0) {
continue;
}
tmp *= cnt[2];
}
if (i == 1 || i == 3 || i == 5 || i == 6 || i == 8 || i == 9) {
if (cnt[3] == 0) {
continue;
}
tmp *= cnt[3];
}
if (i == 2 || i == 4 || i == 5 || 7 <= i && i <= 9) {
if (cnt[4] == 0) {
continue;
}
tmp *= cnt[4];
}
ans += tmp;
}
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;
char ini[2560];
int main(void) {
long long m[100];
long long n;
string name;
for (long long i = 0; i < 255; i++) ini[i] = 5;
ini['M'] = 0;
ini['A'] = 1;
ini['R'] = 2;
ini['C'] = 3;
ini['H'] = 4;
for (long long i = 0; i < 7; i++) m[i] = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> name;
m[ini[name[0]]]++;
}
long long cnt = 0;
for (long long i = 0; i < n - 2; i++) {
for (long long j = i + 1; j < n - 1; j++) {
for (long long k = j + 1; k < n; k++) {
cnt += m[i] * m[j] * m[k];
}
}
}
cout << cnt << 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.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;
class Main{
static FastScanner s=new FastScanner(System.in);
void solve(){
String f="MARCH";
int[]c=new int[5];
STRS(gInt())
.mapToInt(o->f.indexOf(o.charAt(0)))
.filter(o->o>=0)
.forEach(o->++c[o]);
System.err.println(Arrays.toString(c));
long r=0;
for(int i=0;i<5;++i)
for(int j=i+1;j<5;++j)
for(int k=j+1;k<5;++k)
r+=c[i]*c[j]*c[k];
System.out.println(r);
}
public static void main(String[] $){
new Main().solve();
}
int gInt(){
return s.nextInt();
}
long gLong(){
return s.nextLong();
}
double gDouble(){
return Double.parseDouble(s.next());
}
SupplyingIterator<Integer> ints(int n){
return new SupplyingIterator<>(n,this::gInt);
}
SupplyingIterator<Long> longs(int n){
return new SupplyingIterator<>(n,this::gLong);
}
SupplyingIterator<Double> doubles(int n){
return new SupplyingIterator<>(n,this::gDouble);
}
SupplyingIterator<String> strs(int n){
return new SupplyingIterator<>(n,s::next);
}
Range rep(int i){
return Range.rep(i);
}
Range rep(int f,int t,int d){
return Range.rep(f,t,d);
}
Range rep(int f,int t){
return rep(f,t,1);
}
Range rrep(int f,int t){
return rep(t,f,-1);
}
IntStream INTS(int n){
return IntStream.generate(this::gInt).limit(n);
}
Stream<String> STRS(int n){
return Stream.generate(s::next).limit(n);
}
}
class FastScanner{
private final BufferedInputStream in;
private static final int bufSize =1<<16;
private final byte buf[] =new byte[bufSize];
private int i =bufSize,k=bufSize;
private final StringBuilder str =new StringBuilder();
FastScanner(InputStream in){
this.in=new BufferedInputStream(in,bufSize);
}
int nextInt(){
return (int)nextLong();
}
long nextLong(){
int c;
long x=0;
boolean sign=true;
while((c=nextChar())<=32)
;
if(c=='-'){
sign=false;
c=nextChar();
}
if(c=='+'){
c=nextChar();
}
while(c>='0'){
x=x*10+(c-'0');
c=nextChar();
}
return sign?x:-x;
}
private int nextChar(){
if(i==k){
try{
k=in.read(buf,i=0,bufSize);
}catch(IOException e){
System.exit(-1);
}
}
return i>=k?-1:buf[i++];
}
String next(){
int c;
str.setLength(0);
while((c=nextChar())<=32&&c!=-1)
;
if(c==-1)
return null;
while(c>32){
str.append((char)c);
c=nextChar();
}
return str.toString();
}
String nextLine(){
int c;
str.setLength(0);
while((c=nextChar())<=32&&c!=-1)
;
if(c==-1)
return null;
while(c!='\n'){
str.append((char)c);
c=nextChar();
}
return str.toString();
}
}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
private int remain;
Supplier<T> supplier;
SupplyingIterator(int t,Supplier<T> supplier){
this.remain=t;
this.supplier=supplier;
}
@Override
public Iterator<T> iterator(){
return this;
}
@Override
public boolean hasNext(){
return remain>0;
}
@Override
public T next(){
--remain;
return supplier.get();
}
}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
public final int from,to,d;
private int cur;
Range(int from,int to,int d){
this.from=from;
this.cur=from-d;
this.to=to;
this.d=d;
}
Range(int n){
this(0,n-1,1);
}
@Override
public Iterator<Integer> iterator(){
return this;
}
@Override
public boolean hasNext(){
return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
}
@Override
public int nextInt(){
return cur+=d;
}
protected final int CHARACTERISTICS=Spliterator.SIZED|Spliterator.DISTINCT|Spliterator.IMMUTABLE|Spliterator.NONNULL;
@Override
public Spliterator.OfInt spliterator(){
return Spliterators.spliterator(this,(to-from)/d+1,CHARACTERISTICS);
}
IntStream stream(){
return d==1?IntStream.rangeClosed(from,to):java.util.stream.StreamSupport.intStream(this.spliterator(),false);
}
static Range rep(int i){
return new Range(i);
}
static Range rep(int f,int t,int d){
return new Range(f,t,d);
}
static Range rep(int f,int t){
return rep(f,t,1);
}
static Range rrep(int f,int t){
return rep(t,f,-1);
}
}
|
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 name[15];
int a[10];
void solve(char ch) {
if (ch == 'M')
a[0]++;
else if (ch == 'A')
a[1]++;
else if (ch == 'R')
a[2]++;
else if (ch == 'C')
a[3]++;
else if (ch == 'H')
a[4]++;
}
int main() {
long long n;
long long i;
while (scanf("%lld", &n) != EOF) {
memset(a, 0, sizeof(a));
for (i = 0; i < n; i++) {
scanf("%s", name);
solve(name[0]);
}
long long num1 = 0, num2 = 0, num3 = 0;
long long ans = 0;
for (i = 0; i < 5; i++) {
num1 += a[i];
if (a[i] >= 2) num2++;
if (a[i] >= 3) num3++;
}
for (i = 0; i < 5; i++) {
if (a[i] >= 2) {
ans += (a[i] * a[i] - 1) / 2 * (num1 - a[i]);
}
}
printf("%lld\n", num1 * (num1 - 1) * (num1 - 2) / 6 - ans - num3);
}
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;
bool che(string s) {
return s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<string> s(n);
for (long long i = (0); i < (n); i++) cin >> s[i];
long long ans = 0;
for (long long i = (0); i < (n); i++)
for (long long j = (i + 1); j < (n); j++)
for (long long k = (j + 1); k < (n); k++) {
bool f = che(s[i]) && che(s[j]) && che(s[k]);
bool g = s[i][0] != s[j][0] && s[j][0] != s[k][0] && s[k][0] != s[i][0];
if (f && g) ans++;
}
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
sc.nextLine();
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
if (!s.matches("^[MARCH].*$")) {
continue;
}
inc(map, s.substring(0, 1));
}
int ans = 0;
List<Integer> list = new ArrayList<>(map.values());
for (int i = 0; i < list.size() - 2; i++) {
for (int j = i + 1; j < list.size() - 1; j++) {
for (int k = j + 1; k < list.size(); k++) {
int c = 1;
c *= list.get(i).intValue();
c *= list.get(j).intValue();
c *= list.get(k).intValue();
ans += c;
}
}
}
System.out.println(ans);
}
}
private static final <T> void inc(Map<T, Integer> map, T key) {
Integer val = map.get(key);
if (null == val) {
val = Integer.valueOf(1);
} else {
val = Integer.valueOf(val.intValue() + 1);
}
map.put(key, val);
}
}
|
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 b[1001];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
cout << n - 3;
}
|
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 = 1000000007;
const int INF = 2147483647;
int main(void) {
int N;
cin >> N;
string S[N];
for (int i = 0; i < (N); ++i) cin >> S[i];
int m, a, r, c, h;
m = a = r = c = h = 0;
for (int i = 0; i < (N); ++i) {
if (S[i][0] == 'M')
++m;
else if (S[i][0] == 'A')
++a;
else if (S[i][0] == 'R')
++r;
else if (S[i][0] == 'C')
++c;
else if (S[i][0] == 'H')
++h;
}
int ans = pow(m + a + r + c + h, 3) -
3 * (m + a + r + c + h) * (m * m + a * a + r * r + c * c + h * h);
ans += 2 * (pow(m, 3) + pow(a, 3) + pow(r, 3) + pow(c, 3) + pow(h, 3));
ans /= 6;
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(void) {
int n, M = 0, A = 0, R = 0, C = 0, H = 0, ans = 0;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M')
M++;
else if (s[i][0] == 'A')
A++;
else if (s[i][0] == 'R')
R++;
else if (s[i][0] == 'C')
C++;
else 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 | java | import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Map<Character, Set<String>> map = new HashMap<>();
for(int i =0; i < n; i++){
String s = sc.next();
char c = s.charAt(0);
if(c == 'M' || c == 'A' || c == 'R' || c == 'C' || c=='H'){
if(!map.containsKey(c)) map.put(c, new HashSet<>());
map.get(c).add(s);
}
}
if(map.keySet().size() < 3){
System.out.println(0);
return;
}
long l = 0;
int keySize = map.keySet().size();
List<Character> list = new ArrayList<>(map.keySet());
long x;
for(int i =0; i< list.size() -2; i++){
for(int j =i+1; j < list.size()-1; j++){
for(int k = j+1; k < list.size(); k++){
x =1;
x *= map.get(list.get(i)).size() * map.get(list.get(j)).size() * map.get(list.get(k)).size();
l +=x;
}
}
}
System.out.println(l);
}
}
|
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 | from collections import Counter
import itertools
n = int(input())
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]
if len(l) < 3:
print(0)
else:
c = Counter(l)
cl = list(itertools.combinations(c,3))
ans = 0
for i in cl:
ans += c[i[0]] * c[i[1]] * c[i[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;
char names[10000][11];
long long cnt[26];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> names[i];
++cnt[names[i][0] - 'A'];
}
long long ans = cnt[('M' - 'A')] * cnt[('A' - 'A')] * cnt[('R' - 'A')] +
cnt[('M' - 'A')] * cnt[('A' - 'A')] * cnt[('C' - 'A')] +
cnt[('M' - 'A')] * cnt[('A' - 'A')] * cnt[('H' - 'A')] +
cnt[('M' - 'A')] * cnt[('R' - 'A')] * cnt[('C' - 'A')] +
cnt[('M' - 'A')] * cnt[('R' - 'A')] * cnt[('H' - 'A')] +
cnt[('M' - 'A')] * cnt[('C' - 'A')] * cnt[('H' - 'A')] +
cnt[('A' - 'A')] * cnt[('R' - 'A')] * cnt[('C' - 'A')] +
cnt[('A' - 'A')] * cnt[('R' - 'A')] * cnt[('H' - 'A')] +
cnt[('A' - 'A')] * cnt[('C' - 'A')] * cnt[('H' - 'A')] +
cnt[('R' - 'A')] * cnt[('C' - 'A')] * cnt[('H' - '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;
const int INF = 1e9;
const long long LINF = 1e18;
void solve_A();
void solve_B();
void solve_C();
void solve_D();
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
solve_C();
return 0;
}
void solve_A() {
long long N;
cin >> N;
cout << N / 3 << endl;
}
void solve_B() {
long long N;
cin >> N;
vector<char> S(N);
for (auto &in : S) cin >> in;
bool f1, f2, f3, f4;
f1 = f2 = f3 = f4 = false;
for (int i = 0; i < N; i++) {
if (S[i] == 'P') f1 = true;
if (S[i] == 'W') f2 = true;
if (S[i] == 'G') f3 = true;
if (S[i] == 'Y') f4 = true;
}
if (f4) {
cout << "Four" << endl;
} else {
cout << "Three" << endl;
}
}
void solve_C() {
long long N;
cin >> N;
vector<string> S(N);
for (auto &in : S) cin >> in;
long long MARCH[5] = {};
char C[5] = {'C', 'A', 'R', 'C', 'H'};
for (int i = 0; i < N; i++) {
for (int j = 0; j < 5; j++) {
if (S[i][0] == C[j]) MARCH[j]++;
}
}
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;
}
void solve_D() {}
|
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 = 1e9;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> v = {0, 0, 0, 0, 0};
for (int i = 0; i < (int)(n); i++) {
string s;
cin >> s;
if (s.at(0) == 'M') v.at(0)++;
if (s.at(0) == 'A') v.at(1)++;
if (s.at(0) == 'R') v.at(2)++;
if (s.at(0) == 'C') v.at(3)++;
if (s.at(0) == 'H') v.at(4)++;
}
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; k++) {
ans += (v.at(i) * v.at(j) * v.at(k));
}
}
}
cout << 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 INF = 1e12;
const int MOD = 1e9 + 7;
const double pi = acos(-1);
int main() {
int n;
cin >> n;
vector<int> name(5);
for (long long i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') name[0]++;
if (s[0] == 'A') name[1]++;
if (s[0] == 'R') name[2]++;
if (s[0] == 'C') name[3]++;
if (s[0] == 'H') name[4]++;
}
long long ans = 0;
for (long long i = 0; i < (5); i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += name[i] * name[j] * name[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;
string m = "MARCH";
int main() {
int N;
cin >> N;
int p[5]{};
string S;
for (int i = 0; i != N; ++i) {
cin >> S;
auto j = m.find(S[0]);
if (j != m.npos) {
++p[j];
}
}
long long ans{};
for (int i = 0; i != 3; ++i) {
for (int j = i + 1; j != 4; ++j) {
for (int k = j + 1; k != 5; ++k) {
ans += p[i] * p[j] * p[k];
}
}
}
cout << ans << endl;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.