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;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
int flag[] = {0, 0, 0, 0, 0};
for (int i = 0; i < (N); i++) {
string a;
cin >> a;
if (a[0] == 'M') flag[0]++;
if (a[0] == 'A') flag[1]++;
if (a[0] == 'R') flag[2]++;
if (a[0] == 'C') flag[3]++;
if (a[0] == 'H') flag[4]++;
}
long long ans = 0;
ans = flag[0] * flag[1] * flag[2] + flag[0] * flag[1] * flag[3] +
flag[0] * flag[1] * flag[4] + flag[0] * flag[2] * flag[3] +
flag[0] * flag[2] * flag[4] + flag[0] * flag[3] * flag[4] +
flag[1] * flag[2] * flag[3] + flag[1] * flag[2] * flag[4] +
flag[1] * flag[3] * flag[4] + flag[2] * flag[3] * flag[4];
cout << (ans) << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, num1 = 0;
cin >> N;
string s;
long long 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 | python3 | from itertools import combinations
# input
N = int(input())
S = [input() for i in range(N)]
# check
cnt = 0
MARCH = ["M", "A", "R", "C", "H"]
for c in combinations(S, 3):
tops = [s[0] for s in c if s[0] != MARCH]
if len(set(tops)) == 3:
cnt += 1
print(cnt) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int main(void) {
int N;
int top[5] = {};
long long answer = 0;
std::string str;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> str;
if (str[0] == 'M') {
top[0]++;
} else if (str[0] == 'A') {
top[1]++;
} else if (str[0] == 'R') {
top[2]++;
} else if (str[0] == 'C') {
top[3]++;
} else if (str[0] == 'H') {
top[4]++;
}
}
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
answer += top[i] * top[j] * top[k];
}
}
}
cout << answer << 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.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int numPpl = Integer.parseInt(scanner.nextLine());
int M = 1;
int A = 2;
int R = 4;
int C = 8;
int H = 16;
int[] numMARCH = new int[17];
int[] comb3Chars = {
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,
};
for (int pIdx = 0; pIdx < numPpl; pIdx++) {
char firstChar = scanner.nextLine().charAt(0);
if(firstChar == 'M') numMARCH[M]++;
if(firstChar == 'A') numMARCH[A]++;
if(firstChar == 'R') numMARCH[R]++;
if(firstChar == 'C') numMARCH[C]++;
if(firstChar == 'H') numMARCH[H]++;
}
long result = 0;
for (int comb3Char: comb3Chars) {
int tmpResult = 1;
if ((comb3Char & M) > 0) tmpResult = numMARCH[M] == 0 ? 0 : tmpResult * numMARCH[M];
if ((comb3Char & A) > 0) tmpResult = numMARCH[A] == 0 ? 0 : tmpResult * numMARCH[A];
if ((comb3Char & R) > 0) tmpResult = numMARCH[R] == 0 ? 0 : tmpResult * numMARCH[R];
if ((comb3Char & C) > 0) tmpResult = numMARCH[C] == 0 ? 0 : tmpResult * numMARCH[C];
if ((comb3Char & H) > 0) tmpResult = numMARCH[H] == 0 ? 0 : tmpResult * numMARCH[H];
result += tmpResult;
}
System.out.println(result);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string s[100005];
int a[26];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) a[s[i][0] - 'A']++;
if (n < 3) {
cout << 0 << endl;
return 0;
}
int ans = 1, flag = 0, cnt = 0, c[5];
if (a['M' - 'A']) c[0] = a['M' - 'A'], cnt++;
if (a['A' - 'A']) c[1] = a['A' - 'A'], cnt++;
if (a['R' - 'A']) c[2] = a['R' - 'A'], cnt++;
if (a['C' - 'A']) c[3] = a['C' - 'A'], cnt++;
if (a['H' - 'A']) c[4] = a['H' - 'A'], cnt++;
if (cnt >= 3) {
ans = c[0] * c[1] * c[2];
ans += c[0] * c[3] * c[1];
ans += c[0] * c[1] * c[4];
ans += c[0] * c[3] * c[2];
ans += c[0] * c[4] * c[2];
ans += c[0] * c[4] * c[3];
ans += c[3] * c[1] * c[2];
ans += c[4] * c[1] * c[2];
ans += c[4] * c[3] * c[2];
ans += c[3] * c[1] * c[4];
cout << ans << endl;
} else if (cnt < 3)
cout << 0 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] initials = {'M', 'A', 'R', 'C', 'H'};
int n = sc.nextInt();
HashMap<Character, Integer> map = new HashMap<>();
for(int i = 0; i < n; i++) {
String name = sc.next();
char initial = name.charAt(0);
if(initial == 'M' || initial == 'A' || initial == 'R' || initial == 'C' || initial == 'H') {
map.put(initial, map.getOrDefault(initial, 0) + 1);
}
}
long count = 0;
for(int i = 0; i < 3; i++) {
for(int j = i + 1; j < 4; j++) {
for(int k = j + 1; k < 5; k++) {
count += (map.getOrDefault(initials[i], 0) * map.getOrDefault(initials[j], 0) * map.getOrDefault(initials[k], 0));
}
}
}
System.out.println(count);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
signed main() {
map<char, long long> M;
long long N;
cin >> N;
for (long long i = (long long)(0); i < (long long)(N); i++) {
string S;
cin >> S;
M[S[i]]++;
}
long long ans = 0;
vector<char> C = {'M', 'A', 'R', 'C', 'H'};
for (long long i = (long long)(0); i < (long long)((1ll << 5)); i++) {
bitset<5> B(i);
if (B.count() == 3) {
long long sum = 1;
for (long long j = (long long)(0); j < (long long)(5); j++) {
if (B.test(j)) sum *= M[C[j]];
}
ans += sum;
}
}
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 m = 0, a = 0, r = 0, c = 0, h = 0;
int can_num = 0;
int n;
cin >> n;
string 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++;
}
if (m != 0) can_num++;
if (a != 0) can_num++;
if (r != 0) can_num++;
if (c != 0) can_num++;
if (h != 0) can_num++;
int march[5];
march[0] = m;
march[1] = a;
march[2] = r;
march[3] = c;
march[4] = h;
int ans = 0;
if (can_num < 3) {
cout << 0 << endl;
return 0;
} else if (can_num == 3) {
int tmp = 1;
for (int i = 0; i < 5; i++) {
if (march[i] != 0) {
tmp *= march[i];
}
}
ans = tmp;
} else if (can_num == 4) {
int tmp = 1, cnt = 0;
for (int i = 0; i < 5; i++) {
if (march[i] == 0) continue;
tmp = 1;
for (int j = 0; j < 5; j++) {
if (i == j) continue;
if (march[i] == 0 || march[j] == 0) continue;
tmp *= march[j];
cnt++;
if (cnt == 3) break;
}
ans += tmp;
cnt = 0;
}
} else if (can_num == 5) {
int tmp = 1, cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
tmp = 1;
if (i == j) continue;
for (int k = 0; k < 5; k++) {
if (i == k || j == k) continue;
tmp *= march[k];
cnt++;
if (cnt == 3) break;
}
ans += tmp;
cnt = 0;
}
}
ans /= 2;
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long SZ = 5;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
string s;
cin >> n;
vector<long long> cnt(n);
for (long long 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]++;
}
long long ans = 0;
for (long long i = (0), i_len = (SZ); i < i_len; ++i)
for (long long j = (i + 1), j_len = (SZ); j < j_len; ++j)
for (long long k = (j + 1), k_len = (SZ); k < k_len; ++k) {
ans += (cnt[i] * cnt[j] * cnt[k]);
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
int m[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
m[0]++;
} else if (s[0] == 'A') {
m[1]++;
} else if (s[0] == 'R') {
m[2]++;
} else if (s[0] == 'C') {
m[3]++;
} else if (s[0] == 'H') {
m[4]++;
}
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
cnt++;
}
}
if (cnt < 3) {
cout << 0 << '\n';
return 0;
}
int ans = 1;
int tmp = 0;
if (cnt == 3) {
tmp = 1;
} else if (cnt == 4) {
tmp = 4;
vector<int> v;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
v.push_back(m[i]);
}
}
ans = v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[2] * v[3] +
v[1] * v[2] * v[3];
cout << ans << endl;
return 0;
} else if (cnt == 5) {
tmp = 10;
vector<int> v;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
v.push_back(m[i]);
}
}
ans = v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[2] * v[3] +
v[1] * v[2] * v[3] + v[0] * v[1] * v[4] + v[0] * v[2] * v[4] +
v[0] * v[3] * v[4] + v[1] * v[2] * v[4] + v[1] * v[3] * v[4] +
v[2] * v[3] * v[4];
cout << ans << endl;
return 0;
}
for (int i = 0; i < 5; i++) {
if (m[i] == 0) {
continue;
} else {
ans *= m[i];
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int static fast = []() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
return 0;
}();
long long n3r(long long n) {
if (n < 3) return 0;
return n * (n - 1) * (n - 2) / 6;
}
int main() {
int n;
string s;
cin >> n;
unordered_map<char, int> cnt;
cnt['M'] = cnt['A'] = cnt['R'] = cnt['C'] = cnt['H'] = 0;
long long acc = 0;
for (int i = 0; i < n; i++) {
cin >> s;
if (cnt.count(s[0]) > 0) {
cnt[s[0]] += 1;
acc += 1;
}
}
long long ans = n3r(acc);
for (auto p : cnt) {
long long freq = p.second;
if (freq >= 2) ans -= (freq * (freq - 1) / 2) * (acc - freq);
ans += n3r(freq);
}
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 Factorial(long long k) {
int ans = 1;
for (int i = 1; i <= k; i++) ans *= i;
return ans;
}
long long nPk(long long n, long long k) {
int ans = 1;
for (int i = n - k + 1; i <= n; i++) ans *= i;
return ans;
}
long long nCk(long long n, long long k) { return nPk(n, k) / Factorial(k); }
int main() {
int N;
string S[100001];
cin >> N;
for (int i = 0; i < N; i++) cin >> S[i];
long long int cnt[5] = {0};
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M')
cnt[0]++;
else if (S[i][0] == 'A')
cnt[1]++;
else if (S[i][0] == 'R')
cnt[2]++;
else if (S[i][0] == 'C')
cnt[3]++;
else if (S[i][0] == 'H')
cnt[4]++;
}
long long int ans = 1, c = 0;
for (int i = 0; i < 5; i++) {
if (cnt[i] != 0)
ans *= cnt[i];
else
c++;
}
if (c == 5)
cout << "0" << endl;
else {
int n;
n = 5 - c;
if (n < 4) {
cout << ans << endl;
} else {
ans *= nCk(n, 3);
for (int i = 0; i < 5; i++) {
if (cnt[i] != 0) ans -= (cnt[i] - 1);
}
cout << ans << endl;
}
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
long long n, fl[5] = {0}, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') fl[0]++;
if (s[1] == 'A') fl[1]++;
if (s[2] == 'R') fl[2]++;
if (s[3] == 'C') fl[3]++;
if (s[4] == 'H') fl[4]++;
}
ans = ans + fl[0] * fl[1] * fl[2];
ans = ans + fl[0] * fl[1] * fl[3];
ans = ans + fl[0] * fl[1] * fl[4];
ans = ans + fl[0] * fl[2] * fl[3];
ans = ans + fl[0] * fl[2] * fl[4];
ans = ans + fl[0] * fl[3] * fl[4];
ans = ans + fl[1] * fl[2] * fl[3];
ans = ans + fl[1] * fl[2] * fl[4];
ans = ans + fl[1] * fl[3] * fl[4];
ans = ans + fl[2] * fl[3] * fl[4];
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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n, m = 0, a = 0, r = 0, c = 0, h = 0;
long long sum = 0;
char s[10];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", 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++;
s[0] = '\0';
}
sum += m * a * r;
sum += m * a * c;
sum += m * a * h;
sum += m * r * c;
sum += m * r * h;
sum += m * c * h;
sum += a * r * c;
sum += a * r * h;
sum += a * c * h;
sum += r * c * h;
printf("%lld", 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 <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
// #include <unordered_set>
// #include <unordered_map>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define pb push_back
#define mp make_pair
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);
using namespace std;
// #define int long long
int main(){
int n;
cin>>n;
int initials[n]={0};
REP(i,n){
string tmp;
cin>>tmp;
//march
if(tmp[0]=='M'){
initials[0]++;
}else if(tmp[0]=='A'){
initials[1]++;
}else if(tmp[0]=='R'){
initials[2]++;
}else if(tmp[0]=='C'){
initials[3]++;
}else if(tmp[0]=='H'){
initials[4]++;
}
}
int m=initials[0];
int a=initials[1];
int r=initials[2];
int c=initials[3];
int h=initials[4];
int sum=0;
int ans=0;
REP(i,5){
sum+=initials[i];
// cout<<initials[i]<<" ";
}
// cout<<endl;
// cout<<m<<a<<r<<c<<h<<endl;
REP(i,2){
REP(j,2){
REP(k,2){
REP(l,2){
REP(o,2){
int sum=i+j+k+l+o;
if(sum==3){
// cout<<i<<j<<k<<l<<o<<endl;
int tmp=1;
if(i)tmp*=m;
if(j)tmp*=a;
if(k)tmp*=r;
if(l)tmp*=c;
if(o)tmp*=h;
ans+=tmp;
}
}
}
}
}
}
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 | a = gets.to_i.times.map{gets[0]}.reduce({'M'=>0,'A'=>0,'R'=>0,'C'=>0,'H'=>0}) do |e, c|
e[c] += 1 if e[c]
e
end.map{|e|e[1]}
res = 0
5.times do |i|
(i...5).each do |j|
(j...5).each do |k|
res += a[i]*a[j]*a[k]
end
end
end
puts res
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | open System
let n = Console.ReadLine() |> int
let ss =
seq {
for i in 1 .. n do
yield Console.ReadLine()
}
let ans =
let march = ['M'; 'A'; 'R'; 'C'; 'H']
let mutable m =
new Map<char, int> (
march
|> List.toSeq
|> Seq.map (fun c -> (c, 0))
)
for s in ss do
let c = s.[0]
match List.tryFind (fun x -> x = c) march with
| Some _ -> m <- m |> Map.add c (m.[c] + 1)
| _ -> ()
let tmp =
march
|> List.map (fun c -> m.[c])
|> List.filter (fun x -> x >= 1)
let rec dfs (is: int list) rest =
match rest with
| [] ->
if is.Length = 3 then
is
|> List.map (fun i -> tmp.[i])
|> List.fold (*) 1
else
0
| i :: rest ->
(dfs is rest) + (dfs (i :: is) rest)
dfs [] [0 .. tmp.Length - 1]
ans |> Console.WriteLine
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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())
S = [input() for _ in range(N)]
L = ['M', 'A', 'R', 'C', 'H']
dict_S = {}
for i in range(N):
moji = S[i][0]
if moji in L:
if moji not in dict_S:
dict_S[moji] = 1
else:
dict_S[moji] += 1
keys = len(dict_S.keys())
if keys < 3 or keys == None:
print(0)
else:
x = int(math.factorial(keys) / math.factorial(3) / math.factorial(keys - 3))
for v in dict_S.values():
if v >= 2 and keys > 3:
x *= v
x -= 1
elif v >= 2:
x *= v
print(x) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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;
size_t N;
string S;
char headc[5] = {'M', 'A', 'R', 'C', 'H'};
vector<long long> head_num(5, 0);
void mysort(string s) {
for (size_t i = 0; i < 5; i++) {
if (s.front() == headc[i]) {
head_num[i]++;
return;
}
}
return;
}
int main() {
cin >> N;
S.resize(N);
for (size_t i = 0; i < N; i++) {
cin >> S;
mysort(S);
}
sort(head_num.begin(), head_num.end());
int times = 1;
int sump = 0;
if (head_num[0] > 0) {
for (size_t i = 0; i < 4; i++) {
for (size_t j = i + 1; j < 5; j++) {
for (size_t k = 0; k < 5; k++) {
if (k != i && k != j) {
times *= head_num[k];
}
}
sump += times;
times = 1;
}
}
cout << sump << endl;
} else if (head_num[1] > 0) {
for (size_t i = 1; i < 5; i++) {
for (size_t k = 1; k < 5; k++) {
if (k != i) {
times *= head_num[k];
}
}
sump += times;
times = 1;
}
cout << sump << endl;
} else {
for (size_t k = 2; k < 5; k++) {
times *= head_num[k];
}
cout << times << 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() {
unsigned long long N = 0;
unsigned long long M = 0, A = 0, R = 0, C = 0, H = 0;
cin >> N;
string s;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') {
M += 1;
} else if (s[0] == 'A') {
A += 1;
} else if (s[0] == 'R') {
R += 1;
} else if (s[0] == 'C') {
C += 1;
} else if (s[0] == 'H') {
H += 1;
}
}
int sum = 0;
sum += M * A * R;
sum += M * A * C;
sum += M * A * H;
sum += M * R * C;
sum += M * R * H;
sum += M * C * H;
sum += A * R * C;
sum += A * R * H;
sum += A * C * H;
sum += R * C * H;
printf("%llu\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n;
cin >> n;
char march[] = "MARCH";
vector<vector<string>> names(5);
for (int i = 0; i < n; ++i) {
string name;
cin >> name;
for (int j = 0; j < 5; ++j) {
if (name[0] == march[j]) {
names[j].emplace_back(move(name));
}
}
}
int counts[5] = {0};
for (int i = 0; i < 5; ++i) {
counts[i] = names[i].size();
}
uint64_t ans = 0;
ans += counts[0] * counts[1] * counts[2];
ans += counts[0] * counts[1] * counts[3];
ans += counts[0] * counts[1] * counts[4];
ans += counts[0] * counts[2] * counts[3];
ans += counts[0] * counts[2] * counts[4];
ans += counts[0] * counts[3] * counts[4];
ans += counts[1] * counts[2] * counts[3];
ans += counts[1] * counts[2] * counts[4];
ans += counts[1] * counts[3] * counts[4];
ans += counts[2] * counts[3] * counts[4];
cout << ans << "\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 <bits/stdc++.h>
using namespace std;
int main(void) {
int n, i, j, k, ans = 0;
string s;
vector<int> l(6, 0);
cin >> n;
for (i = 0; i < n; i++) {
cin >> s;
if (s.at(0) == 'M')
l.at(0)++;
else if (s.at(0) == 'A')
l.at(1)++;
else if (s.at(0) == 'R')
l.at(2)++;
else if (s.at(0) == 'C')
l.at(3)++;
else if (s.at(0) == 'H')
l.at(4)++;
}
for (i = 0; i < 3; i++)
for (j = i + 1; j < 4; j++)
for (k = j + 1; k < 5; k++) ans += l.at(i) * l.at(j) * l.at(k);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, i, first, second, third;
string buf;
int nums[5];
for (int i = (0); i < (5); ++i) {
nums[i] = 0;
}
scanf("%d\n", &N);
for (int i = (0); i < (N); ++i) {
getline(cin, buf);
switch (buf[0]) {
case 'M':
(nums[0])++;
break;
case 'A':
(nums[1])++;
break;
case 'R':
(nums[2])++;
break;
case 'C':
(nums[3])++;
break;
case 'H':
(nums[4])++;
break;
}
}
printf("%d\n", nums[0] * nums[1] * nums[2] + nums[0] * nums[1] * nums[3] +
nums[0] * nums[1] * nums[4] + nums[0] * nums[2] * nums[3] +
nums[0] * nums[2] * nums[4] + nums[0] * nums[3] * nums[4] +
nums[1] * nums[2] * nums[3] + nums[1] * nums[2] * nums[4] +
nums[1] * nums[3] * nums[4] + nums[2] * nums[3] * nums[4]);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
N=int(input())
S=[]
m=a=r=c=h=0
for i in range(N):
S.append(list(input()))
if S[i][0]=="M": m+=1
elif S[i][0]=="A": a+=1
elif S[i][0]=="R": r+=1
elif S[i][0]=="C": c+=1
elif S[i][0]=="H": h+=1
t=0
if m>=1: t+=1
if a>=1: t+=1
if r>=1: t+=1
if c>=1: t+=1
if h>=1: t+=1
ans=math.factorial(t)//6
if m>1:
ans*=m
ans-=t-3
if a>1:
ans*=a
ans-=t-3
if r>1:
ans*=r
ans-=t-3
if c>1:
ans*=c
ans-=t-3
if h>1:
ans*=h
ans-=t-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;
const double eps = 1e-10;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
int main() {
int n;
cin >> n;
vector<int> v(5);
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
if (s[0] == 'M') v[0]++;
if (s[0] == 'A') v[1]++;
if (s[0] == 'R') v[2]++;
if (s[0] == 'C') v[3]++;
if (s[0] == 'H') v[4]++;
}
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 += 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 | java | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
int m=0,a=0,r=0,c=0,h=0;
for(int i=0;i<n;i++){
String p=sc.next();
if(p.charAt(0)=='M')m++;
if(p.charAt(0)=='A')a++;
if(p.charAt(0)=='R')r++;
if(p.charAt(0)=='C')c++;
if(p.charAt(0)=='H')h++;
}
long 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;
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;
unsigned long long n, k, a, wynik, roz, p;
int t[5];
int tab[100];
string b;
int main() {
scanf("%llu", &n);
for (int i = 0; n > i; i++) {
cin >> b;
tab[b[0]]++;
}
if (tab[77] > 0) wynik++;
if (tab[65] > 0) wynik++;
if (tab[82] > 0) wynik++;
if (tab[67] > 0) wynik++;
if (tab[72] > 0) wynik++;
t[0] = tab[77];
t[1] = tab[65];
t[2] = tab[82];
t[3] = tab[67];
t[4] = tab[72];
sort(t, t + 5);
if (wynik - 2 > 0) roz += (wynik - 1) * (wynik - 2) / 2 * t[4];
if (wynik - 3 > 0) roz += (wynik - 2) * (wynik - 3) / 2 * t[3];
;
if (wynik - 4 > 0) roz += (wynik - 3) * (wynik - 4) / 2 * t[2];
if (wynik - 5 > 0) roz += (wynik - 4) * (wynik - 5) / 2 * t[1];
if (wynik - 6 > 0) roz += (wynik - 5) * (wynik - 6) / 2 * t[0];
cout << roz;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int s[maxn], t[maxn], c[maxn];
pair<int, int> b[maxn];
int cha[5];
int main() {
int n;
cin >> n;
for (int i = 0; i < 5; i++) cha[i] = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') cha[0]++;
if (s[0] == 'A') cha[1]++;
if (s[0] == 'R') cha[2]++;
if (s[0] == 'C') cha[3]++;
if (s[0] == 'H') cha[4]++;
}
long long res = 0LL;
long long dp[8][8];
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
res += cha[i] * cha[j] * cha[k];
}
}
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | # -*- coding: utf-8 -*-
N = int(input())
name = []
for i in range(0,N):
data = input()
name.append(data)
check = 0
check_m = 0
check_a = 0
check_r = 0
check_c = 0
check_h = 0
for i in name:
if i[0] == "M":
if check_m == 0:
check += 1
check_m += 1
elif i[0] == "A":
if check_a == 0:
check += 1
check_a += 1
elif i[0] == "R":
if check_r == 0:
check += 1
check_r += 1
elif i[0] == "C":
if check_c == 0:
check += 1
check_c += 1
elif i[0] == "H":
if check_h == 0:
check += 1
check_h += 1
if check < 3:
print(0)
elif check == 3:
s = []
if check_m != 0:
s.append(check_m)
if check_a != 0:
s.append(check_a)
if check_r != 0:
s.append(check_r)
if check_c != 0:
s.append(check_c)
if check_h != 0:
s.append(check_h)
se = 1
for i in s:
se = se*i
print(int(se))
elif check == 4:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = (check*(check-1)*(check-2))/6
if len(s) == 0:
print(int(n))
else:
se = 1
for i in s:
se += i*(n-1)
print(int(se))
elif check == 5:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = (check*(check-1)*(check-2))/6
if len(s) == 0:
print(int(n))
else:
se = n - sum(s) + 1
for i in s:
se += i*(n-1)
print(int(se)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M = 0, A = 0, R = 0, C = 0, H = 0, sum = 0;
long long int ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M') {
if (M == 0) sum++;
M++;
}
if (S[0] == 'A') {
if (A == 0) sum++;
A++;
}
if (S[0] == 'R') {
if (R == 0) sum++;
R++;
}
if (S[0] == 'C') {
if (C == 0) sum++;
C++;
}
if (S[0] == 'H') {
if (H == 0) sum++;
H++;
}
}
if (sum >= 3) {
int k = 0;
if (sum == 3) {
ans = 1;
if (M >= 2) ans += (ans) * (M - 1);
if (A >= 2) ans += (ans) * (A - 1);
if (R >= 2) ans += (ans) * (R - 1);
if (C >= 2) ans += (ans) * (C - 1);
if (H >= 2) ans += (ans) * (H - 1);
}
if (sum == 4) {
ans = 4;
k = 1;
if (M >= 2) {
ans += (ans - 1 * k) * (M - 1);
k += (M - 1);
}
if (A >= 2) {
ans += (ans - 1 * k) * (A - 1);
k += (A - 1);
}
if (R >= 2) {
ans += (ans - 1 * k) * (R - 1);
k += (R - 1);
}
if (C >= 2) {
ans += (ans - 1 * k) * (C - 1);
k += (C - 1);
}
if (H >= 2) {
ans += (ans - 1 * k) * (H - 1);
k += (H - 1);
}
}
if (sum == 5) {
ans = 10;
k = 1;
if (M >= 2) {
ans += (ans - 4 * k) * (M - 1);
k += (M - 1);
}
if (A >= 2) {
ans += (ans - 4 * k) * (A - 1);
k += (A - 1);
}
if (R >= 2) {
ans += (ans - 4 * k) * (R - 1);
k += (R - 1);
}
if (C >= 2) {
ans += (ans - 4 * k) * (C - 1);
k += (C - 1);
}
if (H >= 2) {
ans += (ans - 4 * k) * (H - 1);
k += (H - 1);
}
}
}
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 | def main():
n = int(input())
num_m = 0
num_a = 0
num_r = 0
num_c = 0
num_h = 0
inlis = []
for i in range(n):
s = input()
if s in inlis:
pass
else:
inlis.append(s)
if s[0] == "M":
num_m += 1
if s[0] == "A":
num_a += 1
if s[0] == "R":
num_r += 1
if s[0] == "C":
num_c += 1
if s[0] == "H":
num_h += 1
numlis = [num_m, num_a, num_r, num_c, num_h]
ans = 0
if sum(numlis) < 3:
print(0)
else:
for i in range(5):
for j in range(5):
for k in range(5):
if i == j or i == k or j == k:
pass
else:
ans += numlis[i] * numlis[j] * numlis[k]
print(int(ans/6))
if __name__ == "__main__":
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
public static void Main() {
// 終了後回答
int N = int.Parse(Console.ReadLine());
string[] names = new string[N];
for (int i = 0; i < N; i++) {
names[i] = Console.ReadLine();
}
int[] MARCH = new[]{ 'M', 'A', 'R', 'C', 'H' }.Select(c => names.Count(s => s[0] == c)).ToArray();
int M = MARCH[0], A = MARCH[1], R = MARCH[2], C = MARCH[3], H = MARCH[4];
// MARCH(5C3=10): MAR, MAC, MAH, MRC, MRH, MCH, ARC, ARH, ACH, RCH;
long res = 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;
Console.WriteLine(res);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | incloud.(studio.h)
int main()
{
int MASHIKE,RUMOI,OBIRA,HABORO,HOROKANAI,;
char s [11];
scanf ("%d", &MASAKI);
scanf ("%d %d %d %d %d" ,&RUMOI,BIRA,HABORO,HOROKANAI);
scanf ("%d",s);
printf("%d %s\n" ,2);
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 | #!/usr/bin/env python3
#ABC89 C
import math
n = int(input())
s = [input() for _ in range(n)]
x = ['M','A','R','C','H']
a = [0]*5
def c(n,r):
return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
for i in s:
if i[0] in x:
a[x.index(i[0])] += 1
s = 0
t = 1
u = 0
for i in a:
if i != 0:
s += 1
if i > 1:
t *= i
u += 1
if s <= 2:
print(0)
else:
ans = c(s,3)
ans *= t
if s > 3:
ans -= u
print(int(ans))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
string str;
vector<long long> cnt(5, 0);
for (int i = (int)0; i < (int)N; ++i) {
cin >> str;
switch (str[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;
}
}
sort((cnt).begin(), (cnt).end(), std::greater<int>());
long long ans = 0ll, sum;
for (int i = (int)0; i < (int)5; ++i) {
sum = 0ll;
if (cnt[i] == 0) continue;
for (int j = (int)i + 1; j < (int)5; ++j) {
if (cnt[j] == 0) continue;
for (int k = (int)j + 1; k < (int)5; ++k) {
if (cnt[k] == 0) continue;
++sum;
}
}
ans += sum * cnt[i];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m = 0, a = 0, r = 0, c = 0, h = 0;
int count = 0;
cin >> n;
string str;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M') {
m++;
if (m == 1) {
count++;
}
} else if (str[0] == 'A') {
a++;
if (a == 1) {
count++;
}
} else if (str[0] == 'R') {
r++;
if (r == 1) {
count++;
}
} else if (str[0] == 'C') {
c++;
if (c == 1) {
count++;
}
} else if (str[0] == 'H') {
h++;
if (h == 1) {
count++;
}
}
}
int re = 0, s = 1;
for (int i = count; i > count - 3 && i > 0; i--) {
s *= i;
}
if (h == 0) {
h++;
}
if (c == 0) {
c++;
}
if (r == 0) {
r++;
}
if (a == 0) {
a++;
}
if (m == 0) {
m++;
}
re = s / 6 * m * a * r * c * h;
if (count < 3) {
cout << "0";
} else {
cout << re;
}
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 double PI = 3.14159265358979323846;
int count(uint32_t x) {
int ret = 0;
while (x) {
if (x & 1) ++ret;
x >>= 1;
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
map<char, int64_t> m;
for (int i = 0; i < n; ++i) {
cin >> s;
++m[s[0]];
}
s = "MARCH";
int64_t ans = 0;
for (int i = 0; i < (1 << 5); ++i) {
if (count(i) == 3) {
int temp = i;
int cnt = 0;
int64_t sum = 1;
while (temp) {
if (temp & 1) {
sum = (sum * m[s[cnt]]) % 1000000007ULL;
}
++cnt;
temp >>= 1;
}
ans = (ans + sum) % 1000000007ULL;
}
}
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;
long long combination(int n, int r) {
if (n == r)
return (1);
else if (r == 0)
return (1);
else if (r == 1)
return (n);
else
return (combination(n - 1, r - 1) + combination(n - 1, r));
}
int main() {
long long n;
cin >> n;
char s[11];
int a[5] = {};
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
a[0] += 1;
} else if (s[0] == 'A') {
a[1] += 1;
} else if (s[0] == 'R') {
a[2] += 1;
} else if (s[0] == 'C') {
a[3] += 1;
} else if (s[0] == 'H') {
a[4] += 1;
}
}
long long cnt = 0;
long long cnt1 = 0;
for (int i = 0; i < 5; i++) {
if (a[i] >= 1) {
cnt++;
}
if (a[i] >= 2) {
cnt1 += (a[i] - 1);
}
}
if (cnt == 3) {
cout << combination(cnt, 3) + cnt1 << endl;
} else if (cnt == 4) {
cout << combination(cnt, 3) + (cnt1 * 3) << endl;
} else if (cnt == 5) {
cout << combination(cnt, 3) + (cnt1 * 6) << endl;
} else {
cout << 0 << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int long long a[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < n; i++) {
string x;
cin >> x;
if (x[0] == 'M') {
a[0]++;
} else if (x[0] == 'A') {
a[1]++;
} else if (x[0] == 'R') {
a[2]++;
} else if (x[0] == 'C') {
a[3]++;
} else if (x[0] == 'H') {
a[4]++;
}
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
if (i == 0) {
for (int j = 0; j < 3; j++) {
ans += a[i] * a[1] * a[2 + j];
}
for (int j = 0; j < 2; j++) {
ans += a[i] * a[2] * a[3 + j];
}
ans += a[i] * a[3] * a[4];
}
if (i == 1) {
for (int j = 0; j < 2; j++) {
ans += a[i] * a[2] * a[3 + j];
}
ans += a[i] * a[3] * a[4];
} else {
ans += a[i] * a[3] * a[4];
}
}
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() {
char a[100000][10];
int b;
long double h = 0;
int c = 0, d = 0, e = 0, f = 0, g = 0;
cin >> b;
for (int i = 0; i < b; i++) cin >> a[i];
for (int i = 0; i < b; i++) {
if (a[i][0] == 'M') c++;
if (a[i][0] == 'A') d++;
if (a[i][0] == 'R') e++;
if (a[i][0] == 'C') f++;
if (a[i][0] == 'H') g++;
}
h = c * d * e + c * d * f + c * d * g + c * e * f + c * e * g + c * f * g +
d * e * f + d * e * g + d * f * g + e * f * g;
cout << 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;
int main() {
string s = "MARCH";
int c[5] = {0};
long long n;
cin >> n;
for (int i = 0; i < n; ++i) {
string t;
cin >> t;
for (int j = 0; j < 5; ++j) {
if (t[0] == s[j]) {
c[j]++;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct edge {
int to, cost;
};
const int INF = 100000000;
int main() {
long long int n, num[10] = {}, ans = 0;
cin >> n;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
num[0]++;
} else if (s[0] == 'A') {
num[1]++;
} else if (s[0] == 'R') {
num[2]++;
} else if (s[0] == 'C') {
num[3]++;
} else if (s[0] == 'H') {
num[4]++;
}
}
for (int Bit = 0; Bit < (1 << 5); Bit++) {
int e = 1, count = 0;
bitset<5> b(Bit);
for (int i = 0; i < (5); i++) {
if (b[i] == 1) {
count++;
e *= num[i];
}
}
if (count == 3) {
{} {}
ans += e;
}
}
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;
bool check(string s) {
for (int i = 0; i < s.size(); i++) {
s[i] = char(tolower(s[i]));
}
for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[5] = {
0,
};
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
a[0]++;
}
if (s[0] == 'A') {
a[1]++;
}
if (s[0] == 'R') {
a[2]++;
}
if (s[0] == 'C') {
a[3]++;
}
if (s[0] == 'H') {
a[4]++;
}
}
long long sum = 0, k = 0;
for (int i = 0; i < 5; i++) {
if (a[i]) {
k++;
}
}
for (int i = 0; i < 5; i++) {
if (a[i] > 1) {
sum += (k - 1) / 3 * a[i];
} else {
sum += a[i];
}
}
cout << sum;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] cnt = new int[5];
for(int i = 0; i<N; i++) {
String x = sc.next().substring(0,1);
if(x.equals("M")) cnt[0]++;
if(x.equals("A")) cnt[1]++;
if(x.equals("R")) cnt[2]++;
if(x.equals("C")) cnt[3]++;
if(x.equals("H")) cnt[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 += cnt[i]*cnt[j]*cnt[k];
}
}
}
System.out.println(sum);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S[N];
for (int i = 0; i < N; i++) cin >> S[N];
int count[5];
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M') {
count[0]++;
} else if (S[i][0] == 'A') {
count[1]++;
} else if (S[i][0] == 'R') {
count[2]++;
} else if (S[i][0] == 'C') {
count[3]++;
} else if (S[i][0] == 'H') {
count[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 += count[i] * count[j] * count[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;
string s;
long long m, a, r, c, h = 0;
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> N;
while (N--) {
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++;
}
long long d[5];
long long x = 0;
d[0] = m, d[1] = a, d[2] = r, d[3] = c, d[4] = h;
for (int i = 0; i < 10; i++) {
x += d[P[i]] * d[Q[i]] * d[R[i]];
}
cout << x << "\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;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <typename P, typename Q>
istream& operator>>(istream& is, pair<P, Q>& p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "(";
for (auto& i : v) os << i << ",";
os << ")";
return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto& i : v) is >> i;
return is;
}
template <typename T>
inline T setmax(T& a, T b) {
return a = std::max(a, b);
}
template <typename T>
inline T setmin(T& a, T b) {
return a = std::min(a, b);
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
while (cin >> n) {
vector<string> v(n);
cin >> v;
map<char, int> m;
for (auto& i : v) ++m[i[0]];
const string s = "MARCH";
long long int sum = 0;
for (int i = 0; i < s.size(); ++i) {
for (int j = i + 1; j < s.size(); ++j) {
for (int k = j + 1; k < s.size(); ++k) {
sum += m[s[i]] * m[s[j]] * m[s[k]];
}
}
}
cout << sum << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.first == b.first) return a.second < b.second;
return a.first < b.first;
}
ll m, a, r, c, h;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
for (int(i) = 0; (i) < (N); ++(i)) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
cout << m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + r * c * h
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> num(5, 0);
string x = "MARCH";
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == x[j]) num[j]++;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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())
s=list(input() for i in range(n))
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
if s[i][0] == "M" and not s[i] in m:
m.append(s[i])
elif s[i][0] == "A" and not s[i] in a:
a.append(s[i])
elif s[i][0] == "R" and not s[i] in r:
r.append(s[i])
elif s[i][0] == "C" and not s[i] in c:
c.append(s[i])
elif s[i][0] == "H" and not s[i] in h:
h.append(s[i])
num = len(m)+len(a)+len(r)+len(c)+len(h)
print(math.factorial(num)/(math.factorial(3)*math.factorial(num))) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9 + 7;
const int INF = (1 << 30) - 1;
const ll INFLL = (1LL << 62) - 1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
string MARCH = "MARCH";
int c[5] = {0};
int N;
cin >> N;
for (int i = (0); i < ((N)); ++i) {
string S;
cin >> S;
for (int j = (0); j < ((5)); ++j) {
if (S[0] == MARCH[j]) {
c[j]++;
}
}
}
for (int i = (0); i < ((5)); ++i) {
cout << "c[i]"
<< " = " << (c[i]) << endl;
;
}
int ans = 0;
for (int i = (0); i < (5); ++i) {
for (int j = (i + 1); j < (5); ++j) {
for (int k = (j + 1); k < (5); ++k) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
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 h[5];
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++) {
cin >> 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, mc = 0, ac = 0, rc = 0, cc = 0, hc = 0;
cin >> N;
string s;
char temp;
for (int i = 0; i < (int)(N); ++i) {
cin >> s;
temp = s.at(0);
if (temp == 'M') ++mc;
if (temp == 'A') ++ac;
if (temp == 'R') ++rc;
if (temp == 'C') ++cc;
if (temp == 'H') ++hc;
}
cout << (mc * ac * rc) + (mc * ac * cc) + (mc * ac * hc) + (mc * rc * cc) +
(mc * rc * hc) + (mc * cc * hc) + (ac * rc * cc) +
(ac * rc * hc) + (ac * cc * hc) + (rc * cc * hc)
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n;
cin >> n;
int c[5] = {};
for (int i = 0, i_len = (n); i < i_len; ++i) {
string s;
cin >> s;
switch (s[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;
}
}
long long ans = 0;
ans += c[0] * c[1] * c[2];
ans += c[0] * c[1] * c[3];
ans += c[0] * c[1] * c[4];
ans += c[0] * c[2] * c[3];
ans += c[0] * c[2] * c[3];
ans += c[1] * c[2] * c[3];
ans += c[1] * c[2] * c[4];
ans += c[2] * c[3] * c[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> cnt(5);
for (long long i = 0; i < (long long)(n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
cnt[0]++;
}
if (s[0] == 'A') {
cnt[1]++;
}
if (s[0] == 'R') {
cnt[2]++;
}
if (s[0] == 'C') {
cnt[3]++;
}
if (s[0] == 'H') {
cnt[4]++;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <stdio.h>
#include <string.h>
main()
{
long a[5] = {0,0,0,0,0};
int N;
scanf("%d", &N);
int k;
for(k = 1; k <= N; k++);
{
char s[11];
scanf("%s", s);
if(s[0] == 'M') a[0]++;
if(s[0] == 'A') a[1]++;
if(s[0] == 'R') a[2]++;
if(s[0] == 'C') a[3]++;
if(s[0] == 'H') a[4]++;
}
int O = 0;
int s, t, r;
for(s=1; s<=3; s++)
{for(t=s+1; t<=4; t++)
{for(r=s+2; r<=5; r++)
{O += a[s]*a[t]*a[r]
}}}
printf("%d", O);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program
{
internal static void Main(string[] args)
{
var N = int.Parse(ReadLine());
var S = new Dictionary<String, int>() {
{"M", 0},
{"A", 0},
{"R", 0},
{"C", 0},
{"H", 0}
};
for (int i = 0; i < N; i++) {
var str = ReadLine().Substring(0, 1);
switch (str) {
case "M":
case "A":
case "R":
case "C":
case "H":
if (S.ContainsKey(str)) {
S[str]++;
}
break;
}
}
string[] p = { "M", "M", "M", "M", "M", "M", "A", "A", "A", "R" };
string[] q = { "A", "A", "A", "R", "R", "C", "R", "R", "C", "C" };
string[] r = { "R", "C", "H", "C", "H", "H", "C", "H", "H", "H" };
long ans = 0;
for (int i = 0; i < 10; i++) {
ans += S[p[i]] * S[q[i]] * S[r[i]];
}
WriteLine(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9;
const long long MOD = (long long)1e9 + 7;
const double EPS = (double)1e-10;
struct Accelerate_Cin {
Accelerate_Cin() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
};
long long N;
string s;
signed main() {
cin >> N;
map<char, long long> mp;
for (long long t = 0; t < N; t++) {
cin >> s;
mp[s[0]]++;
}
long long ans = mp['M'] * (mp['A'] * (mp['R'] + mp['C'] + mp['H']) +
mp['R'] * (mp['C'] + mp['H']) + mp['C'] * mp['H']);
ans +=
mp['A'] * (mp['R'] * (mp['C'] + mp['H'])) + mp['R'] * mp['C'] * mp['H'];
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 | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N;
long M=0,A=0,R=0,C=0,H=0;
ArrayList<Long> numlist = new ArrayList<>();
N = sc.nextInt();
for (int a = 0; a < N; a++) {
String name = sc.next();
if(name.indexOf('M')==0){
M++;
}
else if(name.indexOf('A')==0){
A++;
}
else if(name.indexOf('R')==0){
R++;
}
else if(name.indexOf('C')==0){
C++;
}
else if(name.indexOf('H')==0){
H++;
}
}
numlist.add(M);
numlist.add(A);
numlist.add(R);
numlist.add(C);
numlist.add(H);
long num =0;
for(int a=0;a<3;a++){
for(int b=a+1;b<4;b++){
for(int c=b+1;c<5;c++){
if(numlist.get(a)!=0&&numlist.get(b)!=0&&numlist.get(c)!=0)
num =+(numlist.get(a)*numlist.get(b)*numlist.get(c));
}
}
}
System.out.println(num);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int num;
int m = 0, a = 0, r = 0, c = 0, h = 0;
long long int ans = 0, mix[10];
char name[100000][11];
scanf("%d", &num);
for (int i = 0; i < num; 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;
default:
break;
}
}
mix[0] = m * a * r;
mix[1] = m * a * c;
mix[2] = m * a * h;
mix[3] = m * r * c;
mix[4] = m * r * h;
mix[5] = m * c * h;
mix[6] = a * r * c;
mix[7] = a * r * h;
mix[8] = a * c * h;
mix[9] = r * c * h;
for (int i = 0; i < 10; i++) {
ans += mix[i];
}
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 | UNKNOWN | import std.stdio,
std.string,
std.conv;
void main() {
int N = to!int(readln.chomp);
int[char] hash;
for (int i = 0; i < N; i++) {
string s = readln.chomp;
if ("MARCH".count(s[0])) {
hash[s[0]]++;
}
}
int[] a = hash.values ~ [0, 0, 0, 0, 0];
ulong 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];
}
}
}
writeln(ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | /*
* @Author Silviase(@silviasetitech)
* For ProCon
*/
import java.util.*;
import java.lang.*;
import java.math.*;
class Main{
static int n;
static int c;
static int k;
static int lef;
static int rig;
static String s;
static String anss;
static int[] times;
static long ans;
static int[] w;
static int[] ww;
static boolean[] visit;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
ans = 0;
String[] st = new String[n];
long[] m = new long[5];
for (int i = 0; i < n; i++) {
st[i] = sc.next();
if (st[i].charAt(0) == 'M') {
m[0]++;
}
if (st[i].charAt(0) == 'A') {
m[1]++;
}
if (st[i].charAt(0) == 'R') {
m[2]++;
}
if (st[i].charAt(0) == 'C') {
m[3]++;
}
if (st[i].charAt(0) == 'H') {
m[4]++;
}
}
System.out.println(
m[0]*m[1]*(m[2]+m[3]+m[4]) + m[0]*m[2]*(m[3]+m[4]) + m[0]*m[3]*m[4]
+m[1]*m[2]*(m[3]+m[4]) + m[1]*m[3]*m[4] + m[2]*m[3]*m[4]
);
sc.close();
}
public static long gcd(long a, long b) {
if (a < b) {
long tmpp = a;
a = b;
b = tmpp;
}
if (b == 0) {
return a;
}else{
return gcd(b, a%b);
}
}
public static long lcm(long a, long b) {
long gcd = gcd(a,b);
return a/gcd*b;
}
public static void dfs(int placenow) {
// if went all -> success!
// if not went all -> fail...
/*
dfs
Go All Place that there is way to and not having been yet.
if island 1 is start point, dfs(1);
if there is way to island 2 and island 3,
- island 2 changes non-visited -> visited, and dfs(2).
- island 3 changes non-visited -> visited, and dfs(3).
*/
visit[placenow] = true;
boolean success = true;
for (int i = 0; i < n; i++) {
if (visit[i] == false) { // not go all place
success = false;
break;
}
}
if (success) {
ans++;
visit[placenow] = false;
return;
}
for (int i = 0; i < m; i++) {
if (w[i] == placenow && visit[ww[i]] == false ) {
dfs(ww[i]);
}else if(ww[i] == placenow && visit[w[i]] == false){
dfs(w[i]);
}else{
continue;
}
}
visit[placenow] = false;
return;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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())
name = [0]*n
s = []
for i in range(n):
st = input()
if st[0] == 'M':
name[0] += 1
elif st[0] == 'A':
name[1] += 1
elif st[0] == 'R':
name[2] += 1
elif st[0] == 'C':
name[3] += 1
elif st[0] == 'H':
name[4] += 1
s.append(st)
ans = 0
for v in itertools.combinations(name, 3):
# print(v)
ans += v[0]*v[1]*v[2]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n, m = 0, a = 0, r = 0, c = 0, h = 0;
long long sum = 0;
char s[100005][10];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%*c%s", 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++;
}
sum += m * a * r;
sum += m * a * c;
sum += m * a * h;
sum += m * r * c;
sum += m * r * h;
sum += m * c * h;
sum += a * r * c;
sum += a * r * h;
sum += a * c * h;
sum += r * c * h;
printf("%lld", 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>
template <class _T>
static _T tp_abs(const _T& a) {
return ((a < 0) ? (a * -1) : a);
}
template <class _T>
static void tp_swap(_T& right, _T& left) {
_T tmp = right;
right = left;
left = tmp;
}
template <class _T>
static _T tp_min(_T a, _T b) {
return a < b ? a : b;
}
template <class _T>
static _T tp_max(_T a, _T b) {
return a > b ? a : b;
}
template <class _T>
static void get1int(_T& a) {
const char* fmt = " %d";
if (sizeof(_T) == sizeof(long long)) {
fmt = " %lld";
}
if (scanf(fmt, &a) < 0) {
printf("g1int Error\n");
}
}
template <class _T>
static void get2int(_T& a, _T& b) {
const char* fmt = " %d %d";
if (sizeof(_T) == sizeof(long long)) {
fmt = " %lld %lld";
}
if (scanf(fmt, &a, &b) < 0) {
printf("g2int Error\n");
}
}
template <class _T>
static void get3int(_T& a, _T& b, _T& c) {
const char* fmt = " %d %d %d";
if (sizeof(_T) == sizeof(long long)) {
fmt = " %lld %lld %lld";
}
if (scanf(fmt, &a, &b, &c) < 0) {
printf("g3int Error\n");
}
}
static void getstring(char* buff) {
if (scanf(" %s", buff) < 0) {
printf("getstr error!\n");
}
}
static void ABC089C_March();
int main() {
ABC089C_March();
fflush(stdout);
return 0;
}
static void ABC089C_March() {
int N;
get1int(N);
std::map<char, long long> nList;
for (int i = 0; i < N; i++) {
char names[11] = {0};
getstring(names);
nList[names[0]]++;
}
int iniKind = 0;
const char* initial = "MARCH";
for (int i = 0; i < 5; i++) {
if (nList.find(initial[i]) != nList.end()) {
iniKind++;
}
}
if (iniKind < 3) {
printf("0\n");
return;
}
long long pattern = 0;
for (int i = 0; i < iniKind - 2; i++) {
for (int j = i + 1; j < iniKind - 1; j++) {
for (int k = j + 1; k < iniKind; k++) {
pattern += nList[initial[i]] * nList[initial[j]] * nList[initial[k]];
}
}
}
printf("%lld\n", pattern);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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;
map<char, int> mci;
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
continue;
}
mci[s[0]]++;
}
vector<ll> fac(100);
fac[0] = 1;
for (int i = 0; i < 100; i++) {
fac[i + 1] = fac[i] * (i + 1);
}
ll countable = mci.size();
if (countable < 3) {
cout << 0 << endl;
return 0;
}
ll ans = 0;
for (auto v : mci) {
if (v.second < 2) continue;
if (countable > 3) {
ll tmp = fac[countable - 1] / (fac[countable - 3] * fac[2]);
ans += tmp * v.second;
ans += fac[countable - 1] / (fac[countable - 4] * fac[3]);
} else {
ans = fac[countable] / (fac[countable - 3] * fac[3]);
ans *= v.second;
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long INF = 1000000009;
void solve() {
int n;
cin >> n;
string s[n + 10];
for (long long i = 0; i < n; i++) {
cin >> s[i];
}
int count[5];
for (long long i = 0; i < 5; i++) {
count[i] = 0;
}
for (long long i = 0; i < n; i++) {
char c = s[i][0];
if (c == 'M') count[0]++;
if (c == 'A') count[1]++;
if (c == 'R') count[2]++;
if (c == 'C') count[3]++;
if (c == 'H') count[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
if (i < j && j < k) ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int d[5] = {0};
int main() {
string str;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> str;
switch (str[0]) {
case 'M':
d[0]++;
break;
case 'A':
d[1]++;
break;
case 'R':
d[2]++;
break;
case 'C':
d[3]++;
break;
case 'H':
d[4]++;
break;
default:
break;
}
}
int cnt = 0;
for (int i = 0; i + 2 < 5; i++) {
for (int j = i + 1; j + 1 < 5; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += d[i] * d[j] * d[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>
using namespace std;
int main() {
int n;
cin >> n;
int a[10] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
a[1]++;
else if (s[0] == 'A')
a[2]++;
else if (s[0] == 'R')
a[3]++;
else if (s[0] == 'C')
a[4]++;
else if (s[0] == 'H')
a[5]++;
}
unsigned long long ans = 0;
for (int i = 1; i <= 3; i++) {
for (int j = i + 1; j <= 4; j++) {
for (int k = j + 1; k <= 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
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() {
long long int n, p[5];
string s;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s[0] == 'M') p[0]++;
if (s[0] == 'A') p[1]++;
if (s[0] == 'R') p[2]++;
if (s[0] == 'C') p[3]++;
if (s[0] == 'H') p[4]++;
}
long long 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 += p[i] * p[j] * p[k];
}
}
}
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 N = 3e4 + 5;
int a[100];
int main() {
int n;
while (~scanf("%d", &n)) {
memset(a, 0, sizeof(a));
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
a[1]++;
else if (s[0] == 'A')
a[2]++;
else if (s[0] == 'R')
a[3]++;
else if (s[0] == 'C')
a[4]++;
else if (s[0] == 'H')
a[5]++;
}
int sum = 0, ans = 0, k = 0;
for (int i = 1; i < 6; i++) {
if (a[i] == 1)
sum++;
else if (a[i] != 0)
ans++;
k += a[i];
if (a[i] == 2) {
a[i * 10 + 2] = a[i] * (a[i] - 1) / 2;
} else if (a[i] >= 3)
a[i * 10 + 3] = a[i] * (a[i] - 1) * (a[i] - 2) / 6;
}
if (ans + sum < 3 || n < 3)
printf("0\n");
else {
int cnt = k * (k - 1) * (k - 2) / 6;
for (int i = 1; i < 6; i++) {
cnt = cnt - a[i * 10 + 3];
cnt -= sum * a[i * 10 + 2];
}
for (int i = 1; i < 6; i++) {
for (int j = 1; j < 6 && i != j && a[i] != 1 && a[j] != 1; j++) {
cnt -= a[i] * a[j * 10 + 2];
}
}
printf("%d\n", cnt);
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const long long int LLINF = 1LL << 60;
const long long int MOD = 1000000007;
const double EPS = 1e-19;
uintmax_t ncr(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;
}
signed main() {
long long int n;
cin >> n;
long long int ans = 0;
long long int sum = 0;
vector<long long int> cnt(5, 0);
string s;
for (long long int i = 0; i < (n); ++i) {
cin >> s;
if (s[0] == 'M') {
cnt[0]++;
sum++;
}
if (s[0] == 'A') {
cnt[1]++;
sum++;
}
if (s[0] == 'R') {
cnt[2]++;
sum++;
}
if (s[0] == 'C') {
cnt[3]++;
sum++;
}
if (s[0] == 'H') {
cnt[4]++;
sum++;
}
}
if (sum < 3) {
cout << (0) << endl;
return 0;
}
ans = ncr(sum, 3);
for (long long int i = 0; i < (5); ++i) {
if (cnt[i] >= 3) {
ans -= ncr(cnt[i], 3) - (ncr(cnt[i], 2) * (sum - cnt[i]));
continue;
}
if (cnt[i] == 2) {
ans -= (sum - cnt[i]);
continue;
}
}
cout << (ans) << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
class Main
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] y = new int[5];
Arrays.fill(y, 0);
for(int i = 0; i < n; i++){
char x = sc.next().charAt(0);
switch(x){
case 'M': y[0]++; break;
case 'A': y[1]++; break;
case 'R': y[2]++; break;
case 'C': y[3]++; break;
case 'H': y[4]++; break;
default: break;
}
}
long ans = 0;
for(int i = 0; i < 3; i++)
for(int j = i+1; j < 4; j++)
for(int k = j+1; k < 5; k++)
ans += y[i] * y[j] * y[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;
long long fact(long long k) {
if (k == 0) return 1;
return k * fact(k - 1);
}
int main() {
long long N;
cin >> N;
map<char, long long> word;
map<char, bool> check;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' || S[i][0] == 'C' ||
S[i][0] == 'H') {
word[S[i][0]]++;
}
}
if (word.size() < 3) {
cout << 0 << endl;
return 0;
}
long long sum;
sum = fact(word.size()) / 6;
long long minus[3] = {1, 3, 16};
long long i = 0;
if (word.size() == 4)
i = 1;
else if (word.size() == 5)
i = 2;
if (word['M'] > 1) sum += (word['M'] - 1) * minus[i];
if (word['A'] > 1) sum += (word['A'] - 1) * minus[i];
if (word['R'] > 1) sum += (word['R'] - 1) * minus[i];
if (word['C'] > 1) sum += (word['C'] - 1) * minus[i];
if (word['H'] > 1) sum += (word['H'] - 1) * minus[i];
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int M;
vector<int> initial(5, 0);
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M') {
M++;
initial[0]++;
} else if (S[0] == 'A') {
initial[1]++;
M++;
} else if (S[0] == 'R') {
M++;
initial[2]++;
} else if (S[0] == 'C') {
M++;
initial[3]++;
} else if (S[0] == 'H') {
M++;
initial[4]++;
}
}
long long comb = M * (M - 1) * (M - 2) / 6;
for (int i = 0; i < 5; i++) {
int init = initial[i];
if (init > 2) comb -= init * (init - 1) * (init - 2) / 6;
if (init > 1) comb -= init * (init - 1) * (M - init) / 2;
}
cout << comb << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n,c[5],ans=0;
cin>>n;
string s[100000];
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++){
if(s[i][0]=='M')s[0]++;
if(s[i][0]=='A')s[1]++;
if(s[i][0]=='R')s[2]++;
if(s[i][0]=='C')s[3]++;
if(s[i][0]=='H')s[4]++;
}
for(int i=0;i<n-2;i++){
for(int j=1;j<n-1;j++){
for(int k=2;k<n;k++){
ans+=s[i]*s[j]*s[k];
}
}
}
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = 0;
int a=0;
int r=0;
int c=0;
int h=0;
//Pattern pat = new Pattern.compile("^M");
//Scanner sc2 = new Scanner(System.in);
/*for(int i = 0;i < 100;i++){
System.out.println(scanner.next());
}*/
int N = sc.nextInt();
String b = sc.nextLine();
//int N = Integer.parseInt(sc.next());
//System.out.println(N);
ArrayList<String> array = new ArrayList<String>();
for(int i = 0;i < N;i++){
String str = sc.nextLine();
array.add(str);
//System.out.println(str);
}
for(String str:array){
if(str.matches("^M")){
m++;
}else if(str.matches("^A")){
a++;
}else if(str.matches("^R")){
r++;
}else if(str.matches("^C")){
c++;
}else if(str.matches("^H")){
h++;
}
}
ArrayList<Integer> nums = new ArrayList<Integer>();
ArrayList<Integer> nums2 = new ArrayList<Integer>();
int num =0;
nums.add(m);
nums.add(a);
nums.add(r);
nums.add(c);
nums.add(h);
for(int lol:nums){
if(lol == 0){
num++;
}else{
nums2.add(lol);
}
}
if(num >=3){
System.out.println(0);
}else if(num == 2){
System.out.println(nums2.get(0)*nums2.get(1)*nums2.get(2));
}else if(num == 1){
int ans =nums2.get(0)*nums2.get(1)*nums2.get(2) +
nums2.get(0)*nums2.get(1)*nums2.get(3)+
nums2.get(0)*nums2.get(2)*nums2.get(3)+
nums2.get(3)*nums2.get(1)*nums2.get(2) ;
System.out.println(ans);
}else if(num == 0){
int ans = nums2.get(0)*nums2.get(1)*nums2.get(2)+
nums2.get(0)*nums2.get(1)*nums2.get(3)+
nums2.get(0)*nums2.get(1)*nums2.get(4)+
nums2.get(0)*nums2.get(3)*nums2.get(2)+
nums2.get(0)*nums2.get(4)*nums2.get(2)+
nums2.get(0)*nums2.get(3)*nums2.get(4)+
nums2.get(3)*nums2.get(1)*nums2.get(2)+
nums2.get(4)*nums2.get(1)*nums2.get(2)+
nums2.get(4)*nums2.get(1)*nums2.get(3)+
nums2.get(4)*nums2.get(3)*nums2.get(2);
System.out.println(ans);
}
sc.close();
//sc2.close();
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 string march = "MARCH";
vector<tuple<char, char, char>> combinations;
void create_combinations(int depth, vector<char> now = {}) {
if (now.size() == 3) {
combinations.push_back(make_tuple(now[0], now[1], now[2]));
return;
}
if (depth == march.length()) return;
create_combinations(depth + 1, now);
vector<char> tmp = now;
tmp.push_back(march[depth]);
create_combinations(depth + 1, tmp);
}
int main() {
create_combinations(0);
map<char, int> cnt;
for (char ch : march) cnt[ch] = 0;
long long N;
cin >> N;
for (long long i = 0; i < N; i++) {
string tmp;
cin >> tmp;
for (auto p : cnt) {
if (p.first == tmp[0]) {
cnt[p.first]++;
}
}
}
unsigned long long ans = 0;
for (auto e : combinations) {
ans += cnt[get<0>(e)] * cnt[get<1>(e)] * cnt[get<2>(e)];
}
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 comb0[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int comb1[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int comb2[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main() {
int N;
cin >> N;
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') M++;
if (s[0] == 'A') A++;
if (s[0] == 'C') C++;
if (s[0] == 'R') R++;
if (s[0] == 'H') H++;
}
int comb[5] = {M, A, R, C, H};
long long ans = 0;
for (int i = 0; i < 10; i++) {
ans += comb[comb0[i]] * comb[comb1[i]] * comb[comb2[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 | # -*- coding: utf-8 -*-
N = int(input())
name = []
for i in range(0,N):
data = input()
name.append(data)
check = 0
check_m = 0
check_a = 0
check_r = 0
check_c = 0
check_h = 0
for i in name:
if i[0] == "M":
if check_m == 0:
check += 1
check_m += 1
elif i[0] == "A":
if check_a == 0:
check += 1
check_a += 1
elif i[0] == "R":
if check_r == 0:
check += 1
check_r += 1
elif i[0] == "C":
if check_c == 0:
check += 1
check_c += 1
elif i[0] == "H":
if check_h == 0:
check += 1
check_h += 1
if check < 3:
print(0)
elif check == 3:
s = []
if check_m != 0:
s.append(check_m)
if check_a != 0:
s.append(check_a)
if check_r != 0:
s.append(check_r)
if check_c != 0:
s.append(check_c)
if check_h != 0:
s.append(check_h)
se = 1
for i in s:
se = se*i
print(int(se))
elif check == 4:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = (check*(check-1)*(check-2))/6
if len(s) == 0:
print(int(n))
else:
se = 1
for i in s:
se += i*(n-1)
print(int(se))
elif check == 5:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = 10
n_1 = 5
if len(s) == 0:
print(int(n))
else:
se = n
for i in s:
se += i*(n_1)
print(int(se)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string a;
char b[5] = {0};
cin >> N;
while (N--) {
cin >> a;
if (a[0] == 'M')
b[0]++;
else if (a[0] == 'A')
b[1]++;
else if (a[0] == 'R')
b[2]++;
else if (a[0] == 'C')
b[3]++;
else if (a[0] == 'H')
b[4]++;
}
int s, flag = 0;
for (int i = 0; i < 5; i++)
if (b[i]) flag++;
if (flag < 3)
printf("0\n");
else if (flag == 3) {
s = 1;
for (int i = 0; i < 5; i++)
if (b[i]) s *= b[i];
printf("%d\n", s);
} else if (flag >= 4) {
s = 0;
int x, y, z;
for (x = 0; x < 3; x++)
for (y = x + 1; y < 4; y++)
for (z = y + 1; z < 5; z++)
if (b[x] && b[y] && b[z]) s += b[x] * b[y] * b[z];
printf("%d\n", s);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | # -*- coding: utf-8 -*-
import itertools
N = int(input())
a = [input() for i in range(N)]
march = {'M','A','R','C','H'}
b = [item for item in a if item[:1] in march]
c = list(itertools.combinations(b, 3))
d = []
for item in c:
initial_list = [name[:1] for name in item]
initial_set = set(initial_list)
if len(initial_list) == len(initial_set):
d.append(item)
print(len(d)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import numpy
import sys
import math
N=int(input())
a = []
for i in range(N):
a.append(input())
dic = {}
for n in a:
if n[0] in ['M','A','R','C','H']:
if n[0] not in dic:
dic[n[0]] = [n]
else:
dic[n[0]].append(n)
if len(dic)<3:
print(0)
exit()
basic = int(math.factorial(len(dic))/(math.factorial(3)*math.factorial(len(dic)-3)))
for i in dic:
names = dic[i]
if len(names)>1:
basic *= (2 * (len(names)-1))
basic -= (len(dic)-3)
print(basic) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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;
while (cin >> n) {
long long int ans = 0;
int ansm = 0, ansa = 0, ansr = 0, ansc = 0, ansh = 0;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
ansm++;
else if (s[0] == 'A')
ansa++;
else if (s[0] == 'R')
ansr++;
else if (s[0] == 'C')
ansc++;
else if (s[0] == 'H')
ansh++;
}
ans += ansm * ansa * ansr;
ans += ansm * ansa * ansc;
ans += ansm * ansa * ansh;
ans += ansm * ansr * ansc;
ans += ansm * ansr * ansh;
ans += ansm * ansc * ansh;
ans += ansa * ansr * ansc;
ans += ansa * ansr * ansh;
ans += ansa * ansc * ansh;
cout << ans << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long m = 0, a = 0, r = 0, c = 0, h = 0;
string s;
for (int i = 0; i < (n); i++) {
cin >> s;
if (s[0] == 'M')
m++;
else if (s[0] == 'A')
a++;
else if (s[0] == 'R')
r++;
else if (s[0] == 'C')
c++;
else if (s[0] == 'H')
h++;
}
long long ans = 0;
ans += m * a * r;
ans += m * a * c;
ans += m * a * h;
ans += m * r * c;
ans += m * r * h;
ans += a * r * c;
ans += a * r * h;
ans += a * c * h;
ans += 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() {
int n, ini[5] = {};
double ans = 0;
char name[11];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name);
switch (name[0]) {
case 'M':
ini[0]++;
break;
case 'A':
ini[1]++;
break;
case 'R':
ini[2]++;
break;
case 'C':
ini[3]++;
break;
case 'H':
ini[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 += ini[i] * ini[j] * ini[k];
}
}
}
printf("%lf", 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>
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
size_t rest = endbuf - pos;
if (buf + rest > pos) {
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int>
inline bool scan(Int &in) {
in = 0;
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return !(*++pos == 0 && !rebuffer());
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return !(*++pos == 0 && !rebuffer());
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T>
inline bool scan(T &in) {
return FastIn::scan(in);
}
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
inline bool eat(char ch) { return FastIn::eat(ch); }
};
} // namespace FastIn
FastIn::Scanner cin;
int main() {
size_t N;
cin.scan(N);
int S[256] = {};
for (size_t i = 0; i < N; ++i) {
char c;
cin.scan(c);
++S[c];
cin.eat('\n');
}
uint64_t res = 0;
res += S['M'] * S['A'] * S['R'];
res += S['M'] * S['A'] * S['C'];
res += S['M'] * S['A'] * S['H'];
res += S['M'] * S['R'] * S['C'];
res += S['M'] * S['R'] * S['H'];
res += S['M'] * S['C'] * S['H'];
res += S['A'] * S['R'] * S['C'];
res += S['A'] * S['R'] * S['H'];
res += S['M'] * S['C'] * S['H'];
res += S['R'] * S['C'] * S['H'];
printf("%" PRIu64 "\n", 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 | from itertools import combinations
N = int(input())
s_li = []
for _ in range(N):
s = input()
if s[0] in "MARCH":
s_li.append(s)
s_set = set(s_li)
# print(len(list(combinations(s_set, 3))))
ans = 0
for c in combinations(s_set, 3):
initial = []
for name in c:
if name[0] in initial:
break
initial.append(name[0])
else:
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())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
a = input()
if a[0] == "M":
Mnum+=1
elif a[0] == "A":
Anum+=1
elif a[0] == "R":
Rnum+=1
elif a[0] == "C":
Cnum+=1
elif a[0] == "H":
Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
blist =list(combinations(alist,3))
from functools import reduce
sum = 0
for i in range(len(blist)):
sum+=reduce(mul,blist)
print(sum) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<int> m(5);
for (int i = 0; i < n; i++) {
char f = s[i][0];
switch (f) {
case 'M':
m[0]++;
break;
case 'A':
m[1]++;
break;
case 'R':
m[2]++;
break;
case 'C':
m[3]++;
break;
case 'H':
m[4]++;
break;
}
}
vector<long long> P = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
vector<long long> Q = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
vector<long long> R = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
long long sum = 0;
for (long long i = 0; i < 10; i++) {
sum += (m[P[i]] * m[Q[i]] * m[R[i]]);
}
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S[i];
vector<int> ct(5);
for (int i = 0; i < N; i++) {
string X = S[i];
if (X[0] == 'M') ct[0]++;
}
for (int i = 0; i < N; i++) {
string X = S[i];
if (X[0] == 'A') ct[1]++;
}
for (int i = 0; i < N; i++) {
string X = S[i];
if (X[0] == 'R') ct[2]++;
}
for (int i = 0; i < N; i++) {
string X = S[i];
if (X[0] == 'C') ct[3]++;
}
for (int i = 0; i < N; i++) {
string X = S[i];
if (X[0] == 'H') ct[4]++;
}
long long int ans;
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++) ans += ct[i] * ct[j] * ct[k];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n;
char s[1000][101];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int cm = 0, ca = 0, cr = 0, cc = 0, ch = 0;
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
cm++;
}
if (s[i][0] == 'A') {
ca++;
}
if (s[i][0] == 'R') {
cr++;
}
if (s[i][0] == 'C') {
cc++;
}
if (s[i][0] == 'H') {
ch++;
}
}
int ans = 0;
ans = cm * ca * cr;
ans += cm * ca * cc;
ans += cm * ca * ch;
ans += cm * cr * cc;
ans += cm * cr * ch;
ans += cm * cc * ch;
ans += ca * cr * cc;
ans += ca * cr * ch;
ans += ca * cc * ch;
ans += cr * cc * ch;
printf("%d\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<String,Integer> namelist = new HashMap<String,Integer>();
String s = "MARCH";
for(int i = 0;i<s.length();i++){
namelist.put(String.valueOf(s.charAt(i)), 0);
}
for (int i = 0; i < n; i++) {
String name = String.valueOf(sc.next().charAt(0));
if(namelist.containsKey(name)){
namelist.put(name,namelist.get(name)+1);
}
}
long ans=0;
for(int i =0;i<s.length()-2;i++){
int a = namelist.get(String.valueOf(s.charAt(i)));
for(int j=i+1;j<s.length()-1;j++){
int b = namelist.get(String.valueOf(s.charAt(j)));
for(int k = j+1;k<s.length();k++){
int c = namelist.get(String.valueOf(s.charAt(k)));
ans += a*b*c;
}
}
}
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;
string s;
int n;
long long ans;
int top[5];
int ncr[10][3]{{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}, {0, 1, 4},
{0, 2, 4}, {1, 2, 4}, {0, 3, 4}, {1, 3, 4}, {2, 3, 4}};
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') top[0]++;
if (s[0] == 'A') top[1]++;
if (s[0] == 'R') top[2]++;
if (s[0] == 'C') top[3]++;
if (s[0] == 'H') top[4]++;
}
for (int i = 0; i < 10; i++)
ans += top[ncr[i][0]] * top[ncr[i][1]] * top[ncr[i][2]];
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;
set<string> S;
for (int i = 0; i < N; i++) {
string T;
cin >> T;
if (T.at(0) == 'M' || T.at(0) == 'A' || T.at(0) == 'R' || T.at(0) == 'C' ||
T.at(0) == 'H') {
S.insert(T);
}
}
long long A = S.size();
if (A < 3) {
cout << 0 << endl;
} else {
cout << A * (A - 1) * (A - 2) / 6 << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = []
for i in range(N):
s = input()
if s[0] in ('M','A','R','C','H'):
S.append(s)
N = len(S)
ret = []
for i in range(N**2):
tmp = []
for j in range(N):
if (i >> j) & 1:
tmp.append(S[j])
if len(tmp) == 3:
ret.append(tmp)
judge = True
cnt = 0
for r in ret:
tmp = []
for name in r:
if not name[0] in tmp:
tmp.append(name[0])
else:
judge = False
break
if judge:
cnt += 1
print(cnt) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x;
cin >> x;
string s;
map<char, int> m;
for (int i = 0; i < x; i++) {
cin >> s;
m[s[0]]++;
}
long long ans = 0;
int y[5];
y[0] = m['A'];
y[1] = m['C'];
y[2] = m['H'];
y[3] = m['M'];
y[4] = m['R'];
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++) ans += y[i] * y[j] * y[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() {
long long n, M = 0, A = 0, R = 0, C = 0, H = 0, result = 0;
int march[5];
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') M++;
if (s[0] == 'A') A++;
if (s[0] == 'R') R++;
if (s[0] == 'C') C++;
if (s[0] == 'H') H++;
}
march[0] = M;
march[1] = A;
march[2] = R;
march[3] = C;
march[4] = H;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i == j) continue;
for (int k = 0; k < 5; k++) {
if (i == j || i == k || j == k) continue;
int tmp = march[i] * march[j] * march[k];
if (tmp > result) result = tmp;
}
}
}
cout << result << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int N;
cin >> N;
int m, a, r, c, h;
m = a = r = c = h = 0;
int i;
for (i = 0; i < N; i++) {
cin >> str;
if (str[0] == 'M') {
m += 1;
}
if (str[0] == 'A') {
a += 1;
}
if (str[0] == 'R') {
r += 1;
}
if (str[0] == 'C') {
c += 1;
}
if (str[0] == 'H') {
h += 1;
}
}
cout << 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;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.