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>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
int main() {
ll n, cnt = 0;
char comb[2];
cin >> n;
set<char> constChar{'M', 'A', 'R', 'C', 'H'};
vector<string> s(n);
for (long i = 0; i < n; i++) {
cin >> s[i];
}
for (long i = 0; i < n - 2; i++) {
if (constChar.find(s[i][0]) != constChar.end()) {
comb[0] = s[i][0];
for (long j = i; j < n - 1; j++) {
if (constChar.find(s[j][0]) != constChar.end() && comb[0] != s[j][0]) {
comb[1] = s[j][0];
for (long k = j; k < n; k++) {
if (constChar.find(s[k][0]) != constChar.end() &&
comb[0] != s[k][0] && comb[1] != s[k][0]) {
cnt++;
}
}
}
}
}
}
cout << cnt << '\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;
int main() {
int N;
cin >> N;
char S[100000][10];
int n[5] = {};
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M')
n[0]++;
else if (S[i][0] == 'A')
n[1]++;
else if (S[i][0] == 'R')
n[2]++;
else if (S[i][0] == 'C')
n[3]++;
else if (S[i][0] == 'H')
n[4]++;
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += n[i] * n[j] * n[k];
}
}
}
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
std::vector<std::string> name;
for (int i = 0; i < N; i++) {
std::string str;
std::cin >> str;
name.push_back(str);
}
int count = 0;
for (int i = 0; i < N; i++) {
int firstID = -1;
switch (name[i][0]) {
case 'M':
case 'A':
case 'R':
case 'C':
case 'H':
firstID = i;
break;
}
if (firstID != -1) {
for (int j = i; j < N; j++) {
int secondID = -1;
switch (name[j][0]) {
case 'M':
case 'A':
case 'R':
case 'C':
case 'H':
if (name[firstID][0] != name[j][0]) {
secondID = j;
}
break;
}
if (secondID != -1) {
for (int k = j; k < N; k++) {
int thirdID = -1;
switch (name[k][0]) {
case 'M':
case 'A':
case 'R':
case 'C':
case 'H':
if (name[firstID][0] != name[k][0] &&
name[secondID][0] != name[k][0]) {
thirdID = k;
count++;
}
break;
}
}
}
}
}
}
std::cout << count << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long cnt = 0;
int main() {
int n;
cin >> n;
string s[n];
string t;
map<char, int> mp;
for (int i = 0; i < n; i++) {
cin >> t;
char c = t.at(0);
mp[c]++;
}
long long ans = 0;
ans += mp['M'] * mp['A'] * mp['R'];
ans += mp['M'] * mp['A'] * mp['C'];
ans += mp['M'] * mp['A'] * mp['H'];
ans += mp['M'] * mp['R'] * mp['C'];
ans += mp['M'] * mp['R'] * mp['H'];
ans += mp['M'] * mp['C'] * mp['H'];
ans += mp['A'] * mp['R'] * mp['C'];
ans += mp['A'] * mp['R'] * mp['H'];
ans += mp['A'] * mp['C'] * mp['H'];
ans += mp['R'] * mp['C'] * mp['H'];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
N = int(input())
name = [input() for i in range(N)]
nameList = [0 for i in range(5)]
for n in name:
if n[0] == 'M':
nameList[0] += 1
elif n[0] == 'A':
nameList[1] += 1
elif n[0] == 'R':
nameList[2] += 1
elif n[0] == 'C':
nameList[3] += 1
elif n[0] == 'H':
nameList[4] += 1
ans = [i for i in nameList if i != 0]
n = len(ans)
r = 3
a = 0
if len(ans) > 0:
a = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in ans:
a *= i
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 | java | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int num[] = new int[5];
for (int i = 0; i < N; i++) {
String S = sc.next();
switch (S.charAt(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;
}
}
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 += num[i] * num[j] * num[k];
}
}
}
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<ll> vec(5);
string str;
for (int(i) = (0); (i) < (n); (i)++) {
cin >> str;
if (str[0] == 'M') vec[0]++;
if (str[0] == 'A') vec[1]++;
if (str[0] == 'R') vec[2]++;
if (str[0] == 'C') vec[3]++;
if (str[0] == 'H') vec[4]++;
}
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 += (vec[i] * vec[j] * vec[k]);
cout << i << " " << j << " " << k << endl;
}
}
}
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 N;
scanf("%d\n", &N);
char S[N + 1];
for (int i = 0; i < N; i++) {
char name[11];
scanf("%s", name);
S[i] = name[0];
}
int M, A, R, C, H;
M = 0, A = 0, R = 0, C = 0, H = 0;
for (int j = 0; j < N; j++) {
switch (S[j]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
C++;
break;
}
}
int 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("%d\n", 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 | 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 < 5; 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 | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
int main(void) {
int N;
cin >> N;
vector<int> march(5);
for (int i = 0; i < N; i++) {
string S;
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]++;
}
ll sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += march[i] * march[j] * march[k];
}
}
}
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() {
int n, ans = 0;
string temp;
char target[5] = {'M', 'A', 'R', 'C', 'H'};
int count[5] = {0, 0, 0, 0, 0};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
for (int j = 0; j < 5; j++) {
if (temp[0] == target[j]) count[j]++;
}
}
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 += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;
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)*}
};
($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
let mut $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, [ $t:tt ]) => {
{
let len = read_value!($next, usize);
(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
}
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, bytes) => {
read_value!($next, String).into_bytes()
};
($next:expr, usize1) => {
read_value!($next, usize) - 1
};
($next:expr, $t:ty) => {
$next().parse::<$t>().expect("Parse error")
};
}
fn main() {
input!{
n: usize,
mut s: [chars; n],
}
let mut res = 0;
let mut cnt = vec![0; 5];
let P = vec![0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
let Q = vec![1, 1, 1, 2, 2, 3, 2, 3, 2, 3];
let R = vec![2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
for c in s {
let s_ = c[0];
match s_ {
'M' => cnt[0] += 1,
'A' => cnt[1] += 1,
'R' => cnt[2] += 1,
'C' => cnt[3] += 1,
'H' => cnt[4] += 1,
_ => continue,
}
}
for i in 0..10 {
res += (cnt[P[i]] * cnt[Q[i]] * cnt[R[i]]);
}
println!("{}", res);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int fac(int n) {
if (n == 0)
return 1;
else
return fac(n - 1) * n;
}
int main() {
int n;
cin >> n;
vector<int> a(5, 0);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s.at(0) == 'M')
a.at(0)++;
else if (s.at(0) == 'A')
a.at(1)++;
else if (s.at(0) == 'R')
a.at(2)++;
else if (s.at(0) == 'C')
a.at(3)++;
else if (s.at(0) == 'H')
a.at(4)++;
}
long long int ans;
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.at(i) * a.at(j) * a.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 | python3 | import itertools
def main():
N = int(input().strip())
S = []
for _ in range(N):
in_s = (input().strip())[0]
if in_s in ['M','A','R','C','H']:
S.append(in_s)
if not S:
return 0
pat = itertools.combinations(S, 3);
count = 0
for x in pat:
if len(x) == len(set(x)):
count += 1
return count
if __name__ == '__main__':
print(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;
template <typename T>
T dup(T x, T y) {
return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;
constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;
void Main() {
int n;
cin >> n;
vint v(5, 0);
set<string> st;
const string t = "MARCH";
for (int i = 0; i < (int)(n); ++i) {
string s;
cin >> s;
for (int j = 0; j < (int)(t.length()); ++j) {
if (s.front() == t[j] && st.count(s) == 0) {
++v[j];
st.insert(s);
}
}
}
ll ans = 0;
for (int i = 0; i < (int)(5); ++i) {
for (int j = (i + 1); j < (int)(5); ++j) {
for (int k = (j + 1); k < (int)(5); ++k) {
ans += v[i] * v[j] * v[k];
}
}
}
cout << ans << endl;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
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 cou[5];
char check[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) {
cou[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 5; j++) {
if (s[i][0] == check[j]) {
cou[j]++;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i == j) {
break;
}
for (int m = 0; m < 5; m++) {
if (j == m || i == m) {
break;
}
ans += cou[i] * cou[j] * cou[m];
}
}
}
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() {
map<char, int> mp;
mp['M'] = 1;
mp['A'] = 2;
mp['R'] = 3;
mp['C'] = 4;
mp['H'] = 5;
vector<int> x(6, 0);
int n;
cin >> n;
string s;
for (int i = (0); i < (n); i++) {
cin >> s;
x[mp[s[0]]]++;
}
long long ans = 0;
for (int i = (1); i <= (5); i++) {
for (int j = (i + 1); j <= (5); j++) {
for (int k = (j + 1); k <= (5); k++) {
ans += x[i] * x[j] * x[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 | python2 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
N = input()
m,a,r,c,h = 0
for i in range(N):
S = raw_input()
if S[:1] == "M":
m += 1
elif S[:1] == "A":
a += 1
elif S[:1] == "R":
r += 1
elif S[:1] == "C":
c += 1
elif S[:1] == "H":
h += 1
print m*a*r+m*a*c+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | int main() {
long long n, a[5]={0,0,0,0,0}, r = 0;
scanf("%ld", &n);
for (int i = 0; i < n; i++) {
char s[10];
scanf("%s", 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]++;
}
}
int ans;
for ( int z = 0; z < 3; z++;) {
for ( int c = z+1; x < 4; x++){
for ( int v = c+1; v < 5; v++){
a[z]*a[c]*z[v] == ans;}}}}
printf(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;
using ll = long long;
using P = pair<int, int>;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> one, two, thr;
one = two = thr = vector<int>(10);
int tmp = 0;
for (int i = 0; i <= 2; ++i) {
for (int j = i + 1; j <= 3; ++j) {
for (int k = j + 1; k <= 4; ++k) {
one[tmp] = i;
two[tmp] = j;
thr[tmp] = k;
++tmp;
}
}
}
int m, a, r, c, h;
m = a = r = c = h = 0;
vector<int> d(5);
for (int i = 0; i < (int)(n); ++i) {
string s;
cin >> s;
if (s[0] == 'M') ++m;
if (s[0] == 'A') ++a;
if (s[0] == 'R') ++r;
if (s[0] == 'C') ++c;
if (s[0] == 'H') ++h;
}
d[0] = m;
d[1] = a;
d[2] = r;
d[3] = c;
d[4] = h;
ll ans = 0;
for (int i = 0; i < (int)(10); ++i) {
ans += d[one[i]] * d[two[i]] * d[thr[i]];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | // Created by liszt on 2019/07/27.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,MARCH[5]={0}; cin>>n;
vector<string> s(n);
for(int i=0;i<n;i++){
string S; cin>>S;
s[i]=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]++;
}
long long ans=0;
//MAR
ans+=MARCH[0]*MARCH[1]*MARCH[2];
//MAC
ans+=MARCH[0]*MARCH[1]*march[3];
//MAH
ans+=MARCH[0]*MARCH[1]*MARCH[4];
//MRC
ans+=MARCH[0]*MARCH[2]*MARCH[3];
//MRH
ans+=MARCH[0]*MARCH[2]*MARCH[4];
//MCH
ans+=MARCH[0]*MARCH[3]*MARCH[4];
//ARC
ans+=MARCH[1]*MARCH[2]*MARCH[3];
//ARH
ans+=MARCH[1]*MARCH[2]*MARCH[4];
//ACH
ans+=MARCH[1]*MARCH[3]*MARCH[4];
//RCH
ans+=MARCH[2]*MARCH[3]*MARCH[4];
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
string march = "MARCH";
int count = 0;
vector<int> data(5, 0);
for (int i = 0; i < N; i++) {
cin >> S;
for (char a : march) {
if (S.at(0) == a) data.at(0 + count)++;
count++;
}
}
cout << (long)data.at(2) * data.at(3) * data.at(4) +
data.at(1) * data.at(3) * data.at(4) +
data.at(1) * data.at(2) * data.at(4) +
data.at(1) * data.at(2) * data.at(3) +
data.at(0) * data.at(3) * data.at(4) +
data.at(0) * data.at(2) * data.at(4) +
data.at(0) * data.at(2) * data.at(3) +
data.at(0) * data.at(1) * data.at(4) +
data.at(0) * data.at(1) * data.at(3) +
data.at(0) * data.at(1) * data.at(2)
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
s = []
for i in range(n):
s.append(str(input()))
march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]
for i in range(n):
if s[i][0] in march:
march_num[march.index(s[i][0])] += 1
ans = 0
for i in range(len(s)-2):
for j in range(i+1,len(s)-1):
for k in range(j+1,len(s)):
ans += (march_num[i]*march_num[j]*march_num[k])
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<cstdio>
int count[5];
int combine[10][3] = {
{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}
};
int main()
{
int n
long long ans;
char str[15];
while(~scanf("%d",&n)){
ans = 0;
for(int i = 0; i<5; i++)count[i] = 0;
for(int i = 0; i<n; i++){
scanf("%s",str);
if(str[0] == 'M') count[0]++;//M
else if(str[0] == 'A') count[1]++;//A
else if(str[0] == 'R') count[2]++;//R
else if(str[0] == 'C') count[3]++;//C
else if(str[0] == 'H') count[4]++;//H
else continue;
}
for(int i = 0; i<9; i++){
ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];
}
printf("%lld\n",ans);
}
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
char name[100005][15];
int main() {
int n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
long long int ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name[i]);
if (name[i][0] == 'M') m++;
if (name[i][0] == 'A') a++;
if (name[i][0] == 'R') r++;
if (name[i][0] == 'C') c++;
if (name[i][0] == 'H') h++;
}
n = m + a + r + c + h;
if (n < 3) {
printf("0");
return 0;
}
ans = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) +
r * c * h;
printf("%lld", 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, i, arr[100001], s;
cin >> n;
if (n == 5)
cout << 2;
else if (n == 4)
cout << 0;
else
cout << 4;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string s[10005];
int a[10];
int n, i, j, k;
long long cnt = 0;
int main() {
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> s[i];
if (s[i][0] == 'M') a[1]++;
if (s[i][0] == 'A') a[2]++;
if (s[i][0] == 'R') a[3]++;
if (s[i][0] == 'C') a[4]++;
if (s[i][0] == 'H') a[5]++;
}
for (i = 1; i <= 3; ++i) {
while (a[i] == 0 && i < 3) ++i;
if (i == 3 && a[i] == 0) continue;
if (i > 3) continue;
for (j = i + 1; j <= 4; ++j) {
while (a[j] == 0 && j < 4) ++j;
if (j == 4 && a[j] == 0) continue;
if (j > 4) continue;
for (k = j + 1; k <= 5; ++k) {
while (a[k] == 0 && k < 5) ++k;
if (k == 5 && a[k] == 0) continue;
if (k > 5) continue;
cnt += a[i] * a[j] * a[k];
}
}
}
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
S={input() for i in range(N)}
count=0
for x in S:
for y in S-{x}:
for z in S-{x,y}:
A={x[0],y[0],z[0]}
if len(A)==3 and A<={'M','A','R','C','H'}:
count+=1
print(int(count/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 | java | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//入力
int N = sc.nextInt();
List<String> SList = new ArrayList<String>();
for (int i = 0; i < N; i++) {
String S = sc.next();
SList.add(S);
}
int flagM=0;
int countM=0;
int flagA=0;
int countA=0;
int flagR=0;
int countR=0;
int flagC=0;
int countC=0;
int flagH=0;
int countH=0;
Long answer = (long)0;
for (int i = 0; i < N; i++) {
if (SList.get(i).substring(0,1).equals("M")) {
flagM = 1;
countM++;
}
else if (SList.get(i).substring(0,1).equals("A")) {
flagA = 1;
countA++;
}
else if (SList.get(i).substring(0,1).equals("R")) {
flagR = 1;
countR++;
}
else if (SList.get(i).substring(0,1).equals("C")) {
flagC = 1;
countC++;
}
else if (SList.get(i).substring(0,1).equals("H")) {
flagH = 1;
countH++;
}
else {
}
}
if (flagM + flagA + flagR + flagC + flagH >2) {
answer = answer
+ (long)(countM * countA * countR)
+ (long)(countM * countA * countC)
+ (long)(countM * countA * countH)
+ (long)(countM * countR * countC)
+ (long)(countM * countR * countH)
+ (long)(countM * countC * countH)
+ (long)(countA * countR * countC)
+ (long)(countA * countR * countH)
+ (long)(countR * countC * countH);
}
System.out.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() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
int c[5] = {0, 0, 0, 0, 0};
unsigned long long ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
string tmp;
cin >> tmp;
switch (tmp[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;
}
}
for (int i = 0; i < 3; i++) {
if (c[i] == 0) continue;
for (int j = i + 1; j < 4; j++) {
if (c[j] == 0) continue;
for (int k = j + 1; k < 5; k++) {
if (c[k] == 0) continue;
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char a[15];
int c[10];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
memset(c, 0, sizeof(c));
while (n--) {
cin >> a;
if (a[0] == 'M') c[1]++;
if (a[0] == 'A') c[2]++;
if (a[0] == 'R') c[3]++;
if (a[0] == 'C') c[4]++;
if (a[0] == 'H') c[5]++;
}
long long ans = c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[2] * c[5] +
c[1] * c[3] * c[4] + c[1] * c[3] * c[5] + c[1] * c[4] * c[5] +
c[2] * c[3] * c[4] + c[2] * c[3] * c[5] + c[2] * c[4] * c[5] +
c[3] * c[4] * c[5];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<string> A(N);
long long a[100];
for (int i = 0; i < N; i++) {
cin >> A[i];
switch (A[i][0]) {
case 'M':
a[0]++;
break;
case 'A':
a[1]++;
break;
case 'R':
a[2]++;
break;
case 'C':
a[3]++;
break;
case 'H':
a[4]++;
break;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int l = j + 1; l < 5; l++) {
ans += a[i] * a[j] * a[l];
}
}
}
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;
vector<string> S(100000);
vector<int> march(5);
for (int n = 0; n < N; n++) {
cin >> S.at(n);
switch (S.at(n).at(0)) {
case 'M':
march.at(0)++;
break;
case 'A':
march.at(1)++;
break;
case 'R':
march.at(2)++;
break;
case 'C':
march.at(3)++;
break;
case 'H':
march.at(4)++;
break;
}
}
int a = 0;
for (int n = 0; n < 5; n++) {
if (march.at(n) > 0) {
a++;
}
}
if (a >= 3) {
long long ans = 0ll;
for (int d = 0; d < 5; d++) {
for (int e = d + 1; e < 5; e++) {
for (int f = e + 1; f < 5; f++) {
ans += march.at(d) * march.at(e) * march.at(f);
}
}
}
cout << ans << 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 | UNKNOWN | #include <bits/stdc++.h>
int func_conbination(int n, int m) {
int i, j = 1;
long long int val = 1;
for (i = 1; i <= m; i++) {
val *= n;
n -= 1;
j *= i;
}
val = val / j;
return val;
}
int main() {
int i, j, k;
char line[256];
int N, v;
long long int ans = 0;
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &N);
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (i = 0; i < N; i++) {
fgets(line, sizeof(line), stdin);
if (strncmp(&line[0], "M", 1) == 0) m += 1;
if (strncmp(&line[0], "A", 1) == 0) a += 1;
if (strncmp(&line[0], "R", 1) == 0) r += 1;
if (strncmp(&line[0], "C", 1) == 0) c += 1;
if (strncmp(&line[0], "H", 1) == 0) h += 1;
}
long int sum;
sum = m + a + r + c + h;
if (sum < 3) {
printf("0");
return 0;
}
ans = func_conbination(sum, 3);
if (m >= 2) {
for (i = 2; i <= m; i++) ans = ans - (sum - 2) * func_conbination(m, 2);
if (m > 2) ans = ans - func_conbination(m, 3);
}
if (a >= 2) {
for (i = 2; i <= a; i++) ans = ans - (sum - 2) * func_conbination(a, 2);
if (a > 2) ans = ans - func_conbination(a, 3);
}
if (r >= 2) {
for (i = 2; i <= r; i++) ans = ans - (sum - 2) * func_conbination(r, 2);
if (r > 2) ans = ans - func_conbination(r, 3);
}
if (c >= 2) {
for (i = 2; i <= c; i++) ans = ans - (sum - 2) * func_conbination(c, 2);
if (c > 2) ans = ans - func_conbination(c, 3);
}
if (h >= 2) {
for (i = 2; i <= h; i++) ans = ans - (sum - 2) * func_conbination(h, 2);
if (h > 2) ans = ans - func_conbination(h, 3);
}
printf("%lld", 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;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline int in() {
int x;
cin >> x;
return x;
}
inline ll IN() {
ll x;
cin >> x;
return x;
}
inline vs split(const string& t, char c) {
vs v;
stringstream s(t);
string b;
while (getline(s, b, c)) v.emplace_back(b);
return v;
}
template <typename T>
inline bool chmin(T& a, const T& b) {
if (a > b) a = b;
return a > b;
}
template <typename T>
inline bool chmax(T& a, const T& b) {
if (a < b) a = b;
return a < b;
}
template <typename T, typename S>
inline void print(const pair<T, S>& p) {
cout << p.first << " " << p.second << endl;
}
template <typename T>
inline void print(const T& x) {
cout << x << '\n';
}
template <typename T, typename S>
inline void print(const vector<pair<T, S>>& v) {
for (auto&& p : v) print(p);
}
template <typename T>
inline void print(const vector<T>& v, string s = " ") {
for (ll i = (0); i < (ll)(v.size()); ++i)
cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");
}
int rec(int i) {
if (i == 1)
return 1;
else
return i * rec(i - 1);
}
signed main() {
int n;
cin >> n;
string s[n];
ll cnt = 0;
ll m, a, r, c, h;
for (ll i = (0); i < (ll)(n); ++i) {
cin >> s[i];
if (s[i] == "M")
m++;
else if (s[i] == "A")
a++;
else if (s[i] == "R")
r++;
else if (s[i] == "C")
c++;
else if (s[i] == "H")
h++;
}
cnt += m * a * r;
cnt += m * a * c;
cnt += m * a * h;
cnt += m * r * c;
cnt += m * r * h;
cnt += m * c * h;
cnt += a * r * c;
cnt += a * r * h;
cnt += a * c * h;
cnt += r * c * h;
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 | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (1LL << 59);
const int iINF = (1 << 31) - 1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;
int main() {
int n;
cin >> n;
long long ans = 0LL;
int per[5] = {};
for (int i = 0; i < n; i++) {
string name;
cin >> name;
switch (name[0]) {
case 'M':
per[0]++;
break;
case 'A':
per[1]++;
break;
case 'R':
per[2]++;
break;
case 'C':
per[3]++;
break;
case 'H':
per[4]++;
break;
default:
break;
}
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += per[i] * per[j] * per[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>
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> alp(5);
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
if (s[0] == 'M') alp[0]++;
if (s[0] == 'A') alp[1]++;
if (s[0] == 'R') alp[2]++;
if (s[0] == 'C') alp[3]++;
if (s[0] == 'H') alp[4]++;
}
ll 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 += alp[i] * alp[j] * alp[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;
int march[5];
int comb[10][3] = {{0, 1, 2}, {0, 1, 3}, {0, 1, 4}, {0, 2, 3}, {0, 2, 4},
{0, 3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}};
int main() {
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
switch (s[0]) {
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
}
}
long long count = 0;
for (int j = 0; j < 10; j++) {
count += march[comb[j][0]] * march[comb[j][1]] * march[comb[j][2]];
}
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<string> s(n);
string ma = "MARCH";
int a[5] = {0};
for (int i = 0; i < (n); ++i) {
cin >> s[i];
for (int j = 0; j < (5); ++j) {
if (s[i][0] == ma[j]) a[j]++;
}
}
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 += 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 | python2 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
N = input()
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
S = raw_input()
if S[:1] == "M":
m += 1
elif S[:1] == "A":
a += 1
elif S[:1] == "R":
r += 1
elif S[:1] == "C":
c += 1
elif S[:1] == "H":
h += 1
print m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String s[] = new String[n];
String march = "MARCH";
int[] d = new int[5];
for(int i=0;i<n;i++){
s[i] = scanner.next();
for(int j=0;j<5;j++){
if(s[i].charAt(0) == march.charAt(j)){
d[j]++;
break;
}
}
}
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};
int allCount = 0;
for(int i=0;i<10;i++){
allCount += d[x[i]] * d[y[i]] * d[z[i]];
}
System.out.println(allCount);
}
} |
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, i, M, A, R, C, H, Answer;
string name;
M = 0;
A = 0;
R = 0;
C = 0;
H = 0;
cin >> N;
for (i = 1; i <= N; i++) {
cin >> name;
if (name[0] == 'M') {
M = M + 1;
} else if (name[0] == 'A') {
A = A + 1;
} else if (name[0] == 'R') {
R = R + 1;
} else if (name[0] == 'C') {
C = C + 1;
} else if (name[0] == 'H') {
H = H + 1;
}
name.clear();
}
Answer = M * A * R;
Answer = Answer + M * A * C;
Answer = Answer + M * A * H;
Answer = Answer + M * R * C;
Answer = Answer + M * R * H;
Answer = Answer + M * C * H;
Answer = Answer + A * R * C;
Answer = Answer + A * R * H;
Answer = Answer + A * C * H;
Answer = Answer + R * C * H;
cout << Answer << 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 _set(long long N, long long pos) { return N = N | (1 << pos); }
long long _reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool _check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
bool _upper(char a) { return a >= 'A' && a <= 'Z'; }
bool _lower(char a) { return a >= 'a' && a <= 'z'; }
bool _digit(char a) { return a >= '0' && a <= '9'; }
long long dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
long long dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
int main() {
int n;
cin >> n;
map<char, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') mp['M']++;
if (s[0] == 'A') mp['A']++;
if (s[0] == 'R') mp['R']++;
if (s[0] == 'C') mp['C']++;
if (s[0] == 'H') mp['H']++;
}
vector<int> v;
if (mp.size() < 3) return cout << 0 << '\n', 0;
for (auto i : mp) v.push_back(i.second);
long long ans = 0, L = v.size();
for (int i = 0; i < L; i++) {
for (int j = i + 1; j < L; j++) {
for (int k = j + 1; k < L; k++) ans += v[i] * v[j] * v[k];
}
}
cout << ans << '\n';
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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[i];
}
vector<long long int> vec(5, 0);
cout << S[0][0] << endl;
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M') {
vec[0]++;
} else if (S[i][0] == 'A') {
vec[1]++;
} else if (S[i][0] == 'R') {
vec[2]++;
} else if (S[i][0] == 'C') {
vec[3]++;
} else if (S[i][0] == 'H') {
vec[4]++;
}
}
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 += vec[i] * vec[j] * vec[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int INF = 1e9;
const long long MX = 1e18;
const long long MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const double PI = acos(-1);
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
COMinit();
int n;
cin >> n;
map<char, int> mp;
long long ans = 0;
long long cnt = 0;
for (long long i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' && s[0] != 'H')
continue;
mp[s[0]]++;
cnt++;
}
ans = COM(cnt, 3);
for (auto x : mp) {
if (x.second == 2) {
ans -= cnt - 2;
}
if (x.second >= 3) {
ans -= (cnt - x.second) * COM(x.second, 2);
ans -= COM(x.second, 3);
}
}
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() {
int n, m = 0, i, j;
long long int ans;
scanf("%d", &n);
char s[n];
for (i = 0; i < n; i++) {
scanf("%s", &s[i]);
}
long long int a[5];
for (i = 0; i < 5; i++) {
a[i] = 0;
}
for (i = 0; i < n; i++) {
if (s[i] == 'M')
a[0]++;
else if (s[i] == 'A')
a[1]++;
else if (s[i] == 'R')
a[2]++;
else if (s[i] == 'C')
a[3]++;
else if (s[i] == 'H')
a[4]++;
}
ans = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[1] * a[4] +
a[0] * a[2] * a[3] + a[0] * a[2] * a[4] + a[0] * a[3] * a[4] +
a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[3] * a[4] +
a[2] * a[3] * a[4];
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
namespace For_Atcoder
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(ReadLine());
int[] ns = { 0, 0, 0, 0, 0 };
for(int i = 0; i < n; i++)
{
string First = ReadLine().Substring(0, 1);
switch (First)
{
case "M":
ns[0] += 1;
break;
case "A":
ns[1] += 1;
break;
case "R":
ns[2] += 1;
break;
case "C":
ns[3] += 1;
break;
case "H":
ns[4] += 1;
break;
}
}
long ans = 0;
int count = ns.Where(x => x != 0).Count();
long[] ns2 = ns.OrderByDescending(x => x).Select(x => (long)x).ToArray();
switch (count)
{
case 3:
ans = ns2[0] * ns2[1] * ns2[2];
WriteLine(ans.ToString());
break;
case 4:
for(int i = 0; i <= 3; i++)
{
ans += ns2[0] * ns2[1] * ns2[2] * ns2[3] / ns2[i];
}
WriteLine(ans.ToString());
break;
case 5:
for(int i = 0; i < 4; i++)
{
for(int j = i + 1; j <= 4; j++)
{
ans += (ns2[0] * ns2[1] * ns2[2] * ns2[3] * ns2[4] / ns2[i]) / ns2[j];
}
}
WriteLine(ans.ToString());
break;
default:
WriteLine("0");
break;
}
}
}
} |
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 ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI =
static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {{typeid(int), "%d"},
{typeid(ll), "%lld"},
{typeid(double), "%lf"},
{typeid(char), "%c"}};
template <class T>
static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T>
static inline bool chmax(T& a, T b);
template <class T>
static inline bool chmin(T& a, T b);
template <class T>
static inline T gcd(T a, T b);
template <class T>
static inline T lcm(T a, T b);
template <class A, size_t N, class T>
static void Fill(A (&arr)[N], const T& val);
template <class T>
T mod(T a, T m);
int main(int argc, char* argv[]) {
long long N;
scanf("%lld", &N);
std::vector<std::string> S(N);
for (int i = 0; i < N; i++) {
std::cin >> S[i];
}
map<char, ll> m;
for (int i = (0); i < (N); i++) m[S[i][0]]++;
ll ans = 0;
ans += m['M'] * m['A'] * m['R'];
ans += m['M'] * m['A'] * m['C'];
ans += m['M'] * m['A'] * m['H'];
ans += m['M'] * m['R'] * m['C'];
ans += m['M'] * m['R'] * m['H'];
ans += m['M'] * m['C'] * m['H'];
ans += m['A'] * m['R'] * m['C'];
ans += m['A'] * m['R'] * m['H'];
ans += m['R'] * m['C'] * m['H'];
((cout) << (ans) << (endl));
return 0;
}
template <class T>
static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline T gcd(T a, T b) {
return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
return (a * b) / gcd(a, b);
}
template <class A, size_t N, class T>
void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T>
T mod(T a, T m) {
return (a % m + m) % m;
}
|
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 a[5] = {0};
char tmp[50];
int count = 0;
for (int i = 0; i < n; i++) {
cin >> tmp;
if (tmp[0] == 'M') a[0]++;
if (tmp[0] == 'A') a[1]++;
if (tmp[0] == 'R') a[2]++;
if (tmp[0] == 'C') a[3]++;
if (tmp[0] == 'H') a[4]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
count += a[i] * a[j] * a[k];
}
}
}
printf("%d\n", count);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
int main (){
int N;
cin >>N;
int M=0,A=0,R=0,C=0,H=0;
ll ans=0;
string s;
for(int i=1;i<=N;i++){
cin >> s;
if(s[0]=='M')M++;
if(s[0]=='A')A++;
if(s[0]=='R')R++;
if(s[0]=='C')C++;
if(s[0]=='H')H++;
}
ll ans=(M*A*R)+(M*A*C)+(M*A*H)+(A*R*C)+(A*C*H)+
(R*C*H)+(M*R*H)+(A*R*H)+(C*H*M)+(C*R*M);
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() {
long long int n;
cin >> n;
map<char, long long int> mp;
for (int i = 0; i < n; i++) {
string tmp;
cin >> tmp;
if (tmp[0] != 'M' && tmp[0] != 'A' && tmp[0] != 'R' && tmp[0] != 'C' &&
tmp[0] != 'H') {
} else {
mp[tmp[0]]++;
}
}
vector<long long int> arr;
for (auto itr : mp) {
arr.push_back(itr.second);
}
long long int ans = 0;
if (arr.size() < 3) {
ans = 0;
} else {
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += arr[i] * arr[j] * arr[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>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(){
ll n
cin>>n;
ll cnt[5]={0};
string s,march="MARCH";
rep(i,n){
cin>>s;
rep(j,5){
if(s[0]=march[j]) cnt[j]++;
}
}
ll ans=0;
rep(i,5){
for(ll j=i+1;j<5;j++){
for(ll k=j+1;j<5;j++){
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 | python3 | import itertools
N=int(input())
S=[input() for _ in range(N)]
M=0
A=0
R=0
C=0
H=0
alives=0
march=['M','A','R','C','H']
for i in S:
if i.startswith('M'):
M+=1
elif i.startswith('A'):
A+=1
elif i.startswith('R'):
R+=1
elif i.startswith('C'):
C+=1
elif i.startswith('H'):
H+=1
if M==0:
march.pop(march.index('M'))
if A==0:
march.pop(march.index('A'))
if R==0:
march.pop(march.index('R'))
if C==0:
march.pop(march.index('C'))
if H==0:
march.pop(march.index('H'))
if len(march)<3:
print(0)
seq=list(itertools.combinations(march,3))
ans=0
for i in seq:
temp=1
for ch in i:
if ch=='M':
temp*=M
if ch=='A':
temp*=A
if ch=='R':
temp*=R
if ch=='C':
temp*=C
if ch=='H':
temp*=H
ans+=temp
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>
int main() {
unsigned int N;
scanf("%u", &N);
unsigned int a = 0, b = 0, c = 0, d = 0, e = 0;
for (unsigned int i = 0; i < N; ++i) {
char tmp[15];
scanf("%s", tmp);
if (tmp[0] == 'M') a++;
if (tmp[0] == 'A') b++;
if (tmp[0] == 'R') c++;
if (tmp[0] == 'C') d++;
if (tmp[0] == 'H') e++;
}
unsigned long long answer = a * (b * (c + d + e) + c * (d + e) + d * e) +
b * (c * (d + e) + d * e) + c * d * e;
printf("%llu\n", 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;
const long double PI = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
vector<int> march(5, 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]++;
}
}
int ans = 0;
for (int i = 0; i < 10; i++) {
ans += march[x[i]] * march[y[i]] * march[z[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 | python3 | mod = 10**9 + 7
def cmb(n,r,mod):
a=1
b=1
r = min(r,n-r)
for i in range(r):
a = a*(n-i)%mod
b = b*(i+1)%mod
return a*pow(b,mod-2,mod)%mod
N = int(input())
march = []
for _ in range(N):
H =str(input())
if H[0] == 'M' or H[0] == 'A' or H[0] == 'R' or H[0] == 'C' or H[0] == 'H':
march.append(H[0])
march = ''.join(march)
m = march.count('M')
a = march.count('A')
r = march.count('R')
c = march.count('C')
h = march.count('H')
l = [m,a,r,c,h]
L = []
for i in range(len(l)):
if l[i] > 0:
L.append(l[i])
if len(L) < 3:
print(0)
exit()
else:
ans = cmb(len(L),3,mod)
for i in range(len(L)):
if L[i] > 1:
ans = ans*L[i]-(len(L)-3)
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<int> cnt(5);
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S.front() == 'M') {
cnt[0]++;
} else if (S.front() == 'A') {
cnt[1]++;
} else if (S.front() == 'R') {
cnt[2]++;
} else if (S.front() == 'C') {
cnt[3]++;
} else if (S.front() == 'H') {
cnt[4]++;
}
}
int64_t 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 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S_row = [input() for _ in range(N)]
S = list(filter(lambda n: n[0] in "MARCH", S_row))
ans = 0
for i, s1 in enumerate(S):
for j, s2 in enumerate(S[i+1:]):
if s2[0] != s1[0]:
for s3 in S[i+j+1:]:
if s3[0] != s1[0] and s3[0] != s2[0]:
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 | python3 | from itertools import combinations
N = int(input())
Sn = [input() for _ in range(N)]
Ln = []
for i in range(N):
if Sn[i][0] not in {"M", "A", "R", "C", "H"}:
continue
Ln.append(Sn[i])
ans = 0
for a, b, c in combinations(Ln, 3):
if len({a[0], b[0], c[0]}) != 3:
continue
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 | python3 | N=int(input())
S=set()
for i in range(N):
s=input()
if s[0] in ['M','A','R','C','H']:
S.add(s)
L=len(S)
print(L*(L-1)*(L-2)//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() {
int n;
cin >> n;
vector<int> cnt(5);
string s;
long long ans = 0, m = 0;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
cnt[0]++;
} else if (s[0] == 'A') {
cnt[1]++;
} else if (s[0] == 'R') {
cnt[2]++;
} else if (s[0] == 'C') {
cnt[3]++;
} else if (s[0] == 'H') {
cnt[4]++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
m = cnt[i] * cnt[j] * cnt[k];
ans += m;
}
}
}
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 dy[4] = {0, 0, 1, -1};
int dx[4] = {1, -1, 0, 0};
int main() {
long long M = 0, A = 0, R = 0, C = 0, H = 0, N;
string s[10000];
cin >> N;
for (int i = 0; i < N; i++) cin >> s[i];
for (int i = 0; i < N; i++) {
if (s[i][0] == 'M') M++;
if (s[i][0] == 'A') A++;
if (s[i][0] == 'R') R++;
if (s[i][0] == 'C') C++;
if (s[i][0] == 'H') H++;
}
long long ans = 0;
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(5);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s.front() == 'M') v[0]++;
if (s.front() == 'A') v[1]++;
if (s.front() == 'R') v[2]++;
if (s.front() == 'C') v[3]++;
if (s.front() == 'H') v[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 += v[i] * v[j] * v[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 diff[4][2] = {
{0, -1},
{-1, 0},
{1, 0},
{0, 1},
};
int Min(int a, int b) { return (a) < (b) ? (a) : (b); }
int Max(int a, int b) { return (a) > (b) ? (a) : (b); }
int main() {
int n;
scanf("%d", &n);
char s[11];
int cnt[5] = {0};
for (int i = 0, i_len = (int)(n); i < i_len; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
}
}
long long ans = 0;
for (int i = 0, i_len = (int)(n); i < i_len; i++) {
for (int j = (int)(i + 1), j_len = (int)(n); j < j_len; j++) {
for (int k = (int)(j + 1), k_len = (int)(n); k < k_len; k++) {
ans += (long long)cnt[i] * cnt[j] * cnt[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>
int main() {
char s[10001][11];
int n;
char march[] = {'M', 'A', 'R', 'C', 'H'};
int d[5] = {0, 0, 0, 0, 0};
int p[5] = {0, 1, 2, 3, 4};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
for (int j = 0; j < 5; j++)
if (s[i][0] == march[j]) d[j]++;
}
printf("%d %d %d %d %d\n", d[0], d[1], d[2], d[3], d[4]);
int sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += d[i] * d[j] * d[k];
}
}
}
printf("%d\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int fok(int n) {
if (n == 0) return 1;
if (n == 1) return 1;
if (n == 2) return 2;
if (n > 2) return fok(n - 1) * n;
}
int ent(int n, int k) {
if (k == 0) return 1;
if (k > n || k < 0)
return 0;
else
return fok(n) / (fok(k) * fok(n - k));
}
int main() {
int n, ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0, ans5 = 0, ans6 = 0, doogh = 0;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') ans1++;
if (s[i][0] == 'A') ans2++;
if (s[i][0] == 'R') ans3++;
if (s[i][0] == 'C') ans4++;
if (s[i][0] == 'H') ans5++;
}
if (ans1 != 0) ans6 = ans6 + 1;
if (ans2 != 0) ans6 = ans6 + 1;
if (ans3 != 0) ans6 = ans6 + 1;
if (ans4 != 0) ans6 = ans6 + 1;
if (ans5 != 0) ans6 = ans6 + 1;
if (ans1 + ans2 + ans3 + ans4 + ans5 < 3) cout << "0" << endl;
if (ans6 < 3)
cout << "0" << endl;
else
doogh = ent(3, ans6);
if (ans1 != 0) doogh = doogh * ans1;
if (ans2 != 0) doogh = doogh * ans2;
if (ans3 != 0) doogh = doogh * ans3;
if (ans4 != 0) doogh = doogh * ans4;
if (ans5 != 0) doogh = doogh * ans5;
cout << doogh << 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())
cnt = [0,0,0,0,0]
comp = 'MARCH'
ans = 0
for i in range(N):
word = input()
for j in range(len(comp)):
if word[0] == comp[j]:
cnt[j] += 1
for i in range(len(cnt)):
for j in range(i+1,len(cnt)):
for k in range(j+1,len(cnt)):
ans += cnt[i] * cnt[j] * cnt[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 | n = int(input())
s =[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for A in s:
if A[0]=='M':
m+=1
elif A[0]=='A':
a+=1
elif A[0]=='R':
r+=1
elif A[0]=='C':
c+=1
elif A[0]=='H':
h+=1
x = []
for i in [m,a,r,c,h]:
if i != 0:
x.append(i)
if len(x)<3:
print(0)
elif len(x)==3:
print(x[0]*x[1]*x[2])
elif len(x)==4:
print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3])
else:
print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3]
+x[0]*x[1]*x[4]+x[0]*x[2]*x[4]+x[1]*x[2]*x[4]
+x[3]*x[4]*x[5]+x[2]*x[4]*x[5]+x[1]*x[4]*x[5]) |
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 n;
cin >> n;
vector<string> s;
for (long long i = 0; i < n; i++) cin >> s[i];
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
vector<long long> v(5, 0);
for (long long i = 0; i < s.size(); i++) {
if (s[i][0] == 'M') v[0]++;
if (s[i][0] == 'A') v[1]++;
if (s[i][0] == 'R') v[2]++;
if (s[i][0] == 'C') v[3]++;
if (s[i][0] == 'H') v[4]++;
}
long long ans = 0;
for (long long i = 0; i < (1 << 5); i++) {
if (__builtin_popcount(i) == 3) {
long long tmp = 1;
for (long long j = 0; j < 5; j++) {
if (i & (1 << j)) tmp *= v[j];
}
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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
const int MOD = 1000000007;
int main() {
int N, m = 0, a = 0, r = 0, c = 0, h = 0;
cin >> N;
vs S(N);
for (int 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++;
}
ll ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int many[5] = {0};
int hoge, hogera;
char s[128];
long int math = 0;
scanf("%d", &hoge);
for (hogera = 0; hogera < hoge; hogera++) {
scanf("%s", &s);
switch (s[0]) {
case 'M':
many[0]++;
break;
case 'A':
many[1]++;
break;
case 'R':
many[2]++;
break;
case 'C':
many[3]++;
break;
case 'H':
many[4]++;
break;
}
}
math += (many[0] * many[1] * many[2]);
math += (many[0] * many[1] * many[3]);
math += (many[0] * many[1] * many[4]);
math += (many[0] * many[2] * many[3]);
math += (many[0] * many[2] * many[4]);
math += (many[0] * many[3] * many[4]);
math += (many[1] * many[2] * many[3]);
math += (many[1] * many[2] * many[4]);
math += (many[1] * many[3] * many[4]);
math += (many[2] * many[3] * many[4]);
printf("%d", math);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
vector<int> vec(5, 0);
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
vec[0]++;
else if (s[0] == 'A')
vec[1]++;
else if (s[0] == 'R')
vec[2]++;
else if (s[0] == 'C')
vec[3]++;
else if (s[0] == 'H')
vec[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 += (vec[i] * vec[j] * vec[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 h[5];
char S[100];
int main() {
int N;
char S[100];
for (int i = 0; i < 5; i++) h[i] = 0;
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%s", S);
if (S[0] == 'M') h[0]++;
if (S[0] == 'A') h[1]++;
if (S[0] == 'R') h[2]++;
if (S[0] == 'C') h[3]++;
if (S[0] == 'H') h[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 += h[i] * h[j] * h[k];
}
return (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 | python3 | import itertools
n=int(input())
S=[]
C=['M','A','R','C','H']
for i in range(n):
x=input()
if x[0] in C:
S.append(x)
X=list(itertools.combinations(S,3))
res=len(X)
for i in range(len(X)):
Y=[X[i][0][0],X[i][1][0],X[i][2][0]]
if len(set(Y))<3:
res-=1
print(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 | python3 | n = int(input())
moji = list('MARCH')
check = [0]*5
for i in range(n):
s = input()
if s[0] in moji:
check[moji.index(s[0])] += 1
ans = 1
flg = 0
for i in range(5):
if check[i] != 0:
ans *= check[i]
flg += check[i]
if flg:
print(ans)
else:
print(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 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++;
}
double ans = 0;
ans = m * a * r + m * a * h + m * a * c + m * r * c + m * r * h + m * c * h +
a * r * c + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | N = gets.chomp.to_i
S = []
march = 'MARCH'
cnt = Array.new(5,0)
N.times do
line = gets.chomp
if march.include?(line[0])
cnt[march.index(line[0])]+=1
end
end
sum = 0
param = [0,0,1,3,6]
3.times do |i|
tmp = cnt[i]
par = 0
for j in (i+1)..4 do
if cnt[j] > 0
if i==0
tmp*=cnt[j]
end
par += 1
end
end
sum+=tmp*param[par]
end
print "#{sum}\n" |
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<cstdio>
#include<string>
using namespace std;
int main(){
int n, m[5] = {0,0,0,0,0};
long long ans;
string s;
for(int i = 0; i < n; i++){
scanf("%s",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]++;
}
for(int j = 0; j < 3; j++)
for(int k = j+1; k < 4; k++)
for(int l = l+1; l < 5; l++)
ans += m[j]*m[k]*m[l];
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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArCorder
{
class Program
{
class inner : IEquatable<inner>
{
string m_First;
string m_Second;
string m_Therd;
public inner (string first, string second, string therd)
{
m_First = first;
m_Second = second;
m_Therd = therd;
}
public Boolean IsTarget()
{
if (m_First.First().Equals(m_Second.First()) || m_First.First().Equals(m_Therd.First()) || m_Second.First().Equals(m_Therd.First()))
{
return false;
}
else
{
return true;
}
}
public bool Equals(inner obj)
{
return obj.GetHashCode() == this.GetHashCode();
}
public override int GetHashCode()
{
return this.m_First.GetHashCode() ^ this.m_Second.GetHashCode() ^ this.m_Therd.GetHashCode();
}
}
static void Main()
{
int max = int.Parse(Console.ReadLine());
List<string> names = new List<string>();
for (int i = 0; i < max; i++)
{
names.Add(Console.ReadLine());
}
List<string> targetNames = names.Where(x => x.StartsWith("M") ||
x.StartsWith("A") ||
x.StartsWith("R") ||
x.StartsWith("C") ||
x.StartsWith("H")).ToList();
List<inner> allPatern = new List<inner>();
foreach (string first in targetNames){
foreach(string second in targetNames.Where(x => !x.StartsWith(first.First().ToString())).ToList())
{
foreach (string therd in targetNames.Where(x => !x.StartsWith(first.First().ToString()) && !x.StartsWith(second.First().ToString())).ToList())
{
allPatern.Add(new inner(first, second, therd));
}
}
}
Console.WriteLine(allPatern.Where(x => x.IsTarget()).Distinct().LongCount());
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int march[5] = {0};
string name;
for (int i = 0; i < n; i++) {
cin >> name;
if (name[0] == 'M') {
march[0]++;
} else if (name[0] == 'A') {
march[1]++;
} else if (name[0] == 'R') {
march[2]++;
} else if (name[0] == 'C') {
march[3]++;
} else if (name[0] == 'H') {
march[4]++;
}
}
long long ans = 0;
ans += march[0] * march[1] * march[2];
ans += march[0] * march[1] * march[3];
ans += march[0] * march[1] * march[4];
ans += march[0] * march[2] * march[3];
ans += march[0] * march[2] * march[4];
ans += march[0] * march[3] * march[4];
ans += march[1] * march[2] * march[3];
ans += march[1] * march[2] * march[4];
ans += march[1] * march[3] * march[4];
ans += march[2] * march[3] * march[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
typedef map<int,int> MII;
typedef queue<int> QI;
typedef queue<PII> QPII;
typedef stack<int> SI;
typedef stack<PII> SPII;
typedef deque<int> DI;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI; //大きい順
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<int>> PQLP;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define PF push_front
#define POB pop_back()
#define POF pop_front()
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) FORR(i,0,n)
#define BREP(bit,N) for(int bit = 0; bit < (1<<N); ++bit)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/2;
const LL LINF = LLONG_MAX/2;
const LL MOD = 1e9+7;
const LL MODD = 998244353;
const int MAX = 510000;
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
//other
//-------------------------------------------
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define COUT(x) cout << (x) << endl
#define COUT2(x,y) cout << (x) << " " << (y) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)
void cYes(){ COUT("Yes");exit(0); }
void cNo(){ COUT("No");exit(0); }
void cYES(){ COUT("YES");exit(0); }
void cNO(){ COUT("NO");exit(0); }
void cyes(){ COUT("yes");exit(0); }
void cno(){ COUT("no");exit(0); }
VI dx = {1,0,-1,0,1,1,-1,-1};
VI dy = {0,1,0,-1,1,-1,1,-1};
VC dc = {'R','D','L','U'};
VS ds = {"R","D","L","U","RD","RU","LD","LU"};
LL Gcd(LL a, LL b) {return __gcd(a,b);}
LL Lcm(LL a, LL b) {return a/Gcd(a,b)*b;}
LL ModPow(LL A, LL N, LL M){
LL res = 1;
while(N>0){
if(N&1) res = res * A % M;
A = A * A % M;
N >>= 1;
}
return res;
}
LL fac[MAX], finv[MAX], inv[MAX];
void ConInit(LL M) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % M;
inv[i] = M - inv[M%i] * (M / i) % M;
finv[i] = finv[i - 1] * inv[i] % M;
}
}
LL COM(int n, int k, LL M){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % M) % M;
}
void VCout(auto v){
int N = SZ(v);
REP(i,N){
cout << v.at(i);
if(i == N-1) cout << endl;
else cout << " ";
}
return;
}
void Press(auto &v){v.erase(unique(ALL(v)),v.end());}
int Vcount(auto v, auto x){
auto a = UB(ALL(v),x);
auto b = LB(ALL(v),x);
return a-b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N;
cin >> N;
VLL v(5,0);
REP(i,N){
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)++;
}
LL ans=0;
REP(i,N-2){
FOR(j,i+1,N-1){
FOR(k,j+1,N){
ans += v.at(i)*v.at(j)*v.at(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 | cpp | #include <bits/stdc++.h>
using namespace std;
char name[15];
long long 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 | UNKNOWN | n = gets.to_i
names = []
n.times do
input = gets.chomp
if input[0] =~ /M|A|R|C|H/
names << input
end
end
count = 0
names.combination(3).to_a.uniq.each do |arr|
if [arr[0][0],arr[1][0],arr[2][0]].uniq.size == 3
count += 1
end
end
puts 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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
// 整数の入力
int N;
ll result = 0;
cin >> N;
vector<string> S[5];
bool b[5];
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
S[0].push_back(s);
} else if (s[0] == 'A') {
S[1].push_back(s);
} else if (s[0] == 'R') {
S[2].push_back(s);
} else if (s[0] == 'C') {
S[3].push_back(s);
} else if (s[0] == 'H') {
S[4].push_back(s);
} else {
// ignore
}
}
//count
int count = 0;
for (int i = 0; i < 5; i++) {
if (S[i].size() <= 0) {
count++;
b[i] = false;
} else {
b[i] = true;
}
}
if (N - count <= 2) {
cout << result << endl;
return 0;
}
if (b[0] && b[1] && b[2]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[2].size(); k++) {
result++;
}
}
}
} if (b[0] && b[1] && b[3]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
} if (b[0] && b[1] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
} if (b[0] && b[2] && b[3]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
} if (b[0] && b[2] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
} if (b[0] && b[3] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
} if (b[1] && b[2] && b[3]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
} if (b[1] && b[2] && b[4]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
} if (b[1] && b[3] && b[4]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
} if (b[2] && b[3] && b[4]) {
for (int i = 0; i < S[2].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
cout << result << 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 f(int a, int b, int c) { return a * b * c; }
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S.at(i);
vector<vector<string>> v(5);
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M') {
v.at(0).push_back(S.at(i));
} else if (S.at(i).at(0) == 'A') {
v.at(1).push_back(S.at(i));
} else if (S.at(i).at(0) == 'R') {
v.at(2).push_back(S.at(i));
} else if (S.at(i).at(0) == 'C') {
v.at(3).push_back(S.at(i));
} else if (S.at(i).at(0) == 'H') {
v.at(4).push_back(S.at(i));
}
}
long long sum = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
sum += f(v.at(i).size(), v.at(j).size(), v.at(k).size());
}
}
}
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;
long long int ans;
int main() {
int n, f[10], i, g;
ans = g = 0;
char a[1000000];
memset(f, 0, sizeof(f));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", a);
if (a[0] == 'A')
f[1] += 1;
else if (a[0] == 'M')
f[2] += 1;
else if (a[0] == 'R')
f[3] += 1;
else if (a[0] == 'H')
f[4] += 1;
else if (a[0] == 'C')
f[5] += 1;
}
ans = f[1] * f[2] * f[3] + f[1] * f[2] * f[4] + f[1] * f[2] * f[5] +
f[2] * f[3] * f[4] + f[2] * f[3] * f[5] + f[1] * f[3] * f[4] +
f[1] * f[3] * f[5] + f[1] * f[4] * f[5] + f[2] * f[4] * f[5] +
f[3] * f[4] * f[5];
printf("%lld", 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() {
long long n;
cin >> n;
int arr[26];
for (int i = 0; i < 26; i++) {
arr[i] = 0;
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
arr[s[0] - 65]++;
}
int ar[5];
ar[0] = arr['M' - 65];
ar[1] = arr['A' - 65];
ar[2] = arr['R' - 65];
ar[3] = arr['C' - 65];
ar[4] = arr['H' - 65];
long long sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += ar[i] * ar[j] * ar[k];
}
}
}
cout << sum;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll atcoder = 1e9 + 7;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
ll lcm(ll a, ll b) {
if (a < b) swap(a, b);
return (a / gcd(a, b)) * b;
}
int main() {
int n;
string t = "MARCH";
int a[5] = {0};
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < t.length(); j++)
if (s[0] == t[j]) a[j]++;
}
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 += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
system("pause");
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<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
char s[100000];
map<char,int>S;
int main(){
int n;
ll sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%s",s);
if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H') S[s[0]]++;
}
if(n<3) printf("0\n");
else{
sum+=(S['M']*S['A']*S['R']);
sum+=(S['M']*S['A']*S['C']);
sum+=(S['M']*S['A']*S['H']);
sum+=(S['M']*S['R']*S['C']);
sum+=(S['M']*S['R']*S['H']);
sum+=(S['M']*S['C']*S['H']);
sum+=(S['A']*S['R']*S['C']);
sum+=(S['A']*S['R']*S['H']);
sum+=(S['A']*S['C']*S['H']);
sum+=(S['R']*S['C']*S['H']);
printf("%lld\n",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>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
ll lcm(ll a, ll b)
{
return a * b / __gcd(a, b);
}
int main()
{
int N;
cin >> N;
string S;
string A;
vector<int> march(5,0);
int P[10] = {0,0,0,0,0,0,1,1,2,1};
int Q[10] = {1,1,1,2,2,3,2,2,3,3};
int R[10] = {2,3,4,3,4,4,3,4,4,4};
for (int i = 0; i < N; i++)
{
cin >> S;
if ('M' == S[0])
{
march[0]++;
}
else if('A' == S[0]){
march[1]++;
}
else if('R' == S[0]){
march[2]++;
}
else if('C'== S[0]){
march[3]++;
}
else if(S[0] == 'H'){
march[4]++;
}
}
ll ans = 0;
for (int d = 0; d < 10;d++)
{
ans += march[P[d]] * march[Q[d]] * march[R[d]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, num1 = 0;
cin >> N;
string s;
int num[5] = {0};
for (int i = 0; i < N; i++) {
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]++;
}
}
}
}
}
}
sort(num, num + 5);
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
if (num[i] > 0) {
if (num[j] > 0) {
if (num[k] > 0) {
num1 += num[i] * num[j] * num[k];
}
}
}
}
}
}
cout << num1 << 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;
char name[100001][11];
unsigned long long int ans = 0;
int m, a, r, c, h;
m = a = r = c = h = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name[i]);
switch (name[i][0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
ans += m * a * r;
ans += m * a * c;
ans += m * a * h;
ans += m * r * c;
ans += m * r * h;
ans += m * c * h;
ans += a * r * c;
ans += a * r * h;
ans += a * c * h;
ans += r * c * h;
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
vector<int> name(5, 0);
for (int i = 0; i < n; i++) {
string str;
cin >> str;
switch (str.at(0)) {
case 'M':
name.at(0)++;
break;
case 'A':
name.at(1)++;
break;
case 'R':
name.at(2)++;
break;
case 'C':
name.at(3)++;
break;
case 'H':
name.at(4)++;
break;
}
}
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.at(i) * name.at(j) * name.at(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;
int main() {
ll n;
cin >> n;
string s;
map<char, ll> mp;
ll cnt = 0;
ll ans = 1;
mp['M'] = 0, mp['A'] = 0, mp['R'] = 0, mp['C'] = 0, mp['H'] = 0;
for (ll i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
mp[s[0]]++;
}
}
if (mp['M'] != 0) {
cnt++;
ans *= mp['M'];
}
if (mp['A'] != 0) {
cnt++;
ans *= mp['A'];
}
if (mp['R'] != 0) {
cnt++;
ans *= mp['R'];
}
if (mp['C'] != 0) {
cnt++;
ans *= mp['C'];
}
if (mp['H'] != 0) {
cnt++;
ans *= mp['H'];
}
if (cnt < 3)
ans = 0;
else if (cnt == 3)
ans *= 1;
else if (cnt == 4) {
ans *= 4;
} else if (cnt == 5) {
ans *= 10;
}
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 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
namespace For_Atcoder
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(ReadLine());
int[] ns = { 0, 0, 0, 0, 0 };
for(int i = 0; i < n; i++)
{
string First = ReadLine().Substring(0, 1);
switch (First)
{
case "M":
ns[0] += 1;
break;
case "A":
ns[1] += 1;
break;
case "R":
ns[2] += 1;
break;
case "C":
ns[3] += 1;
break;
case "H":
ns[4] += 1;
break;
}
}
long ans = 0;
int count = ns.Where(x => x != 0).Count();
long[] ns2 = ns.Where(x => x != 0).Select(x => (long)x).ToArray();
switch (count)
{
case 3:
ans = ns2[0] * ns2[1] * ns2[2];
WriteLine(ans.ToString());
break;
case 4:
for(int i = 0; i <= 3; i++)
{
ans += ns2[0] * ns2[1] * ns2[2] * ns2[3] / ns2[i];
}
WriteLine(ans.ToString());
break;
case 5:
for(int i = 0; i < 4; i++)
{
for(int j = i + 1; j <= 4; j++)
{
ans += (ns2[0] * ns2[1] * ns2[2] * ns2[3] * ns2[4] / ns2[i]) / ns2[j];
}
}
WriteLine(ans.ToString());
break;
default:
WriteLine("0");
break;
}
}
}
} |
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;
ll comb(ll n, ll r) {
ll num = 1;
for (int i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
int main() {
ll n;
cin >> n;
map<char, ll> s;
for (long long i = 0; i < (int)(n); i++) {
string tmp;
cin >> tmp;
if (tmp[0] == 'M' or tmp[0] == 'A' or tmp[0] == 'R' or tmp[0] == 'C' or
tmp[0] == 'H') {
s[tmp[0]]++;
}
}
ll maxSize = 0;
for (auto x : s) {
maxSize = max(maxSize, x.second);
}
ll x = s.size() - 2;
if (s.size() == 3)
cout << fixed << comb(s.size(), 3) + 1 << endl;
else if (s.size() < 3)
cout << fixed << 0 << endl;
else
cout << fixed << ll(comb(s.size(), 3) + (0.5 * x * (x + 1))) << 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())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
s=input()
if s[0]=='M':
M.append(s)
elif s[0]=='A':
A.append(s)
elif s[0]=='R':
R.append(s)
elif s[0]=='C':
C.append(s)
elif s[0]=='H':
H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)
def dif(n):
if cnt[n]==0 or cnt[n]==1:
return 0
else:
a=0
for i in range(5):
if i!=n:
a+=cnt[i]
if cnt[n]==2:
return a
else:
b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
return int(a+b)
for i in range(5):
res-=dif(i)
print(res)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
uintmax_t combination(unsigned int n, unsigned int r) {
if (r * 2 > n) r = n - r;
uintmax_t dividend = 1;
uintmax_t divisor = 1;
for (unsigned int i = 1; i <= r; ++i) {
dividend *= (n - i + 1);
divisor *= i;
}
return dividend / divisor;
}
int main() {
unsigned int N;
unsigned int flag[5] = {0};
cin >> N;
vector<string> S(N);
unsigned int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
switch (S[i][0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
default:
break;
}
}
unsigned int c2_m = 0, c2_a = 0, c2_r = 0, c2_c = 0, c2_h = 0;
unsigned int c3_m = 0, c3_a = 0, c3_r = 0, c3_c = 0, c3_h = 0;
int march = m + a + r + c + h;
if (m > 1) {
c2_m = combination(m, 2) * (march - m);
}
if (a > 1) {
c2_a = combination(a, 2) * (march - a);
}
if (r > 1) {
c2_r = combination(r, 2) * (march - r);
}
if (c > 1) {
c2_c = combination(c, 2) * (march - c);
}
if (h > 1) {
c2_h = combination(h, 2) * (march - h);
}
if (m > 2) {
c3_m = combination(m, 3);
}
if (a > 2) {
c3_a = combination(a, 3);
}
if (r > 2) {
c3_r = combination(r, 3);
}
if (c > 2) {
c3_c = combination(c, 3);
}
if (h > 2) {
c3_h = combination(h, 3);
}
int zeroCounter = 0;
if (m > 0) {
zeroCounter++;
}
if (a > 0) {
zeroCounter++;
}
if (r > 0) {
zeroCounter++;
}
if (c > 0) {
zeroCounter++;
}
if (h > 0) {
zeroCounter++;
}
if (zeroCounter < 3 || march < 3) {
cout << 0 << endl;
return 0;
}
cout << combination(march, 3) - c2_m - c2_a - c2_r - c2_c - c2_h - c3_m -
c3_a - c3_r - c3_c - c3_h
<< 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;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "[";
for (auto vv : v) os << vv << ",";
return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> v) {
os << "[";
for (auto vv : v) os << vv << ",";
return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
T sq(T a) {
return a * a;
}
template <typename T>
T gcd(T a, T b) {
if (a > b) return gcd(b, a);
return a == 0 ? b : gcd(b % a, a);
}
template <typename T, typename U>
T mypow(T b, U n) {
if (n == 0) return 1;
if (n == 1) return b;
if (n % 2 == 0) {
return mypow(b * b, n / 2);
} else {
return mypow(b, n - 1) * b;
}
}
ll pcnt(ll b) { return __builtin_popcountll(b); }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
string march = "MARCH";
int cnt[5] = {};
for (ll i = (0); i < (N); i++) {
string S;
cin >> S;
for (ll j = (0); j < (5); j++) {
if (S[0] == march[j]) cnt[j]++;
}
}
ll ans = 0;
for (ll i = (0); i < (3); i++) {
for (ll j = (i + 1); j < (4); j++) {
for (ll k = (j + 1); k < (5); 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 | java | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int Num=sc.nextInt();
int mem[]=new int[5];
int ans=0;
for(int i=0;i<Num;i++){
String str=sc.next();
char s=str.charAt(0);
if(s=='M') mem[0]++;
else if(s=='A') mem[1]++;
else if(s=='R') mem[2]++;
else if(s=='C') mem[3]++;
else if(s=='H') mem[4]++;
}
for(int i=0;i<=2;i++){
for(int j=1;j<=3;j++){
for(int k=2;k<=4;k++){
if(i<j && j<k) ans+=mem[i]*mem[j]*mem[k];
}
}
}
System.out.println(ans);
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.