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() {
int n;
cin >> n;
int c[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < n; i++) {
string s_temp;
cin >> s_temp;
if (s_temp[0] == 'M')
c[0]++;
else if (s_temp[0] == 'A')
c[1]++;
else if (s_temp[0] == 'R')
c[2]++;
else if (s_temp[0] == 'C')
c[3]++;
else if (s_temp[0] == 'H')
c[4]++;
}
long long ans;
ans = c[0] * c[1] * c[2] + c[0] * c[1] * c[3] + c[0] * c[1] * c[4] +
c[0] * c[2] * c[3] + c[0] * c[2] * c[4] + c[0] * c[3] * c[4] +
c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[3] * c[4] +
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;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int a[5];
int main() {
for (int i = 0; i < 5; i++) a[i] = 0;
long int n;
cin >> n;
for (int i = 0; i < n; i++) {
char tmp[15];
cin >> tmp;
for (int j = 0; j < 5; j++) {
if (tmp[0] == c[j]) {
a[j]++;
}
}
}
long long out = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
out += a[i] * a[j] * a[k];
}
}
}
cout << out << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, i, j, k;
cin >> N;
string S[100000];
int march[5] = {};
for (i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M') {
march[0] = march[0] + 1;
} else if (S[i][0] == 'A') {
march[1] = march[1] + 1;
} else if (S[i][0] == 'R') {
march[2] = march[2] + 1;
} else if (S[i][0] == 'C') {
march[3] = march[3] + 1;
} else if (S[i][0] == 'H') {
march[4] = march[4] + 1;
}
}
int ans = 0;
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
for (k = j + 1; k < 5; k++) {
ans = ans + march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long n, k, a, wynik, roz;
int tab[100];
string b;
int main() {
scanf("%lld", &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++;
roz = wynik * (wynik - 1) * (wynik - 2) / 6;
if (roz < 0) roz = 0;
if ((tab[77] - 1) * (wynik - 1) > 0) roz += (tab[77] - 1) * (wynik - 1);
if ((tab[65] - 1) * (wynik - 1) > 0) roz += (tab[65] - 1) * (wynik - 1);
if ((tab[82] - 1) * (wynik - 1) > 0) roz += (tab[82] - 1) * (wynik - 1);
if ((tab[67] - 1) * (wynik - 1) > 0) roz += (tab[67] - 1) * (wynik - 1);
if ((tab[72] - 1) * (wynik - 1) > 0) roz += (tab[72] - 1) * (wynik - 1);
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 | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String[] S = new String[N];
char[] initial = new char[N];
int m = 0; int a = 0; int r = 0; int c = 0; int h = 0;
for(int i=0; i<N; i++) {
S[i] = sc.next();
initial[i] = S[i].charAt(0);
if(initial[i] == 'M') m++;
else if(initial[i] == 'A') a++;
else if(initial[i] == 'R') r++;
else if(initial[i] == 'C') c++;
else if(initial[i] == 'H') h++;
}
int ans = 0;
ans += m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h
+a*r*c+a*r*h+a*c*h+r*c*h;
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;
int main(void) {
int n;
cin >> n;
string str[100001];
vector<int> d(5);
for (int i = 0; i < 5; i++) d[i] = 0;
char march[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < n; i++) {
string x;
cin >> x;
str[i] = x;
for (int j = 0; j < 5; j++) {
if (march[j] == x[0]) d[j]++;
}
}
long long ans = 0LL;
for (int i = 0; i < 5; i++) {
if (d[i] == 0) {
d.erase(d.begin() + i);
}
}
int cnt = 0, cc = 0;
if (d.empty()) {
cout << 0 << endl;
return 0;
} else if (d.size() == 5)
cnt = 10;
else if (d.size() == 4)
cnt = 4;
else if (d.size() == 3)
cnt = 1;
for (int i = 0; i < d.size() - 2; i++) {
for (int j = 1; j < d.size() - 1; j++) {
for (int k = 2; k < d.size(); k++) {
cc++;
if (cc == cnt) {
cout << ans << endl;
return 0;
}
ans += d[i] * d[j] * d[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;
int main() {
int N;
cin >> N;
string S;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
cin >> S;
if (S.at(0) == 'M') {
m++;
}
if (S.at(0) == 'A') {
a++;
}
if (S.at(0) == 'R') {
r++;
}
if (S.at(0) == 'C') {
c++;
}
if (S.at(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 + h * a * r + r * c * h
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
vector<pair<long long int, long long int> > p;
bool pairCompare(const pair<double, long long int>& firstElof,
const pair<double, long long int>& secondElof) {
return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double, long long int>& firstElof,
const pair<double, long long int>& secondElof) {
return firstElof.second < secondElof.second;
}
bool x[100100];
long long int num[100100];
long long int fibl[100100] = {0};
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
long long int fib(long long int a) {
if (fibl[a] != 0) return fibl[a];
if (a == 0) {
return 0;
} else if (a == 1) {
return 1;
}
return fibl[a] = fib(a - 1) + fib(a - 2);
}
long long int eratosthenes(long long int n) {
int p = 0;
for (long long int i = 0; i <= n; ++i) x[i] = true;
x[0] = x[1] = false;
for (int i = 2; i <= n; ++i) {
if (x[i]) {
p++;
for (int j = 2 * i; j <= n; j += i) x[j] = false;
}
num[i] = p;
}
return p;
}
long long int gcd(long long int a, long long int b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
long long int keta(long long int N) {
int tmp{};
while (N > 0) {
tmp += (N % 10);
N /= 10;
}
N = tmp;
return N;
}
int main() {
long long int n;
cin >> n;
string s[n];
for (long long int i = 0; i < n; i++) cin >> s[i];
long long int c[5] = {0};
for (long long int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
c[0] += c[0] + 1;
} else if (s[i][0] == 'A') {
c[1] += c[1] + 1;
} else if (s[i][0] == 'R') {
c[2] += c[2] + 1;
} else if (s[i][0] == 'C') {
c[3] += c[3] + 1;
} else if (s[i][0] == 'H') {
c[4] += c[4] + 1;
}
}
long long int ans = 0;
for (long long int i = 0; i < 5; i++) {
for (long long int j = i + 1; j < 5; j++) {
for (long long int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long b, c, d, n, m, i, j;
int k = 0;
cin >> n;
int ar[n];
if (n == 5) {
cout << 2;
} else if (n == 4) {
cout << 0;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
int n = 0;
char c = 0;
char name[16];
int names[5] = {};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name);
switch (*name) {
case 'M':
names[0]++;
break;
case 'A':
names[1]++;
break;
case 'R':
names[2]++;
break;
case 'C':
names[3]++;
break;
case 'H':
names[4]++;
break;
}
}
long long sum = 0;
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
sum += names[i] * names[j] * names[k];
}
}
}
printf("%lld\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0)
return a;
else
return GCD(b, a % b);
}
bool sosuu_check(int num) {
int i;
for (i = 2; i <= sqrt(num); ++i) {
if (num % i == 0) return false;
}
return (num < 2) ? false : true;
}
int main() {
long long ans;
string s;
int N, i, m, a, r, c, h;
m = a = r = c = h = 0;
cin >> N;
for (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++;
}
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | gets
correct_chars = %w[M A R C H]
answer = 0
names = readlines.map(&:chomp).select { |s|
correct_chars.include?(s[0])
}.uniq.combination(3).each do |a, b, c|
answer += 1 if a[0] != b[0] && b[0] != c[0] && a[0] != c[0]
end
puts answer
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
struct Combination {
int a;
int b;
int c;
};
using namespace std;
vector<Combination> v_c;
void recursive_comb(vector<int>& indexes, int s, int rest, std::function<void(vector<int> &)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
return;
}
void foreach_comb(int n, int k, std::function<void(vector<int> &)> f) {
vector<int> indexes(k);
recursive_comb(indexes, n - 1, k, f);
return;
}
int main() {
int n;
cin >> n;
vector<int> v_num(5, 0);
for (int i = 0; i < n; ++i) {
string str; cin >> str;
if (str[0] == 'M') v_num[0]++;
if (str[0] == 'A') v_num[1]++;
if (str[0] == 'R') v_num[2]++;
if (str[0] == 'C') v_num[3]++;
if (str[0] == 'H') v_num[4]++;
}
v_c.reserve(10);
foreach_comb(5, 3, [](vector<int>& indexes) {
Combination c{ indexes[0], indexes[1], indexes[2] };
v_c.push_back(c);
});
long long int score = 0;
for (int i = 0; i < v_c.size(); i++) {
score += long long int (v_num[v_c[i].a] * v_num[v_c[i].b] * v_num[v_c[i].c] );
}
cout << score << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder
{
class ABC
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
string[] S = new string[N];
for(int i = 0; i < N; i++)
{
S[i] = Console.ReadLine();
}
int m = 0, a = 0, r = 0, c = 0, h = 0;
for(int i = 0; i < N; i++)
{
if (S[i][0] == 'M') m++;
else if (S[i][0] == 'A') a++;
else if (S[i][0] == 'R') r++;
else if (S[i][0] == 'C') c++;
else if (S[i][0] == 'H') h++;
}
int[] list = { m, a, r, c, h };
int[] A = { 0, 0, 0, 1, 1, 2, 1, 0, 0, 0 };
int[] B = { 1, 1, 1, 2, 2, 3, 3, 2, 2, 3 };
int[] C = { 2, 3, 4, 3, 4, 4, 4, 3, 4, 4 };
long ans = 0;
for(int i = 0; i < 10; i++)
{
ans += list[A[i]] * list[B[i]] * list[C[i]];
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<int> cnt(5);
cnt.assign(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]++;
}
ll ans = 0;
for (int i1 = 0; i1 < 3; i1++) {
for (int i2 = i1 + 1; i2 < 4; i2++) {
for (int i3 = i2 + 1; i3 < 5; i3++) {
ans += cnt[i1] * cnt[i2] * cnt[i3];
}
}
}
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 itertools
n = int(input())
names = []
initial = ['M', 'A', 'R', 'C', 'H']
ans = 0
for i in range(n):
name = input()
if name[0] in initial:
names.append(name)
combo = list(itertools.combinations(names, 3))
for i in combo:
if not i[0][0] == i[1][0] and not i[0][0] == i[2][0] and not i[1][0] == i[2][0]:
ans += 1
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
n = int(input())
sl = []
for i in range(n):
name = input()
if name[0] in ['M','A','R','C','H']:
sl.append(name)
if len(sl) < 3:
print(0)
exit()
dic = {'M':0,'A':1,'R':2,'C':3,'H':4}
cnt = 0
for com in itertools.combinations(sl,3):
lst = [0]*5
for name in com:
if lst[dic[name[0]]] == 0:
lst[dic[name[0]]] += 1
if sum(lst) == 3:
cnt += 1
print(cnt)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
{
int n, a = 0, b = 0, c = 0, d = 0, e = 0;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
switch (s[0]) {
case 'M':
a++;
break;
case 'A':
b++;
break;
case 'R':
c++;
break;
case 'C':
d++;
break;
case 'H':
e++;
break;
}
}
if (a) v.push_back(a);
if (b) v.push_back(b);
if (c) v.push_back(c);
if (d) v.push_back(d);
if (e) v.push_back(e);
}
if (v.size() < 3) {
cout << 0;
} else {
int s = 0;
for (int i = 0; i < v.size() - 2; i++)
for (int j = i + 1; j < v.size() - 1; j++)
for (int k = j + 1; k < v.size(); k++) s += v[i] * v[j] * v[k];
cout << 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 | #import collections
#aa = collections.Counter(a) # list to list
from itertools import combinations # (string,3) 3回
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
n = int(input())
S = []
for i in range(n):
s = input()
S.append(s)
na = ['M','A','R','C','H']
cnt = 0
for a,b,c in combinations(S,3):
if a[0] in na and b[0] in na and c[0] in na and a[0]!=b[0] and b[0]!=c[0] and c[0]!= a[0]:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N, cnt;
cin >> N;
char s[11];
long long int ans = 0;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
ans++;
}
cout << ans * (ans - 1) / 6;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
string S;
vector<int> count(5);
for (int i = 0; i < N; i++) {
cin >> S;
if (S.at(0) == 'M')
count.at(0)++;
else if (S.at(0) == 'A')
count.at(1)++;
else if (S.at(0) == 'R')
count.at(2)++;
else if (S.at(0) == 'C')
count.at(3)++;
else if (S.at(0) == 'H')
count.at(4)++;
}
int flag = 0;
for (int i = 0; i < 5; i++)
if (count.at(i)) flag++;
ll ans = 0;
if (flag < 3)
ans = 0;
else {
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += ll(count.at(i) * count.at(j) * count.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>
int diff[4][2] = {
{0, -1},
{-1, 0},
{1, 0},
{0, 1},
};
int Min(int a, int b) { return (a) < (b) ? (a) : (b); }
int Max(int a, int b) { return (a) > (b) ? (a) : (b); }
int main() {
int n;
scanf("%d", &n);
char s[11];
int cnt[5] = {0};
for (int i = 0, i_len = (int)(n); i < i_len; i++) {
scanf("%s", &s);
switch (s[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
}
}
long long ans = 0;
for (int i = 0, i_len = (int)(n); i < i_len; i++) {
for (int j = (int)(i + 1), j_len = (int)(n); j < j_len; j++) {
for (int k = (int)(j + 1), k_len = (int)(n); k < k_len; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
printf("%lld\n", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
int cnt[5] = {}, ans = 0;
char jd[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == jd[j]) cnt[j]++;
}
}
for (int i = 0; i < 5 - 2; i++)
for (int j = i + 1; j < 5; j++)
for (int k = j + 1; k < 5; k++) ans += cnt[i] * cnt[j] * cnt[k];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n;
cin>>n;
vector<string> s(n);
for(int i=0;i<n;i++){
cin>>s.at(i);
}
int M=0;
int A=0;
int R=0;
int C=0;
int H=0;
for(int i=0;i<n;i++){
if(s,at(i)=='M'){
M++;
}
if(s,at(i)=='A'){
A++;
}
if(s,at(i)=='R'){
R++;
}
if(s,at(i)=='C'){
C++;
}
if(s,at(i)=='H'){
H++;
}
}
int64_t count=0;
count+=M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;
cout<<count;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
int n;
string t[200000];
ll c[10];
int main(){
cin>>n;
rep(i,n){
cin>>t[i];
if(t[i][0]=='M')c[0]++;
if(t[i][0]=='A')c[1]++;
if(t[i][0]=='R')c[2]++;
if(t[i][0]=='C')c[3]++;
if(t[i][0]=='H')c[4]++;
}
ll ans=0;
for(int i=0;i<5;i++){
for(int j=i+1;j<5;j++){
for(int k=j+1;k<5;k++)ans+=(c[i]*c[j]*c[k]);
}
}
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> x(5);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
x[0]++;
else if (s[0] == 'A')
x[1]++;
else if (s[0] == 'R')
x[2]++;
else if (s[0] == 'C')
x[3]++;
else if (s[0] == 'H')
x[4]++;
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int l = j + 1; l < 5; l++) {
ans += x[i] * x[j] * x[l];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
template <typename T>
T vdebug(vector<T> v) {
for (auto vv : v) {
cout << vv << " ";
}
cout << endl;
}
template <typename T>
T adebug(T arr[], int n) {
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
void ans(bool b) {
if (b)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool b) {
if (b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int keta(ll num) {
int k = 0;
while (num > 0) {
num /= 10;
k++;
}
return k;
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
int cnt[5];
string s;
for (int i = 0; i < 5; i++) {
cnt[i] = 0;
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') cnt[0]++;
if (s[0] == 'A') cnt[1]++;
if (s[0] == 'R') cnt[2]++;
if (s[0] == 'C') cnt[3]++;
if (s[0] == 'H') cnt[4]++;
}
ll res = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
res += cnt[i] * cnt[j] * cnt[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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, M = 0, A = 0, R = 0, C = 0, H = 0, i;
long long s = 0LL, a[10];
string L;
cin >> n;
for (i = 0; i < n; i++) {
cin >> L;
switch (L[0]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
H++;
break;
default:
break;
}
}
a[0] = M * A * R;
a[1] = M * A * C;
a[2] = M * A * H;
a[3] = M * R * C;
a[4] = M * R * H;
a[5] = M * C * H;
a[6] = A * R * C;
a[7] = A * R * H;
a[8] = A * C * H;
a[9] = R * C * H;
for (i = 0; i < 10; i++) {
s += a[i];
}
cout << s << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.ArrayList;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 人数を取得
Integer n = sc.nextInt();
// 名前を取得
ArrayList<String> m = new ArrayList<String>();
ArrayList<String> a = new ArrayList<String>();
ArrayList<String> r = new ArrayList<String>();
ArrayList<String> c = new ArrayList<String>();
ArrayList<String> h = new ArrayList<String>();
for(int i = 0; i < n ; i++){
String name = sc.next();
if("M".equals(name.substring(0,1))){
m.add(name);
}else if("A".equals(name.substring(0,1))){
a.add(name);
}else if("R".equals(name.substring(0,1))){
r.add(name);
}else if("C".equals(name.substring(0,1))){
c.add(name);
}else if("H".equals(name.substring(0,1))){
h.add(name);
}
}
// それぞれの文字から始まる名前の数を集計
Integer mNum = m.size();
Integer aNum = a.size();
Integer rNum = r.size();
Integer cNum = c.size();
Integer hNum = h.size();
ArrayList<Integer> valid = new ArrayList<Integer>();
if(mNum != 0){
valid.add(mNum);
}
if(aNum != 0){
valid.add(aNum);
}
if(rNum != 0){
valid.add(rNum);
}
if(cNum != 0){
valid.add(cNum);
}
if(hNum != 0){
valid.add(hNum);
}
// 組み合わせ総数を計算(valid.size()<3の場合は組み合わせが1つも成立しないので更新なし)
double pair = 0;
if(3 == valid.size()){
double allMulti = 1;
for(int i = 0 ; i < valid.size() ; i++){
allMulti = allMulti * valid.get(i);
}
pair = allMulti;
}else if(4 == valid.size()){
double allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
double tmp = allMulti/valid.get(i);
pair = pair + tmp;
}
}else if(5 == valid.size()){
double allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
double tmp = allMulti/valid.get(i);
for(int j = 0; j < valid.size(); j++){
if(i < j ){
tmp = tmp/valid.get(j);
pair = pair + tmp;
}
}
}
}
System.out.println((long)pair);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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 int mod = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
int main() {
int n;
cin >> n;
map<char, int> m;
for (int i = 0; i < (int)(n); i++) {
string s;
cin >> s;
m[s[0]]++;
}
vector<int> su(5);
su.at(0) = m['M'];
su.at(1) = m['A'];
su.at(2) = m['R'];
su.at(3) = m['C'];
su.at(4) = m['H'];
mint ans = 0;
for (int i = 0; i < (int)(3); i++) {
mint ii = su.at(i);
for (int j = (int)(i + 1); j < (int)(4); j++) {
mint jj = su.at(j);
for (int k = (int)(j + 1); k < (int)(5); k++) {
mint kk = su.at(k);
mint add = ii * jj * kk;
ans += add;
}
}
}
cout << ans.x << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, rs;
int f[5];
string s;
int main() {
cin >> n;
memset(f, 0, sizeof(f));
while (n-- > 0) {
cin >> s;
if (s[0] == 'M')
f[0]++;
else if (s[0] == 'A')
f[1]++;
else if (s[0] == 'R')
f[2]++;
else if (s[0] == 'C')
f[3]++;
else if (s[0] == 'H')
f[4]++;
}
int ly = 0;
rs = 0;
for (int i = 0; i < 5; i++)
if (f[i] > 0) ly++;
if (ly >= 3) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (j == i) continue;
for (int t = 0; t < 5; t++) {
if (i == t || t == j) continue;
rs += f[i] * f[j] * f[t];
}
}
}
}
cout << rs << 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;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int n;
string s[101010];
void solve() {
cin >> n;
long long cnt[5] = {};
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int t = 1;
while (t--) {
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;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
ll N, M, K, H, W, L, R, X;
string S, T;
int main() {
string march = "MARCH";
cin >> N;
map<char, int> mp;
for (long long i = 0; i < (int)N; i++) {
string s;
cin >> s;
for (long long j = 0; j < (int)5; j++) {
if (s[0] == march[j]) {
mp[s[0]]++;
break;
}
}
}
ll ans = 0;
ll temp = 1;
for (auto itr : mp) temp *= itr.second;
int cnt = mp.size();
if (cnt <= 2) {
cout << 0 << endl;
return 0;
} else if (cnt == 3) {
cout << temp << endl;
return 0;
} else if (cnt == 4) {
for (auto itr : mp) ans += temp / itr.second;
cout << ans << endl;
return 0;
} else if (cnt == 5) {
for (auto itr : mp) {
for (auto itr2 : mp) {
if (itr2 <= itr) continue;
ans += temp / (itr.second * itr2.second);
}
}
cout << ans << endl;
return 0;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
S = input()
if S[0] in 'MARCH':
if S[0] not in names:
names[S[0]] = 1
else:
names[S[0]] += 1
comb = len(names)
if comb <= 2:
print(0)
elif comb == 3:
ret = 1
for v in names.values():
ret *= v
print(ret)
elif comb == 4:
tmp = 1
for v in names.values():
tmp *= v
ret = 0
for v in names.values():
ret += tmp // v
print(ret)
else:
ret = 0
for comb in combinations('MARCH', 3):
tmp = 1
for c in comb:
tmp *= c
ret += comb
print(ret) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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_temp;
int c[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < n; i++) {
cin >> s_temp;
if (s_temp[0] == 'M')
c[0]++;
else if (s_temp[0] == 'A')
c[1]++;
else if (s_temp[0] == 'R')
c[2]++;
else if (s_temp[0] == 'C')
c[3]++;
else if (s_temp[0] == 'H')
c[4]++;
}
long ans;
ans = c[0] * c[1] * c[2] + c[0] * c[1] * c[3] + c[0] * c[1] * c[4] +
c[0] * c[2] * c[3] + c[0] * c[2] * c[4] + c[0] * c[3] * c[4] +
c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[3] * c[4] +
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 | java | import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[5];
for (int i = 0; i < n; i++) {
String s = sc.next();
if (s.charAt(0) == 'M') {
a[0]++;
} else if (s.charAt(0) == 'A') {
a[1]++;
} else if (s.charAt(0) == 'R') {
a[2]++;
} else if (s.charAt(0) == 'C') {
a[3]++;
} else if (s.charAt(0) == 'H') {
a[4]++;
}
}
System.out.println(a[0]*a[1]*a[2] + a[0]*a[1]*a[3] + a[0]*a[1]*a[4] + a[0]*a[2]*a[3] + a[0]*a[2]*a[4] +
a[0]*a[3]*a[4] + a[1]*a[2]*a[3] + a[1]*a[2]*a[4] + a[1]*a[3]*a[4] + a[2]*a[3]*a[4]);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
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++;
}
}
long 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;
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>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int INF = 2147483647;
const long long int MINF = -2147483648;
const long long int LINF = 9223372036854775807;
const long long int MOD = 1000000007;
const double PI = acos(-1);
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<long long int>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec) is >> x;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : "");
}
return os;
}
template <typename T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
long long int solve() {
long long int a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
string s = "", t = "";
vector<pair<long long int, long long int>> pr;
map<long long int, long long int> make_pair;
set<long long int> st;
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
vs d;
map<char, long long int> e;
for (long long int i = 0; i < (n); i++) {
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
e[s[0]]++;
count++;
}
}
b = e.size();
for (auto x : e) {
ans += (count - x.second) * (x.second - 1);
}
w = (count * (count - 1) * (count - 2) / 6) - ans;
if (b >= 3) {
return w;
} else {
return 0;
}
}
signed main() { cout << solve() << '\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 | python3 | n = int(input())
list_N = [input() for _ in range(n)]
list_N = list(set(list_N))
cnt = [0 for _ in range(5)]
for i in range(len(list_N)):
l = list(list_N[i])
if l[0] in "M":
cnt[0] += 1
elif l[0] in "A":
cnt[1] += 1
elif l[0] in "R":
cnt[2] += 1
elif l[0] in "C":
cnt[3] += 1
elif l[0] in "H":
cnt[4] += 1
ans = 0
l = []
if cnt.count(0) == 2:
for num in cnt:
if num != 0:
l.append(num)
ans += l[0]*l[1]*l[2]
if cnt.count(0) == 1:
for num in cnt:
if num != 0:
l.append(num)
ans += l[0] * l[1] * l[2]
ans += l[0] * l[1] * l[3]
ans += l[0] * l[2] * l[3]
ans += l[2] * l[1] * l[3]
if cnt.count(0) == 0:
ans += l[0] * l[1] * l[2]
ans += l[0] * l[1] * l[3]
ans += l[0] * l[1] * l[4]
ans += l[0] * l[2] * l[3]
ans += l[0] * l[2] * l[4]
ans += l[0] * l[3] * l[4]
ans += l[1] * l[2] * l[3]
ans += l[1] * l[2] * l[4]
ans += l[1] * l[3] * l[4]
ans += l[2] * l[3] * l[4]
if cnt.count(0) > 2:
print(0)
else:
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<cstdio>
using namespace std;
int main(){
int n, m[5] = {0,0,0,0,0};
long long ans;
string s;
for(int i = 0; i < n; i++){
scanf("%s",s);
if(s[0] == 'M') m[0]++;
else if(s[0] == 'A') m[1]++;
else if(s[0] == 'R') m[2]++;
else if(s[0] == 'C') m[3]++;
else if(s[0] == 'H') m[4]++;
}
for(int j = 0; j < 3; j++)
for(int k = j+1; k < 4; k++)
for(int l = l+1; l < 5; l++)
ans += m[j]*m[k]*m[l];
printf("%d\n",ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c[5];
for (int i = 0; i < 5; ++i) {
c[i] = 0;
}
for (int i = 0; i < n; ++i) {
string tmp;
cin >> tmp;
if (tmp[0] == 'M') {
c[0]++;
} else if (tmp[0] == 'A') {
c[1]++;
} else if (tmp[0] == 'R') {
c[2]++;
} else if (tmp[0] == 'C') {
c[3]++;
} else if (tmp[0] == 'H') {
c[4]++;
}
}
unsigned long long result = 0;
for (int xi = 0; xi < 5; ++xi) {
for (int yi = 0; yi < xi; ++yi) {
for (int zi = 0; zi < yi; ++zi) {
result += c[xi] * c[yi] * c[zi];
}
}
}
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;
long long ans;
int N;
long long c[5];
int main(void) {
scanf("%d", &N);
for (int i = (0); i < (N); i++) {
char S[15];
scanf("%s", S);
if (S[0] == 'M')
c[0]++;
else if (S[0] == 'A')
c[1]++;
else if (S[0] == 'R')
c[2]++;
else if (S[0] == 'C')
c[3]++;
else if (S[0] == 'H')
c[4]++;
}
for (int i = (0); i < (5); i++) {
for (int j = (i + 1); j < (5); j++) {
for (int k = (j + 1); k < (5); k++) {
ans += c[i] * c[j] * c[k];
}
}
}
printf("%d\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<pair<char, int> > p(5);
p[0] = make_pair('M', 0);
p[1] = make_pair('A', 0);
p[2] = make_pair('R', 0);
p[3] = make_pair('C', 0);
p[4] = make_pair('H', 0);
int use = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
if (s[i].at(0) == p[j].first) {
if (p[j].second == 0) use++;
p[j].second++;
}
}
}
int ans = 0;
if (use >= 3) {
for (int i = 0; i < 5; i++) {
if (p[i].second > 1 && use == 4)
ans += (p[i].second - 1) * 3;
else if (p[i].second > 1 && use == 3)
ans += p[i].second - 1;
else if (p[i].second > 1 && use == 5)
ans += (p[i].second - 1) * 4;
}
if (use == 3) ans += 1;
if (use == 4) ans += 4;
if (use == 5) ans += 10;
} else {
cout << 0 << endl;
return 0;
}
std::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;
using lint = long long;
int main() {
int N;
cin >> N;
int count[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M')
count[0]++;
else if (S[0] == 'A')
count[1]++;
else if (S[0] == 'R')
count[2]++;
else if (S[0] == 'C')
count[3]++;
else if (S[0] == 'H')
count[4]++;
}
lint ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) ans += count[i] * count[j] * count[k];
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
char a[100000][10];
int b;
long int 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 | java | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
Map<Character, Long> map = new HashMap<>();
long count = 0;
for (int i = 0; i < N; i++) {
Character S = in.next().charAt(0);
if (S == 'M' || S == 'A' || S == 'R' || S == 'C' || S == 'H') {
if (map.containsKey(S)) {
map.put(S, map.get(S) + 1);
} else {
map.put(S, 1l);
}
count++;
}
}
long ans = 0;
if (count >= 3) {
ans = count * (count - 1) * (count - 2) / 6;
for (Map.Entry<Character, Long> s : map.entrySet()) {
if (ans > 0 && s.getValue() >= 2) {
long sNum = s.getValue() * (s.getValue() - 1) / 2;
ans -= sNum * ((count - s.getValue()) > 0 ? count - s.getValue() : 1);
}
}
}
System.out.println(ans);
in.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 | 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 = 4
n_1 = 6
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;
using ll = long long;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<int> cnt(5);
cnt.assign(5, 0);
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
ll ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int s = 0, n, i, a = 0, b = 0, c = 0, d = 0, e = 0;
char arr, tmp[100];
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
scanf("%c", &arr);
scanf("%s", tmp);
getchar();
if (arr == 'M') e++;
if (arr == 'A') a++;
if (arr == 'R') b++;
if (arr == 'C') c++;
if (arr == 'H') d++;
}
s += a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e +
b * c * d + b * c * e + b * d * e + c * d * e;
printf("%d", 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 | def factorial(n):
res = 1
for i in range(1, n + 1):
res *= i
return res
def combination(n, r):
return factorial(n) // (factorial(r) * factorial(n - r))
n = int(input())
s = [input()[0] for _ in range(n)]
march = [0] * 5
for c in s:
if c in 'MARCH':
march['MARCH'.index(c)] += 1
k = sum(x > 0 for x in march)
if k < 3:
print(0)
exit()
ans = combination(k, 3)
for x in march:
ans += combination(k - 1, 2) * max(x - 1, 0)
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
long long m = 0, a = 0, r = 0, c = 0, h = 0;
long long num[5];
int A[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2},
B[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3},
C[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (long long 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;
}
num[0] = m, num[1] = a, num[2] = r, num[3] = c, num[4] = h;
int ans = 0;
for (long long i = 0; i < 10; ++i) ans += num[A[i]] * num[B[i]] * num[C[i]];
cout << ans << endl;
cin >> 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() {
ios_base::sync_with_stdio(false);
int n;
string name;
int march[5] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> name;
if (name[0] == 'M') march[0]++;
if (name[0] == 'A') march[1]++;
if (name[0] == 'R') march[2]++;
if (name[0] == 'C') march[3]++;
if (name[0] == 'H') march[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++) {
if (march[i] && march[j] && march[k])
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int64_t kaizyou(int64_t a) {
if (a == 1) {
return 1;
}
if (a == 0) {
return 1;
}
return a * kaizyou(a - 1);
}
int64_t comb(int64_t n, int64_t r) {
return kaizyou(n) / (kaizyou(r) * kaizyou(n - r));
}
int main() {
int N;
cin >> N;
map<char, int> m;
string name = "MARCH";
set<char> sc;
for (int i = 0; i < name.size(); i++) {
sc.insert(name.at(i));
}
int64_t ans = 0;
int64_t count = 0;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (sc.count(S.at(0))) {
if (m.count(S.at(0))) {
m.at(S.at(0))++;
} else {
m[S.at(0)] = 1;
}
count++;
}
}
if (count >= 3) {
ans = comb(count, 3);
for (auto p : m) {
if (p.second >= 3) {
ans -= comb(p.second, 3);
}
if (p.second >= 2) {
ans -= comb(p.second, 2) * (count - p.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;
int main() {
int N;
cin >> N;
string str("MRACH");
vector<string> name(N);
int countM = 0;
int countR = 0;
int countA = 0;
int countC = 0;
int countH = 0;
int all;
for (int i = 0; i < N; i++) {
cin >> name.at(i);
char I = name.at(i).at(0);
if (I == 'M') {
countM++;
} else if (I == 'R') {
countR++;
} else if (I == 'A') {
countA++;
} else if (I == 'C') {
countC++;
} else if (I == 'H') {
countH++;
}
if (countM == 0) {
countM++;
} else if (countR == 0) {
countR++;
} else if (countA == 0) {
countA++;
} else if (countC == 0) {
countC++;
} else if (countH == 0) {
countH++;
}
return countM, countR, countA, countC, countH;
}
if (countM + countR + countA + countC + countH <= 7) {
all = 0;
} else {
all = countM * countR * countA * countC * countH;
}
cout << all << 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 | import Control.Monad
import Data.List
main = do
n <- readLn::IO Int
xs <- replicateM n getLine
let matchEachLen xs = (map (\x -> length x) . group . sort . conditionMap) xs
notSingle xs = (product . filter ( /= 1) . matchEachLen) xs
single xs = (sum . filter ( == 1) . matchEachLen) xs
ans xs = if (product . matchEachLen ) xs == 1
then (comb (single xs) 3)
else comb (length $ matchEachLen xs) 3 * (notSingle xs) - (comb (single xs) 3) * ((notSingle xs) -1)
print $ ans xs
conditionMap::[String] -> [Char]
conditionMap xs = map (!!0) $ filter(\x -> any (== x!!0) cond) xs
where cond = ['M','A','R','C','H']
comb ::Int -> Int -> Int
comb n k = (product[1..n]) `div` ((product[1..(n-k)]) * (product[1..k]))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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<pair<char, int> > p(5);
p[0] = make_pair('M', 0);
p[1] = make_pair('A', 0);
p[2] = make_pair('R', 0);
p[3] = make_pair('C', 0);
p[4] = make_pair('H', 0);
int use = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
if (s[i].at(0) == p[j].first) {
if (p[j].second == 0) use++;
p[j].second++;
}
}
}
long int ans = 0;
if (use >= 3) {
for (int i = 0; i < 5; i++) {
if (p[i].second > 1 && use == 4)
ans += (p[i].second - 1) * 3;
else if (p[i].second > 1 && use == 3)
ans += p[i].second - 1;
else if (p[i].second > 1 && use == 5)
ans += (p[i].second - 1) * 4;
}
if (use == 3) ans += 1;
if (use == 4) ans += 4;
if (use == 5) ans += 10;
} else {
cout << 0 << endl;
return 0;
}
std::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 | java | public class Main {
private static java.util.Scanner scanner = new java.util.Scanner(System.in);
public static void main(String[] args) {
int n = scanner.nextInt();
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
switch (scanner.next().charAt(0)) {
case 'M': m++; continue;
case 'A': a++; continue;
case 'R': r++; continue;
case 'C': c++; continue;
case 'H': h++;
}
}
System.out.println(m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
S=[input() for _ in range(N)]
cnt=[]
ans=0
for i in range(N):
if S[i][0]=='M':
cnt.append('M')
elif S[i][0]=='A':
cnt.append('A')
elif S[i][0]=='R':
cnt.append('R')
elif S[i][0]=='C':
cnt.append('C')
elif S[i][0]=='H':
cnt.append('H')
import math
import itertools
c_list = list(itertools.combinations(cnt, 3))
for v in itertools.combinations(cnt, 3):
print(set(v))
if len(set(v))==3:
ans+=1
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0, a = 0, r = 0, c = 0, h = 0;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i].at(0) == 'M')
m++;
else if (s[i].at(0) == 'A')
a++;
else if (s[i].at(0) == 'R')
r++;
else if (s[i].at(0) == 'C')
c++;
else if (s[i].at(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 + a * c * h + r * c * h;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
d = dict()
for i in range(n):
s = list(input())
if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
if s[0] not in d:
d[s[0]] = 1
else:
d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
count += d[0] * d[1] * d[2]
elif len(d) == 4:
count += d[0] * d[1] * d[2]
count += d[3] * d[1] * d[2]
count += d[0] * d[1] * d[3]
count += d[0] * d[3] * d[2]
elif len(d) == 5:
count += d[0] * d[1] * d[2]
count += d[3] * d[1] * d[2]
count += d[0] * d[1] * d[3]
count += d[0] * d[3] * d[2]
# count += d[0] * d[1] * d[2]
count += d[4] * d[1] * d[2]
count += d[0] * d[1] * d[4]
count += d[0] * d[4] * d[2]
count += d[4] * d[1] * d[2]
# count += d[3] * d[1] * d[2]
count += d[4] * d[1] * d[3]
count += d[4] * d[3] * d[2]
print(count) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
int n;
char name[10001][11];
long long int ans = 0;
int m, a, r, c, h;
m = a = r = c = h = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name[i]);
switch (name[i][0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
ans += m * a * r;
ans += m * a * c;
ans += m * a * h;
ans += m * r * c;
ans += m * r * h;
ans += m * c * h;
ans += a * r * c;
ans += a * r * h;
ans += a * c * h;
ans += r * c * h;
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
int N;
cin >> N;
map<char, int> mp;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
string m = "MARCH";
for (int _ = 0, __len = (N); _ < __len; ++_) {
string s;
cin >> s;
if (count((m).begin(), (m).end(), s[0]) == 1) {
mp[s[0]]++;
}
}
long long ans = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
for (auto it2 = next(it, 1); it2 != mp.end(); it2++) {
for (auto it3 = next(it2, 1); it3 != mp.end(); it3++) {
ans += it->second * it2->second * it3->second;
}
}
}
cout << ans << "\n";
}
int main() {
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
template <typename T>
bool next_combination(const T first, const T last, int k) {
const T subset = first + k;
if (first == last || first == subset || last == subset) {
return false;
}
T src = subset;
while (first != src) {
src--;
if (*src < *(last - 1)) {
T dest = subset;
while (*src >= *dest) {
dest++;
}
iter_swap(src, dest);
rotate(src + 1, dest + 1, last);
rotate(subset, subset + (last - dest) - 1, last);
return true;
}
}
rotate(first, subset, last);
return false;
}
int main() {
int n;
cin >> n;
vector<ll> v(n, 0);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
v[0]++;
} else if (s[0] == 'A') {
v[1]++;
} else if (s[0] == 'R') {
v[2]++;
} else if (s[0] == 'C') {
v[3]++;
} else if (s[0] == 'H') {
v[4]++;
}
}
vector<int> c(5);
iota((c).begin(), (c).end(), 0);
ll t = 0;
do {
t += v[c[0]] * v[c[1]] * v[c[2]];
} while (next_combination((c).begin(), (c).end(), 3));
cout << t << 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>
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
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 += m * c * 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long sum = 0;
cin >> N;
vector<string> S(N);
vector<int> t(5);
for (int i = 0; i < N; i++) {
cin >> S.at(i);
}
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M') {
t.at(0)++;
} else if (S.at(i).at(0) == 'A') {
t.at(1)++;
} else if (S.at(i).at(0) == 'R') {
t.at(2)++;
} else if (S.at(i).at(0) == 'C') {
t.at(3)++;
} else if (S.at(i).at(0) == 'H') {
t.at(4)++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
if (i != j && j != k && k != i) {
sum += t.at(i) * t.at(j) * t.at(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;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
map<char, int> m;
vector<char> c = {'M', 'A', 'R', 'C', 'H'};
ll ans = 0;
for (int i = 0; i < (int)(n); i++) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
m[s[0]]++;
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += m[c[i]] * m[c[j]] * m[c[k]];
}
}
}
cout << ans << 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 = sc.nextInt();
int[] count = new int[5];
for (int i = 0; i < n; i++) {
String str = String.valueOf(sc.next().charAt(0));
if (str.equals("M")) {
count[0]++;
} else if (str.equals("A")) {
count[1]++;
} else if (str.equals("R")) {
count[2]++;
} else if (str.equals("C")) {
count[3]++;
} else if (str.equals("H")) {
count[4]++;
}
}
long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i+1; j < 4; j++) {
for (int k = j+1; k < 5; k++) {
ans += count[i] * count[j] * count[k];
}
}
}
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
l = ['M','A','R','C','H']
m = []
a = []
r = []
c = []
h = []
for i in range(n):
s = input()
if not s[0] in l: continue
if s[0] == 'M':
m.append(s)
elif s[0] == 'A':
a.append(s)
elif s[0] == 'R':
r.append(s)
elif s[0] == 'C':
c.append(s)
else:
h.append(s)
n = sum([len(i) for i in [m,a,r,c,h]])
all = n * (n - 1) * (n - 2) // 6
for t in [m,a,r,c,h]:
i = len(t)
if i >= 2:
k = i * (i -1) // 2
all -= k*(n-2)
elif i >= 3:
k = i * (i - 1) * (i - 2) // 6
all -= 1
print(all)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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().strip())
s = [input().strip() for _ in range(n)]
num = [0 for _ in range(5)]
num[0] = len([True for _s in s if _s[0] == "M"])
num[1] = len([True for _s in s if _s[0] == "A"])
num[2] = len([True for _s in s if _s[0] == "R"])
num[3] = len([True for _s in s if _s[0] == "C"])
num[4] = len([True for _s in s if _s[0] == "H"])
ans = 0
for i in range(5):
for j in range(i, 5):
for k in range(j, 5):
ans += num[i] * num[j] * num[k]
print(ans |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int Getnum(int n) {
int i, s = 0;
for (i = 0; i < 5; i++) {
if ((n >> i) & 0x01 == 1) s++;
}
return s;
}
int main() {
int t, i, tmp, check = 0, n, a[(1 << 5) + 1] = {0}, sum = 0;
char sz[100];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", sz);
switch (sz[0]) {
case 'M':
check |= 1 << 4;
a[1 << 4]++;
break;
case 'A':
check |= 1 << 3;
a[1 << 3]++;
break;
case 'R':
check |= 1 << 2;
a[1 << 2]++;
break;
case 'C':
check |= 1 << 1;
a[1 << 1]++;
break;
case 'H':
check |= 1 << 0;
a[1 << 0]++;
break;
}
}
for (i = 0; i < (1 << 5); i++) {
if (Getnum(i) != 3 || (check & i) != i) continue;
tmp = i;
t = 1;
while (tmp) {
t *= a[tmp & -tmp];
tmp -= tmp & -tmp;
}
sum += t;
}
printf("%d", 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;
typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
//* 便利な変数
namespace {
int dx4[] = { 1, -1, 0, 0 };
int dy4[] = { 0, 0, 1, -1 };
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };
int mDays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
const ll MOD_CONST = (ll)(1e9 + 7);
}
template <typename T>
vector<T> INP(ll n)
{
vector<T> x;
REP(i, n) {
T tmp; cin >> tmp;
x.push_back(tmp);
}
return move(x);
}
//* n文字1行の文字列を入力,一文字ごとの配列を返す
vector<char> SPRIT_STRING(ll n)
{
string str; cin >> str;
vector<char> cs(n);
REP(i, n) cs[i] = str[i];
return move(cs);
}
//* 文字列中から文字列を検索して別の文字列に置換する
void strReplace(std::string& str, const std::string& from, const std::string& to) {
std::string::size_type pos = 0;
while (pos = str.find(from, pos), pos != std::string::npos) {
str.replace(pos, from.length(), to);
pos += to.length();
}
}
//* 素数関連関数
namespace PrimeLib {
//* 素数判定 is_prime<unsigned>(N)
template<typename T, std::enable_if_t<std::is_unsigned<T>::value, std::nullptr_t> = nullptr>
bool is_prime(const T n) {
if (n < 4) return n == 2 || n == 3;
if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
for (T i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
//* 素数テーブル生成 エラトステネスの篩
vector<ll> primeTable(ll n) {
vector<bool> table(n - 1);
vector<ll> ret;
for (ll i = 0; i < n - 1; ++i) {
if (table[i] == false) {
ll num = i + 2;
ret.push_back(i + 2);
for (int j = i + num; j < n - 1; j += num)
table[j] = true;
}
}
return ret;
}
}
//* 組み合わせ計算
inline unsigned long long NChooseK(const unsigned long long& n, const unsigned long long& k)
{
if (n < k) return 0;
if (0 == n) return 0;
if (0 == k) return 1;
if (n == k) return 1;
if (1 == k) return n;
typedef unsigned long long value_type;
value_type* table = new value_type[static_cast<std::size_t>(n * n)];
std::fill_n(table, n * n, 0);
class n_choose_k_impl
{
public:
n_choose_k_impl(value_type* table, const value_type& dimension)
: table_(table),
dimension_(dimension)
{}
inline value_type& lookup(const value_type& n, const value_type& k)
{
return table_[dimension_ * n + k];
}
inline value_type compute(const value_type& n, const value_type& k)
{
if ((0 == k) || (k == n))
return 1;
value_type v1 = lookup(n - 1, k - 1);
if (0 == v1)
v1 = lookup(n - 1, k - 1) = compute(n - 1, k - 1);
value_type v2 = lookup(n - 1, k);
if (0 == v2)
v2 = lookup(n - 1, k) = compute(n - 1, k);
return v1 + v2;
}
value_type* table_;
value_type dimension_;
};
value_type result = n_choose_k_impl(table, n).compute(n, k);
delete[] table;
return result;
}
//* 座標nx, nyがWidth,Heightの領域内にあるかどうかのチェック
inline bool rangeCheck2D(int nx, int ny, int Width, int Height)
{
return nx >= 0 and nx < Width and ny >= 0 and ny < Height;
}
//* bit全探索
/*
for (int i = 0; i < 1<<N; i++) {
REP(j, N)
if ((1 & i >> j) == 1) {;}
}
*/
//* 値の二分探索
/*
int lb = -1, ub = n;
while (ub - lb > 1) {
int mid = (lb + ub) / 2;
if ( ) { // midが条件を満たす
ub = mid; // 解の存在範囲は[lb, mid]
} else {
lb = mid; // 解の存在範囲は[mid, ub]
}
}
int ans = ub;
*/
//* グラフのbfs 次のように格納
/*
struct edge { int to, cost; };
#define MAX_V 100
vector<edge> graph[MAX_V];
*/
//* 最短路
//* ベルマンフォード法 負の経路があっても動作
//* もし負の閉路があればfalseを返す
/*
*/
//* ワーシャル-フロイド法 全点対最短路 DPが基本 負の辺があってもOK(あると)
/*
const int MAX_V = 101;
const int inf = 100000000; // 問題に応じて設定
ll cost[MAX_V][MAX_V];
void warshallInit()
{
REP(i, N) {
REP(j, N) {
if (i == j) cost[i][j] = 0;
else cost[i][j] = inf;
}
}
}
void warshallFloyd()
{
REP(k, N) {
REP(i, N) {
REP(j, N) {
ll newCost = cost[i][k] + cost[k][j];
if (cost[i][j] > newCost) {
cost[i][j] = newCost;
}
}
}
}
}
int main()
{
warshallInit();
// input
warshallFloyd();
return 0;
}
*/
namespace abc080d {
void abc080d()
{
cin >> N >> C;
typedef tuple<int, int, int> Show; // channel, start, end
vector<Show> shows(N);
REP(i, N) {
int s, t, c;
shows[i] = make_tuple(c, s, t);
}
sort(shows.begin(), shows.end());
}
}
namespace agc015b {
void agc015b()
{
string str; cin >> str;
ll cnt = 0;
REP(i, str.size()) {
if (str[i] == 'U') {
cnt += 2 * i;
cnt += (str.size() - (i + 1));
}
else {
cnt += i;
cnt += 2 * (str.size() - (i + 1));
}
}
cout << cnt << endl;
}
}
namespace abc088d {
void abc088d() {
string str; cin >> str;
int ans = INT32_MAX;
REP(i, str.size()) {
if (i == str.size() - 1) continue;
if (str[i] == str[i + 1]) continue;
int n = i + 1;
ans = min(max(n, (int)str.size() - n), ans);
}
if (ans == INT32_MAX) {
cout << str.size() << endl;
}
else
cout << ans << endl;
}
}
namespace abc089d {
static char dp[2000][2000];
bool isBlack(int dx, int dy, char c)
{
return c == dp[dx / K][dy / K];
}
void abc089d()
{
cin >> N >> K;
REP(i, 2 * K) {
REP(j, 2 * K) {
bool bx = (i / K) % 2 == 0;
bool by = (j / K) % 2 == 0;
if (bx and by)
dp[i][j] = 'W';
else if (bx or by)
dp[i][j] = 'B';
else
dp[i][j] = 'W';
}
}
vector<pair<pair<int, int>, char>> xyc(N);
REP(i, N) {
cin >> xyc[i].first.first >> xyc[i].first.second >> xyc[i].second;
}
int ans = 0;
REP(px, 2 *K) {
REP(py, 2*K) {
int cnt = 0;
REP(i, N) {
auto t = xyc[i];
if (isBlack(px + t.first.first, py + t.first.second, t.second))
cnt++;
}
ans = max(ans, cnt);
}
}
cout << ans << endl;
}
}
/*
namespace arc063b {
void arc063b()
{
scanf("%d %d %d", &N, &K, &L);
static vector<int> pqs[200005];
int p, q, r, s;
// リンクをソートしてDFS
REP(i, K) {
scanf("%d %d", &p, &q); p--; q--;
pqs[q].push_back(p);
pqs[p].push_back(q);
}
static vector<int> link[200005];
int link_num = 0;
REP(i, L) {
scanf("%d %d", &r, &s); r--; s--;
link[r].push_back(s);
link[s].push_back(r);
}
static bool visited[200005];
static int linked1[200005], linked2[200005];
queue<int> rest;
REP(i, N) {
if (visited[i]) continue;
linked1[i] = i + 1;
rest.push(i);
while (not rest.empty()) {
int current = rest.front(); rest.pop();
for (int next : pqs[current]) {
if (visited[next]) continue;
rest.push(next);
linked1[next] = i + 1;
}
visited[current] = true;
}
}
memset(&visited[0], 0, sizeof(visited));
REP(i, N) {
if (visited[i]) continue;
linked2[i] = i + 1;
rest.push(i);
while (not rest.empty()) {
int current = rest.front(); rest.pop();
for (int next : link[current]) {
if (visited[next]) continue;
rest.push(next);
linked2[next] = i + 1;
}
visited[current] = true;
}
}
map<pair<int, int>, int> cnt;
memset(&visited[0], 0, sizeof(visited));
REP(i, N) REP(j, N)
if (not visited[i] and not visited[j] and linked1[i] == linked1[j] and linked2[i] == linked2[j]) {
visited[i] = true;
visited[j] = true;
cnt[make_pair(linked1[i], linked2[i])]++;
}
REP(i, N) {
cout << cnt[make_pair(linked1[i], linked2[i])];
if (i != N - 1) cout << " ";
else cout << endl;
}
}
}*/
namespace abc075d {
void abc075d()
{
cin >> N >> K;
vector<pair<int, int>> pos(N);
REP(i, N) cin >> pos[i].first >> pos[i].second;
ll ans = INT64_MAX;
REP(i, N) {
REP(j, N) {
pair<int, int> p1 = pos[i], p2 = pos[j];
int cnt = 0;
REP(k, N) {
int x = pos[k].first, y = pos[k].second;
if (k == i or k == j)
cnt++;
else {
bool ox = false, oy = false;
if (p1.first <= p2.first) {
if (p1.first <= x and
x <= p2.first)
ox = true;
}
else {
if (p2.first <= x and
x <= p1.first)
ox = true;
}
if (p1.second <= p2.second) {
if (p1.second <= y and
y <= p2.second)
oy = true;
}
else {
if (p2.second <= y and
y <= p1.second)
oy = true;
}
if (ox and oy) cnt++;
}
}
if (cnt >= K)
ans = min(ans, (ll)(abs(p1.first - p2.first) * abs(p1.second - p2.second)));
}
}
cout << ans << endl;
}
}
namespace abc088c {
struct edge {
int from, to, cost;
};
bool bellmanFord(vector<edge>& es, vector<ll>& ds, int start) {
for (auto& d : ds) d = INT64_MAX;
ds[start] = 0;
for (int n = 0; n < ds.size(); ++n) {
for (int i = 0; i < es.size(); ++i) {
edge e = es[i];
if (ds[e.from] != INT64_MAX and
ds[e.to] > ds[e.from] + e.cost) {
ds[e.to] = ds[e.from] + e.cost;
if (n == ds.size() - 1)
return false;
}
}
}
return true;
}
void abc088c()
{
cin >> H >> W;
vector<string> field(H);
vector<edge> es;
REP(i, H) cin >> field[i];
REP(i, H) {
REP(j, W) {
if (j + 1 < W and
field[i][j] == '.' and
field[i][j + 1] == '.') {
int p1 = i * W + j, p2 = p1 + 1;
es.push_back(edge{ p1, p2, 1 });
es.push_back(edge{ p2, p1, 1 });
}
if (i + 1 < H and
field[i][j] == '.' and
field[i + 1][j] == '.') {
int p1 = i * W + j, p2 = p1 + W;
es.push_back(edge{ p1, p2, 1 });
es.push_back(edge{ p2, p1, 1 });
}
}
}
vector<ll> ds(H*W);
bellmanFord(es, ds, 0);
int cnt = 0;
REP(i, H) {
REP(j, W) {
if (field[i][j] == '.') cnt++;
}
}
if (ds[ds.size() - 1] == INT64_MAX)
cout << "-1" << endl;
else
cout << cnt - 1 - ds[ds.size() - 1] << endl;
}
}
// dpのテーブルが愚直には確保できない
namespace abc089c {
/*pair<int, int> idxtoxy(int idx) {
return make_pair(idx / W, idx % W);
}
static ll dp[300][300];
static int idx[100000];
ll dfs(int l, int r) {
if (l == r) return 0;
int next = l + D;
if (next > 300) return 0;
if (dp[l][next] != -1) return dp[l][next];
else {
auto before = idxtoxy(idx[l]);
auto after = idxtoxy(idx[next]);
ll ans = abs(before.first - after.first) + abs(before.second - after.second);
dp[l][next] = ans;
ll rest = 0;
if (next != r) rest = dfs(next, r);
dp[l][r] = ans + rest;
return ans + rest;
}
}
void abc089c() {
REP(i, 305) {
REP(j, 305) {
dp[i][j] = -1;
}
}
cin >> H >> W >> D;
vector<int> as(H*W);
REP(i, H) {
REP(j, W) {
int a; cin >> a;
as[W*i + j] = a;
idx[a] = W*i + j;
}
}
cin >> Q;
REP(i, Q) {
int l, r; cin >> l >> r;
cout << dfs(l, r) << endl;
}
}*/
void abc089c() {
cin >> N;
vector<int> cnt(5);
int p1[] = { 0, 0, 0, 0, 0, 0, 1, 1, 2, 3};
int p2[] = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 4};
int p3[] = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 1};
REP(i, N) {
string str; 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;
}
}
ll ans = 0;
REP(i, 10) {
ans += cnt[p1[i]] * cnt[p2[i]] * cnt[p3[i]];
}
cout << ans << endl;
}
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
//arc084b::arc084b();
abc089c::abc089c();
//agc007a::agc007a();
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
vector<int> sum(5);
long long ans = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
switch (S[i][0]) {
case 'M':
sum[0]++;
break;
case 'A':
sum[1]++;
break;
case 'R':
sum[2]++;
break;
case 'C':
sum[3]++;
break;
case 'H':
sum[4]++;
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 += sum[i] * sum[j] * sum[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;
cin >> n;
string s[n];
int cou[5];
char check[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) {
cou[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 5; j++) {
if (s[i][0] == check[j]) {
cou[j]++;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int m = 0; m < 5; m++) {
if (j == m || i == m || i == j) {
break;
}
ans += cou[i] * cou[j] * cou[m];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
map<char, int> S;
int main() {
int n;
cin >> n;
int a[5];
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
a[0]++;
else if (s[0] == 'A')
a[1]++;
else if (s[0] == 'R')
a[2]++;
else if (s[0] == 'C')
a[3]++;
else if (s[0] == 'H')
a[4]++;
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int n, i, M = 0, A = 0, R = 0, C = 0, H = 0;
long long ans = 0;
char na[100000][11];
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%s", na[i]);
for (i = 0; i < n; i++) {
switch (na[i][0]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
H++;
break;
}
}
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[5] = {'M' - 'A', 'A' - 'A', 'R' - 'A', 'C' - 'A', 'H' - 'A'};
int cnt[26] = {0};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
cnt[s[0] - 'A']++;
}
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 += cnt[a[i]] * cnt[a[j]] * cnt[a[k]];
}
}
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
map<char, int> mp;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
int N;
cin >> N;
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') {
auto itr = mp.find(s[0]);
if (itr != mp.end()) {
mp[s[0]]++;
} else {
mp[s[0]] = 1;
}
}
}
char c1[10] = {'M', 'M', 'M', 'M', 'M', 'M', 'A', 'A', 'A', 'R'};
char c2[10] = {'A', 'A', 'A', 'R', 'R', 'C', 'R', 'R', 'C', 'C'};
char c3[10] = {'R', 'C', 'H', 'C', 'H', 'H', 'C', 'H', 'H', 'H'};
long long sum = 0;
for (int i = 0; i < 10; i++) {
sum += mp[c1[i]] * mp[c2[i]] * mp[c3[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;
string S[100010];
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main() {
int N;
cin >> N;
for (int i = 0; i < (int)N; i++) cin >> S[i];
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int i = 0; i < (int)N; i++) {
if (S[i][0] == 'M') M++;
if (S[i][0] == 'A') A++;
if (S[i][0] == 'R') R++;
if (S[i][0] == 'C') C++;
if (S[i][0] == 'H') H++;
}
int D[5] = {M, A, R, C, H};
long long res = 0;
for (int d = 0; d < 10; d++) {
res += D[P[d]] * D[Q[d]] * D[Q[d]];
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
#define size N
string s[size];
for (int i = 0; i < N; i++) {
cin >> s[i];
}
int march[5];
for (int i = 0; i < 5; i++) {
march[i] = 0;
}
for (int i = 0; i < N; i++) {
switch(s[i][0]) {
case 'M': march[0]++; break;
case 'A': march[1]++; break;
case 'R': march[2]++; break;
case 'C': march[3]++; break;
case 'H': march[4]++; break;
default: break;
}
}
int ans = 0;
int p[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int r[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int i = 0; i < 10) {
ans += march[p[i]] * march[q[i]] * march[r[i]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | use std::collections::HashMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;
fn main() {
let n: usize = read();
let mut s = HashMap::new();
for _ in 0..n {
let c: char = read::<String>().chars().next().unwrap();
if c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H' {
*s.entry(c).or_insert(0i64) += 1;
}
}
let s: Vec<i64> = s.iter().map(|(_, &n)| n).collect();
if s.len() == 3 {
println!("{}", s.iter().product::<i64>());
} else if s.len() == 4 {
let prod: i64 = s.iter().product::<i64>();
println!("{}", s.iter().map(|&x| prod / x).sum::<i64>());
} else if s.len() == 5 {
let prod: i64 = s.iter().product::<i64>();
let mut ans = 0;
for i in 0..5 {
for j in 0..5 {
if i != j {
ans += prod / (s[i] * s[j]);
}
}
}
println!("{}", ans);
}
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
let stdin = stdin();
let token: String = stdin
.lock()
.bytes()
.map(|b| b.unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().unwrap()
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int 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 = 0; s <= 2; s++) {
for (t = s + 1; t <= 3; t++) {
for (r = s + 2; r <= 4; r++) {
O += a[s] * a[t] * a[r];
}
}
}
printf("%d", O);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
int MARCH(vector<string> vec, int cnt) {
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int i = 0; i < (int)vec.size(); i++) {
if (vec.at(i).at(0) == 'M') M++;
if (vec.at(i).at(0) == 'A') A++;
if (vec.at(i).at(0) == 'R') R++;
if (vec.at(i).at(0) == 'C') C++;
if (vec.at(i).at(0) == 'H') H++;
}
if (M > 0) cnt++;
if (A > 0) cnt++;
if (R > 0) cnt++;
if (C > 0) cnt++;
if (H > 0) cnt++;
return cnt;
}
int combination(int n, int k) {
double ans = 1;
if (k == 1) {
return n / k;
}
ans = (double)n / k * combination(n - 1, k - 1);
return ans;
}
int main() {
int n;
cin >> n;
vector<string> vec(n);
for (int i = 0; i < n; i++) cin >> vec.at(i);
int cnt = 0;
cnt = MARCH(vec, cnt);
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int i = 0; i < n; i++) {
if (vec.at(i).at(0) == 'M') M++;
if (vec.at(i).at(0) == 'A') A++;
if (vec.at(i).at(0) == 'R') R++;
if (vec.at(i).at(0) == 'C') C++;
if (vec.at(i).at(0) == 'H') H++;
}
ll ans = 1LL * combination(cnt, 3);
if (M > 1) ans += 1LL * combination(cnt - 1, 2) * (M - 1);
if (A > 1) ans += 1LL * combination(cnt - 1, 2) * (A - 1);
if (R > 1) ans += 1LL * combination(cnt - 1, 2) * (R - 1);
if (C > 1) ans += 1LL * combination(cnt - 1, 2) * (C - 1);
if (H > 1) ans += 1LL * combination(cnt - 1, 2) * (H - 1);
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 m, a, r, c, h;
int main() {
long long int n, ans;
string s[100000];
cin >> 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++;
}
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < (int)(n); i++) cin >> s.at(i);
int march[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < (int)(n); i++) {
if (s.at(i).at(0) == 'M') march[0]++;
if (s.at(i).at(0) == 'A') march[1]++;
if (s.at(i).at(0) == 'R') march[2]++;
if (s.at(i).at(0) == 'C') march[3]++;
if (s.at(i).at(0) == 'H') march[4]++;
}
int count = 0;
for (int i = 0; i < (int)(5); i++) {
if (march[i] != 0) count++;
}
long long x = 1;
if (count < 3) cout << 0 << endl;
if (count == 3) {
for (int i = 0; i < (int)(5); i++) {
if (march[i] == 0)
continue;
else
x *= march[i];
}
cout << x << endl;
}
if (count == 4) {
for (int i = 0; i < (int)(5); i++) {
if (march[i] == 0)
continue;
else
x *= march[i];
}
long long result = 0;
for (int i = 0; i < (int)(5); i++) {
if (march[i] == 0)
continue;
else
result += x / march[i];
}
cout << result << endl;
}
if (count == 5) {
for (int i = 0; i < (int)(5); i++) {
x *= march[i];
}
long long result = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
result += x / (march[i] * march[j]);
}
}
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 | UNKNOWN | # Your code here!
n=gets.to_i
arr=[0,0,0,0,0]
n.times{
aa=gets.chomp.split("")[0]
if aa=="M"
arr[0]+=1
end
if aa=="A"
arr[1]+=1
end
if aa=="R"
arr[2]+=1
end
if aa=="C"
arr[3]+=1
end
if aa=="H"
arr[4]+=1
end
}
cc=arr.count(0)
if cc>=3
puts 0
exit
end
if cc==1
arr.delete(0)
a=arr[0]
b=arr[1]
c=arr[2]
d=arr[3]
puts a*b*c+a*b*d+a*c*d+b*c*d
exit
end
if cc==2
arr.delete(0)
a=arr[0]
b=arr[1]
c=arr[2]
puts a*b*c
exit
end
if cc==0
a=arr[0]
b=arr[1]
c=arr[2]
d=arr[3]
e=arr[4]
puts a*b*c+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+c*d*e+b*d*e
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = [input() for i in range(N)]
S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5
for i in range(N):
march_number[i] = S_first.count(march[i])
import itertools
ans=0
for v in itertools.combinations(march_number,3):
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 | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main() {
int n;
cin >> n;
vector<int> cnt(5, 0);
for (ll i = 0; i < (ll)(n); i++) {
string s;
cin >> s;
switch (s[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
}
}
ll ans = 0;
for (ll i = 0; i < (ll)(3); i++) {
for (ll j = i + 1; j <= (ll)(3); j++) {
for (ll k = j + 1; k <= (ll)(4); k++) {
if (cnt[i] == 0) continue;
if (cnt[j] == 0) continue;
if (cnt[k] == 0) continue;
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;
const long double PI = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int march[5] = {0};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
march[0]++;
}
if (s[i][0] == 'A') {
march[1]++;
}
if (s[i][0] == 'R') {
march[2]++;
}
if (s[i][0] == 'C') {
march[3]++;
}
if (s[i][0] == 'H') {
march[4]++;
}
}
int ans = 0;
for (int i = 0; i < 10; i++) {
ans += march[x[i]] * march[y[i]] * march[z[i]];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int main() {
int N; cin>>N;
int cnt[5]; REP(i,5) cnt[i]=0;
string S;
char[5] = {'M','A','R','C','H'};
REP(i,N) {
cin>>S;
REP(i,5) if (S[0]==char[i]) cnt[i]++;
}
i64 ans = 0;
ans = cnt[0]*cnt[1]*cnt[2] + cnt[0]*cnt[1]*cnt[3] + cnt[0]*cnt[1]*cnt[4] + cnt[0]*cnt[2]*cnt[3] + cnt[0]*cnt[2]*cnt[4] + cnt[0]*cnt[3]*cnt[4] + cnt[1]*cnt[2]*cnt[3]
+ cnt[1]*cnt[2]*cnt[4] + cnt[1]*cnt[3]*cnt[4] + cnt[2]*cnt[3]*cnt[4];
cout<<ans<<endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < (N); i++) cin >> S[i];
vector<int> cnt(26);
for (int i = 0; i < (N); i++) {
cnt[S[i][0] - 'A']++;
}
char c[5] = {'M', 'A', 'R', 'C', 'H'};
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 += cnt[c[i] - 'A'] * cnt[c[j] - 'A'] * cnt[c[k] - 'A'];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
int main() {
int N;
cin >> N;
vector<string> name(N);
for (int i = 0; i < N; i++) cin >> name[i];
map<char, int> count;
for (int i = 0; i < N; i++) {
if (name[i][0] == 'M' or name[i][0] == 'A' or name[i][0] == 'R' or
name[i][0] == 'C' or name[i][0] == 'H') {
count[name[i][0]]++;
}
}
ll sum = 0;
sum += count['M'] * count['A'] * count['R'];
sum += count['M'] * count['A'] * count['C'];
sum += count['M'] * count['A'] * count['H'];
sum += count['M'] * count['R'] * count['C'];
sum += count['M'] * count['R'] * count['H'];
sum += count['M'] * count['C'] * count['H'];
sum += count['A'] * count['R'] * count['C'];
sum += count['A'] * count['R'] * count['H'];
sum += count['A'] * count['C'] * count['H'];
sum += count['R'] * count['C'] * count['H'];
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections;
using System.Text;
class Program {
static void Main(string[] args) {
#if LOCAL_ENVIRONMENT
var stdin = new System.IO.StreamReader("stdin.txt");
System.Console.SetIn(stdin);
#endif
Inputer cin = new Inputer();
var N = cin.GetInt();
var S = cin.GetStringArray(N);
long[] cnt = new long[26];
char[,] t = new char[,] {
{'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 (var n = 0; n < N; n++) {
cnt[S[n][0] - 'A']++;
}
long ans = 0;
for (var n = 0; n < 10; n++) {
long c0 = cnt[t[n, 0] - 'A'];
long c1 = cnt[t[n, 1] - 'A'];
long c2 = cnt[t[n, 2] - 'A'];
ans += c0 * c1 * c2;
}
Console.Error.WriteLine($"{ans}");
} //main
public class Inputer {
private int cnt;
private string[] items;
public Inputer() {
this.cnt = 0;
var sb = new StringBuilder();
var s = Console.ReadLine();
while (s != null) {
sb.Append(s + " ");
s = Console.ReadLine();
}
this.items = sb.ToString().Split(' ');
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("items: {0}", this.items.ToStringA());
#endif
}
public void SetCnt(int n) { this.cnt = n; }
public int GetInt() {
return int.Parse(this.items[this.cnt++]);
}
public long GetLong() {
return long.Parse(this.items[this.cnt++]);
}
public string GetString() {
return this.items[this.cnt++];
}
public int[] GetIntArray(int n) {
if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!");
var r = new int[n];
for (var i = 0; i < n; i++) r[i] = this.GetInt();
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("[{0}]", string.Join(", ", r));
#endif
return r;
}
public long[] GetLongArray(int n) {
if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!");
var r = new long[n];
for (var i = 0; i < n; i++) r[i] = this.GetLong();
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("[{0}]", string.Join(", ", r));
#endif
return r;
}
public string[] GetStringArray(int n) {
if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!");
var r = new string[n];
for (var i = 0; i < n; i++) r[i] = this.GetString();
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("[{0}]", string.Join(", ", r));
#endif
return r;
}
public int[][] GetInt2Col(int n) {
const int M = 2;
if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!");
int[][] r = new int[M][] {
new int[n],
new int[n],
};
for (var i = 0; i < n; i++) {
r[0][i] = this.GetInt();
r[1][i] = this.GetInt();
}
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("[");
for (var i = 0; i < M; i++)
Console.Error.WriteLine(" [{0}],", string.Join(", ", r[i]));
Console.Error.WriteLine("]");
#endif
return r;
}
}
} //class
static class Extensions {
public static string ToStringA<T>(this T[] array, string separator = ", ", string braces = "[]") {
string bL = braces.Length > 0 ? braces[0].ToString() : "";
string bR = braces.Length > 1 ? braces[1].ToString() : "";
return bL + String.Join(separator, array) + bR;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INFF = 1e18;
int main() {
int n;
cin >> n;
int cnt[5] = {0};
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
char c = s.front();
if (c == 'M')
cnt[0]++;
else if (c == 'A')
cnt[1]++;
else if (c == 'R')
cnt[2]++;
else if (c == 'C')
cnt[3]++;
else if (c == 'H')
cnt[4]++;
}
long long ans = 0;
for (int i = 0; i < (5); i++)
for (int j = (i + 1); j < (5); j++)
for (int k = (j + 1); k < (5); k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long n=sc.nextLong();
long m= sc.nextLong();
long count=0;
long price=0;
Map<Long,Long> map = new HashMap<>();
for(int i=0;i<n;i++) {
long key= sc.nextLong();
long value = sc.nextLong();
if(map.containsKey(key)) {
map.put(key,value+map.get(key));
}else {
map.put(key,value);
}
}
Object[] mapkey = map.keySet().toArray();
Arrays.sort(mapkey);
for( long nkey: map.keySet()) {
long tempCount=map.get(nkey);
for(int i=1;i<=tempCount;i++) {
price+=nkey;
count+=1;
if(count==m) {System.out.println(price); 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 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input().strip())
s = [input().strip() for _ in range(n)]
num_m = len([True for _s in s if _s[0] == "M"])
num_a = len([True for _s in s if _s[0] == "A"])
num_r = len([True for _s in s if _s[0] == "R"])
num_c = len([True for _s in s if _s[0] == "C"])
num_h = len([True for _s in s if _s[0] == "H"])
print(num_m * num_a * num_r + num_m * num_a * num_c + num_m * num_a * num_h + num_m * num_r * num_c
+ num_m * num_r * num_h + num_m * num_c * num_h + num_a * num_r * num_c +
num_a * num_r * num_h + num_r * num_c * num_h)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
vector<string> M, A, R, C, H, FAL;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
string a;
cin >> a;
switch (a[0]) {
case 'M':
M.push_back(a);
break;
case 'A':
A.push_back(a);
break;
case 'R':
R.push_back(a);
break;
case 'C':
C.push_back(a);
break;
case 'H':
H.push_back(a);
default:
FAL.push_back(a);
break;
}
}
int sm = M.size();
int sa = A.size(), sr = R.size(), sc = C.size(), sh = H.size();
cout << sm * sa * (sr + sc + sh) + sm * sr * (sc + sh) + sm * sc * sh +
sa * sr * (sc + sh) + sr * sc * sh + sa * sc * sh;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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);
int Y = 0;
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i].at(0) == 'M') {
M++;
} else if (S[i].at(0) == 'A') {
A++;
} else if (S[i].at(0) == 'R') {
R++;
} else if (S[i].at(0) == 'C') {
C++;
} else if (S[i].at(0) == 'H') {
H++;
}
}
if (M > 0 && A > 0 && R > 0) {
Y += M * A * R;
}
if (M > 0 && A > 0 && C > 0) {
Y += M * A * C;
}
if (M > 0 && A > 0 && H > 0) {
Y += M * A * H;
}
if (M > 0 && R > 0 && C > 0) {
Y += M * R * C;
}
if (M > 0 && H > 0 && R > 0) {
Y += M * H * R;
}
if (M > 0 && C > 0 && H > 0) {
Y += M * C * H;
}
if (A > 0 && C > 0 && R > 0) {
Y += A * C * R;
}
if (H > 0 && A > 0 && R > 0) {
Y += H * A * R;
}
if (C > 0 && A > 0 && H > 0) {
Y += C * A * H;
}
if (H > 0 && C > 0 && R > 0) {
Y += H * C * R;
}
cout << Y << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<int> a(5);
for (long long int i = 0; i < n; i++) {
string s;
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 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 += 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 <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
copy_n(istream_iterator<string>(cin), N, S.begin());
int64_t m[256] = {0};
for (auto& item : S) {
++(m[item[0]]);
}
int64_t result = 0;
for (size_t i = 0; i < march.size() - 2; ++i) {
for (size_t j = i + 1; j < march.size() - 1; ++j) {
for (size_t k = j + 1; k < march.size(); ++k) {
result += m[march[i]] * m[march[j]] * m[march[k]];
}
}
}
cout << result << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
long long r = 0;
cin >> N;
vector<int> v(5, 0);
for (int i = 0; i < N; ++i) {
cin >> S;
if (S[0] == 'M')
v[0] += 1;
else if (S[0] == 'A')
v[1] += 1;
else if (S[0] == 'R')
v[2] += 1;
else if (S[0] == 'C')
v[3] += 1;
else if (S[0] == 'H')
v[4] += 1;
}
for (int i = 0; i < 3; ++i) {
for (int j = i + 1; j < 4; ++j) {
if (j == 4) break;
for (int k = j + 1; k < 5; ++k) {
if (k == 5) break;
r += v[i] * v[j] * v[k];
}
}
}
cout << r << endl;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.