Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using 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, ll> 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S[N];
for (int i = 0; i < N; ++i) {
cin >> S[i];
}
char head[] = {'M', 'A', 'R', 'C', 'H'};
int headCount[] = {0, 0, 0, 0, 0};
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 5; ++j) {
if (S[i][0] == head[j]) {
headCount[j]++;
}
}
}
int nonZero = 0;
for (int i = 0; i < 5; ++i) {
if (headCount[i] != 0) {
nonZero++;
}
}
long long result = 0;
for (int i = 0; i < 3; ++i) {
for (int j = i + 1; j < 4; ++j) {
for (int k = j + 1; k < 5; ++k)
result += headCount[i] * headCount[j] * headCount[k];
}
}
cout << result << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a[105];
int n, cnt;
int main() {
string s, r = "MARCH";
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
a[s[0]]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += a[r[i]] * a[r[j]] * a[r[k]];
}
}
}
printf("%d", cnt);
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.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Set<String>set = new HashSet<String>();
int n = sc.nextInt();
boolean m = true;
boolean a = true;
boolean r = true;
boolean c = true;
boolean h = true;
int M , A , R , C , H;
M = 0;
A = 0;
R = 0;
C = 0;
H = 0;
for(int i = 0 ; i < n ;i++) {
String s = sc.next();
char x = s.charAt(0);
m = (x == 'M' );
a = (x == 'A');
r = (x == 'R');
c = (x == 'C');
h = (x == 'H');
if(!set.contains(s)) {
set.add(s);
if(m) {
M++;
}
if(a){
A++;
}
if(r) {
R++;
}
if(c) {
C++;
}
if(h) {
H++;
}
}
}
long ans = 0;
ans += (long)M * A * (R + C + H);
ans += (long)M * R * (C + H);
ans += (long)M * C * H;
ans += (long)A * R * (C + H);
ans += (long)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() {
long long N, r = 0;
string S;
map<char, long long> m;
vector<long long> c(5, 0);
cin >> N;
for (int i = 0; i < (N); ++i) {
cin >> S;
if (!m.count(S.at(0)))
m[S.at(0)] = 1;
else
++m.at(S.at(0));
}
if (m.count('M')) c.at(0) = m.at('M');
if (m.count('A')) c.at(1) = m.at('A');
if (m.count('R')) c.at(2) = m.at('R');
if (m.count('C')) c.at(3) = m.at('C');
if (m.count('H')) c.at(4) = m.at('H');
for (int i = 0; i < (1 << 5); ++i) {
int tt = 1;
vector<int> t;
for (int j = 0; j < (5); ++j)
if (i & 1 << j) t.push_back(c.at(j));
if (t.size() != 3) continue;
for (int j = 0; j < (t.size()); ++j) tt *= t.at(j);
r += tt;
}
cout << r << 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 en = "\n";
string t = "hello";
bool isVowel(char ch) {
ch = toupper(ch);
if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
return true;
return false;
}
int toInt(string s) {
int sm;
stringstream ss(s);
ss >> sm;
return sm;
}
template <typename T>
inline T gcd(T a, T b) {
if (a < 0) return gcd(-a, b);
if (b < 0) return gcd(a, -b);
return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
if (a < 0) return lcm(-a, b);
if (b < 0) return lcm(a, -b);
return a * (b / gcd(a, b));
}
int main() {
long long m, a, r, c, h, n, i;
while (cin >> n) {
m = a = r = c = h = 0;
string s;
for (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++;
}
long long x = 0;
x += m * a * r;
x += m * a * c;
x += m * a * h;
x += m * r * c;
x += m * r * h;
x += a * r * c;
x += a * r * h;
x += a * c * h;
x += r * c * h;
cout << x << en;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = (0); i < (n); ++i) cin >> s[i];
vll c(5);
for (int i = (0); i < (n); ++i) {
if (s[i][0] == 'M')
c[0]++;
else if (s[i][0] == 'A')
c[1]++;
else if (s[i][0] == 'R')
c[2]++;
else if (s[i][0] == 'C')
c[3]++;
else if (s[i][0] == 'H')
c[4]++;
}
ll 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 += 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;
scanf("%d", &n);
string str;
int countM = 0;
int countA = 0;
int countR = 0;
int countC = 0;
int countH = 0;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M') {
countM++;
}
if (str[0] == 'A') {
countA++;
}
if (str[0] == 'R') {
countR++;
}
if (str[0] == 'C') {
countC++;
}
if (str[0] == 'H') {
countH++;
}
}
unsigned long long sum = 0;
sum += countM * countA * countR;
sum += countM * countA * countC;
sum += countM * countA * countH;
sum += countM * countR * countC;
sum += countM * countR * countH;
sum += countM * countC * countH;
sum += countA * countR * countC;
sum += countA * countR * countH;
sum += countA * countC * countH;
sum += countR * countC * countH;
printf("%llu", sum);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
long long c = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
if ((p[k][0] == 'M' || p[k][0] == 'A' || p[k][0] == 'R' ||
p[k][0] == 'C' || p[k][0] == 'H') &&
(p[j][0] == 'M' || p[j][0] == 'A' || p[j][0] == 'R' ||
p[j][0] == 'C' || p[j][0] == 'H') &&
(p[i][0] == 'M' || p[i][0] == 'A' || p[i][0] == 'R' ||
p[i][0] == 'C' || p[i][0] == 'H') &&
p[k][0] != p[i][0] && p[k][0] != p[j][0] && p[i][0] != p[j][0]) {
c++;
}
}
}
}
cout << c << 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 | num = gets.to_i
initial = {"M": 0,"A": 0,"R": 0,"C": 0,"H": 0}
while num > 0 do
num -= 1
n = gets.to_s[0]
if n == "M"||"A"||"R"||"C"||"H"
initial[n.to_sym] += 1
end
end
count = 0
"MARCH".split("").combination(3).map do |a,b,c|
#puts "#{a},#{b},#{c}"
count = count + (initial[a.to_sym] * initial[b.to_sym] * initial[c.to_sym])
end
puts count
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
int n;
cin >> n;
int ans = 0, cntm, cnta, cntr, cntc, cnth;
string S;
int C[5] = {0};
for (int i = 0; i < n; i++) {
string S;
cin >> S;
if (S[0] == 'M')
cntm++;
else if (S[0] == 'A')
cnta++;
else if (S[0] == 'R')
cntr++;
else if (S[0] == 'C')
cntc++;
else if (S[0] == 'H')
cnth++;
}
C[0] = cntm;
C[1] = cnta;
C[2] = cntr;
C[3] = cntc;
C[4] = cnth;
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;
cout << 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;
public class Test
{
public static void Main()
{
// your code goes here
char[] initial = new char[2];
char[] topname = new char[5]{'M', 'A', 'R', 'C', 'H'};
int N, count=0;
N = int.Parse(Console.ReadLine());
string[]name = new string[N];
for(int i=0;i<N;i++)
{
name[i] = Console.ReadLine();
}
for(int i=0;i<N-2;i++)
{
if(0<=Array.IndexOf(topname, name[i][0]))
{
initial[0] = name[i][0];
for(int j=i+1;j<N-1;j++)
{
if(0<=Array.IndexOf(topname, name[j][0])&&
0>Array.IndexOf(initial, name[j][0]))
{
initial[1] = name[j][0];
for(int a=j+1;a<N;a++)
{
if(0<=Array.IndexOf(topname, name[a][0])&&
0>Array.IndexOf(initial, name[a][0]))
{
count++;
Console.WriteLine("{0} {1} {2}", name[i], name[j], name[a]);
}
}
initial[1] = '\0';
}
}
}
}
Console.WriteLine(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 | UNKNOWN | my $N = <STDIN>;
my $S;
my @arr = ("M","A","R","C","H");
foreach (@arr) {
$S->{$_} = 0;
}
while (my $l = <STDIN>) {
chomp $l;
if ($l =~ /^([MARCH])/) {
$S->{$1}++;
}
}
my $num = 0;
foreach my $i (0..$N-1) {
foreach my $j ($i+1..$N-1) {
foreach my $k ($j+1..$N-1) {
$num += $S->{$arr[$i]} * $S->{$arr[$j]} * $S->{$arr[$k]};
}
}
}
print $num; |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S[N];
for (int i = 0; i < N; i++) {
cin >> S[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[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++;
}
}
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;
cin >> N;
unordered_map<char, int> charMap;
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
char c = s[0];
switch (c) {
case 'M':
case 'A':
case 'R':
case 'C':
case 'H':
if (charMap.find(c) != charMap.end()) {
charMap[c]++;
} else {
charMap[c] = 1;
}
break;
default:
break;
}
}
if (charMap.size() < 3) {
cout << 0 << endl;
return 0;
}
long long result = 0;
string target = "MARCH";
for (int i = 0; i < target.size(); ++i) {
if (charMap.find(target[i]) == charMap.end()) continue;
for (int j = i + 1; j < target.size(); ++j) {
if (charMap.find(target[j]) == charMap.end()) continue;
for (int k = j + 1; k < target.size(); ++k) {
if (charMap.find(target[k]) == charMap.end()) continue;
result += charMap[target[i]] * charMap[target[j]] * charMap[target[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() {
string s;
int N;
long long m, a, r, c, h;
long long D[5];
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
scanf("% d ", &N);
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
long long res = 0;
for (int d = 0; d < 10; d++) res += D[P[d]] * D[Q[d]] * D[R[d]];
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 long long MOD = (long long)(1e9 + 7);
const long long INF = (long long)(1e13 + 7);
long long bpm(long long x, long long y) {
if (x == 0)
return 0;
else if (y == 0) {
return 1;
}
long long ans = 1;
x %= MOD;
long long digit = (long long)((log((double)y) / log((double)2) / 1 + 1));
for (long long i = 0; i < digit; i++) {
if (((y >> i) & 1u) == 1) {
ans *= x;
ans %= MOD;
}
x = x * x;
x %= MOD;
}
return ans;
}
class CMarch {
public:
long long solve(std::istream& cin, std::ostream& cout) {
long long N;
cin >> N;
vector<long long> MARCH(5, 0);
string march = "MARCH";
for (long long i = 0; i < (long long)(N); i++) {
string temp;
cin >> temp;
for (long long j = 0; j < (long long)(5); j++) {
if (temp[0] == march[j]) MARCH[j] += 1;
}
}
long long ans =
MARCH[0] * (MARCH[1] * (MARCH[2] + MARCH[3] + MARCH[4]) +
MARCH[2] * (MARCH[3] + MARCH[4]) + MARCH[3] + MARCH[4]) +
MARCH[1] * (MARCH[2] * (MARCH[3] + MARCH[4]) + MARCH[3] * MARCH[4]) +
MARCH[2] * MARCH[3] * MARCH[4];
cout << ans << endl;
}
};
signed main() {
CMarch solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
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 n, a[5] = {0, 0, 0, 0, 0}, ans;
scanf("%ld", &n);
for (int i = 0; i < n; i++) {
char s[5];
scanf("%s", s);
if (s[0] == 'M') {
a[0]++;
} else if (s[0] == 'A') {
a[1]++;
} else if (s[0] == 'R') {
a[2]++;
} else if (s[0] == 'C') {
a[3]++;
} else if (s[0] == 'H') {
a[4]++;
}
}
for (int z = 0; z < 3; z++) {
for (int c = z + 1; c < 4; c++) {
for (int v = c + 1; v < 5; v++) {
ans = a[z] * a[c] * a[v];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
long num = 0;
int i, N, M = 0, A = 0, R = 0, C = 0, H = 0;
char name[20];
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%s", name);
if (name[0] == 'M') {
M++;
}
if (name[0] == 'A') {
A++;
}
if (name[0] == 'R') {
R++;
}
if (name[0] == 'C') {
C++;
}
if (name[0] == 'H') {
H++;
}
}
num += M * A * R;
num += M * A * C;
num += M * A * H;
num += A * R * C;
num += A * R * H;
num += R * C * H;
num += M * R * C;
num += M * R * H;
num += M * C * H;
num += A * C * H;
printf("%ld\n", num);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | m, a, r, c, h = [0] * 5
N = int(input())
for _ in range(N):
s = input()[0]
if s == 'M':
m += 1
elif s == 'A':
a += 1
elif s == 'R':
r += 1
elif s == 'C':
c += 1
elif s == 'H':
h += 1
print(m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + r * c * h)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt[5] = {0};
long long ans = 0;
cin >> n;
string s;
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]++;
}
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
ans += 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 n, i, b[10] = {0}, t = 0, j, k;
char a[1000];
cin >> n;
while (n--) {
cin >> a;
if (a[0] == 'M')
b[0]++;
else if (a[0] == 'A')
b[1]++;
else if (a[0] == 'R')
b[2]++;
else if (a[0] == 'C')
b[3]++;
else if (a[0] == 'H')
b[4]++;
}
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
t += b[i] * b[j] * b[k];
}
}
}
cout << t << 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 m, a, r, c, h = 0;
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> N;
while (N--) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
long long d[5];
long long x = 0;
d[0] = m;
d[1] = a;
d[2] = r;
d[3] = c;
d[4] = h;
for (int i = 0; i < 10; i++) {
x += d[P[i]] * d[Q[i]] * d[R[i]];
}
cout << x << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, counter = 0;
vector<string> data;
string temp;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> temp;
if (temp[0] != 'M' && temp[0] != 'A' && temp[0] != 'R' && temp[0] != 'C' &&
temp[0] != 'H') {
continue;
}
data.push_back(temp);
}
for (vector<string>::size_type i = 0; i < N - 2; i++) {
for (vector<string>::size_type j = i + 1; j < N - 1; j++) {
for (vector<string>::size_type k = j + 1; k < N; k++) {
if (data[i][0] != data[j][0] && data[k][0] != data[j][0] &&
data[i] != data[k]) {
counter++;
}
}
}
}
cout << counter << 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>
#pragma GCC optimize("O0")
using namespace std;
template <typename LenType = int>
LenType readln(char* buf, LenType max) {
fgets(buf, max + 1, stdin);
buf[strcspn(buf, "\n")] = 0;
}
template <typename T>
int orderDesc(const void* p1, const void* p2) {
const T& a = *static_cast<const T*>(p1);
const T& b = *static_cast<const T*>(p2);
return (a < b);
}
template <typename T>
int orderAsc(const void* p1, const void* p2) {
const T& a = *static_cast<const T*>(p1);
const T& b = *static_cast<const T*>(p2);
return (a > b);
}
int N;
char S[10001][11];
int hashfunc(char c) {
switch (c) {
case 'M':
return 0;
case 'A':
return 1;
case 'R':
return 2;
case 'C':
return 3;
case 'H':
return 4;
}
return -1;
}
void solve() {
int counts[5] = {0, 0, 0, 0, 0};
int hashcode;
for (int i = 1; i <= N; ++i) {
hashcode = hashfunc(S[i][0]);
if (hashcode != -1) ++counts[hashcode];
}
long long res = 0;
for (int i = 0; i <= 3; ++i) {
for (int j = i + 1; j <= 4; ++j) {
for (int x = j + 1; x <= 5; ++x) {
res += counts[i] * counts[j] * counts[x];
}
}
}
cout << res << endl;
}
int main() {
scanf("%d\n", &N);
for (int i = 1; i <= N && !feof(stdin); ++i) {
readln(S[i], 10);
}
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int i, ans = 1, x = 0;
string name[1000000];
cin >> i;
for (; i > 0; i--) {
cin >> name[i];
if (name[i][0] == 'M' || name[i][0] == 'A' || name[i][0] == 'R' ||
name[i][0] == 'C' || name[i][0] == 'H') {
x++;
}
}
for (; x > 3; x--) {
ans *= x;
}
ans /= 2;
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int n;
string march = "MARCH";
string s;
int count[5] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (march[j] == s[0]) {
count[j]++;
break;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += count[i] * count[j] * count[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 | java | import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;
public class Main {
public static int M = 5;
public static void main(String[] args) {
int i,j,k;
Scanner sc = new Scanner(in);
int n = parseInt(sc.next());
char[] s = null;
char[] ma = new char[M];
for (i = 0; i < n; i++) {
s = sc.next().toCharArray();
switch(s[0]) {
case 'M':
ma[0]++;
break;
case 'A':
ma[1]++;
break;
case 'R':
ma[2]++;
break;
case 'C':
ma[3]++;
break;
case 'H':
ma[4]++;
break;
}
}
sc.close();
long ans = 0L;
long tmp = 1L;
for (i = 0; i < M-2; i++) {
for (j = i+1; j < M-1; j++) {
for (k = j+1; k < M; k++) {
tmp = ma[i]*ma[j]*ma[k];
ans += tmp;
}
}
}
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())
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.count(march[i])
import itertools
ptr = list(itertools.combinations(march_number,3))
ans = 0
seki = 1
for i in range(len(ptr)):
for j in range(3):
seki *= ptr[i][j]
ans += seki
seki = 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;
cin >> n;
vector<string> s(n);
vector<int> p(5);
for (int i = 0; i < (int)(n); i++) {
cin >> s.at(i);
if (s.at(i).at(0) == 'M') {
p.at(0)++;
}
if (s.at(i).at(0) == 'A') {
p.at(1)++;
}
if (s.at(i).at(0) == 'R') {
p.at(2)++;
}
if (s.at(i).at(0) == 'C') {
p.at(3)++;
}
if (s.at(i).at(0) == 'H') {
p.at(4)++;
}
}
long long ans = 0;
int i, j, k;
for (i = 0; i < 5; i++) {
for (j = i + 1; j < 5; j++) {
for (k = j + 1; k < 5; k++) {
ans += p.at(i) * p.at(j) * p.at(k);
}
}
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int list[5];
for (int i = 0; i < 5; i++) list[i] = 0;
for (int i = 0; i < N; i++) {
char name[11];
scanf("%s", name);
switch (name[0]) {
case 'M':
list[0]++;
break;
case 'A':
list[1]++;
break;
case 'R':
list[2]++;
break;
case 'C':
list[3]++;
break;
case 'H':
list[4]++;
break;
default:
break;
}
}
int num = 0;
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
num += list[i] * list[j] * list[k];
}
}
}
cout << num << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MX = 1e6;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
using ll = long long;
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 { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) { return fac[a] / fac[b] / fac[a - b]; }
int a[2001];
signed main() {
int n;
cin >> n;
vector<string> a(n);
map<char, int> m;
for (int i = (0); i < (n); ++i) {
cin >> a[i];
m[a[i][0]]++;
}
vector<int> c;
c.push_back(m['M']);
c.push_back(m['A']);
c.push_back(m['R']);
c.push_back(m['C']);
c.push_back(m['H']);
int ans = 0;
for (int i = (0); i < (5); ++i) {
for (int j = (i); j < (5); ++j) {
for (int k = (j); k < (5); ++k) {
if (i == j || j == k || k == i) continue;
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;
const int INF = 1000000007;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
string S[N];
int A[5] = {};
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M')
A[0]++;
else if (S[i][0] == 'A')
A[1]++;
else if (S[i][0] == 'R')
A[2]++;
else if (S[i][0] == 'C')
A[3]++;
else if (S[i][0] == 'H')
A[4]++;
}
int64_t ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += A[i] * A[j] * A[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
char s[] = {'M', 'A', 'R', 'C', 'H'};
int c[5] = {0, 0, 0, 0, 0};
int N;
cin >> N;
string t;
for (int i = 0; i < N; i++) {
cin >> t;
for (int j = 0; j < 5; j++) {
if (t[0] == s[j]) {
c[j]++;
}
}
}
int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int j, i, s = 0;
cin >> j;
string a[10000];
for (i = 0; i < j; i++) {
cin >> a[i];
if (a[i][0] == 'M' || a[i][0] == 'A' || a[i][0] == 'R' || a[i][0] == 'C' ||
a[i][0] == 'H')
s++;
}
cout << s * (s - 1) * (s - 2) / 6 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> check;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
char c = s[0];
if (c == 'M') check[0]++;
if (c == 'A') check[1]++;
if (c == 'R') check[2]++;
if (c == 'C') check[3]++;
if (c == 'H') check[4]++;
}
ll ans = 0;
for (int a = 0; a < 3; a++) {
for (int b = a + 1; b < 4; b++) {
for (int c = b + 1; c < 5; c++) {
ans += check[a] * check[b] * check[c];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const long long INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
int a[5];
int main(void) {
int n;
cin >> n;
while (n--) {
char s[11];
scanf("%s", s);
switch (s[0]) {
case 'A':
a[0]++;
break;
case 'C':
a[1]++;
break;
case 'R':
a[2]++;
break;
case 'M':
a[3]++;
break;
case 'H':
a[4]++;
break;
}
}
long long sum = 0;
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5 && i != j; ++j)
for (int k = 0; k < 5 && i != k && j != k; ++k) {
if (a[i] && a[j] && a[k]) {
sum += a[i] * (a[j]) * (a[k]);
}
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = (0); i < (int)(n); i++) {
string x;
cin >> x;
switch (x[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
int shurui = 0;
if (m >= 1) shurui++;
if (a >= 1) shurui++;
if (r >= 1) shurui++;
if (c >= 1) shurui++;
if (h >= 1) shurui++;
ll cnt = 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 << cnt << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const int N = 100000;
ll cnt_nxt[N][83] = {0};
ll cnt_prev[N][83] = {0};
int main() {
int n;
cin >> n;
vector<string> vs(n);
for (int i = 0; i < (int)n; ++i) cin >> vs[i];
ll c = 0, b;
string m = "MARCH";
for (int i = 0; i < (int)n; ++i) {
b = (int)vs[i][0];
if (!(b == 'M' || b == 'A' || b == 'R' || b == 'C' || b == 'H')) continue;
if (i > 0) {
for (int j = 0; j < (int)m.size(); ++j)
cnt_prev[i][(int)m[j]] = cnt_prev[i - 1][(int)m[j]];
cnt_prev[i][b] = cnt_prev[i - 1][b] + 1;
} else
cnt_prev[i][b] = 1;
}
for (int i = (int)n - 1; i >= (int)0; --i) {
b = (int)vs[i][0];
if (!(b == 'M' || b == 'A' || b == 'R' || b == 'C' || b == 'H')) continue;
if (i == n - 1)
cnt_nxt[i][b] = 1;
else {
for (int j = 0; j < (int)m.size(); ++j)
cnt_nxt[i][(int)m[j]] = cnt_nxt[i + 1][(int)m[j]];
cnt_nxt[i][b] = cnt_nxt[i + 1][b] + 1;
}
}
for (int i = (int)(1); i < (int)(n); ++i) {
b = (int)vs[i][0];
if (!(b == 'M' || b == 'A' || b == 'R' || b == 'C' || b == 'H')) continue;
for (int j = 0; j < (int)m.size(); ++j) {
for (int k = 0; k < (int)m.size(); ++k)
if (j != k && (b != m[j] && b != m[k])) {
c += cnt_prev[i - 1][(int)m[j]] * cnt_nxt[i + 1][(int)m[k]];
}
}
}
cout << (c) << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import sys,itertools
input = sys.stdin.readline
N = int(input())
S = set([input() for _ in range(N)])
m = len([cand for cand in S if ((cand[0] == 'M')) ])
a = len([cand for cand in S if ((cand[0] == 'A')) ])
r = len([cand for cand in S if ((cand[0] == 'R')) ])
c = len([cand for cand in S if ((cand[0] == 'C')) ])
h = len([cand for cand in S if ((cand[0] == 'H')) ])
# print(set_elements_num)
comb = m*a*r + m*a*c + m*a*h
comb += m*r*c + m*r*h
comb += a*r*c + a*r*h + a*c*h
comb += r*c*h
print(comb) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const double pi =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod = 1000000007;
int bitCount(uint bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16);
}
int main() {
int n, a[55] = {};
char ch[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
string s;
long long ans = 0;
int c = 0;
for (int i = (0); i < (n); ++i) {
cin >> s;
if (a[s[0] - 'A'] == 0) c++;
a[s[0] - 'A']++;
}
if (c < 3) {
cout << 0 << endl;
return 0;
}
for (int i = (0); i < (32); ++i) {
if (bitCount(i) != 3) continue;
int plus = 1;
for (int j = (0); j < (5); ++j) {
if (((i >> j) & 1)) plus *= a[ch[j] - 'A'];
}
ans += plus;
}
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 ;
typedef long long ll ;
string s ;
int N ;
ll m ,a ,r ,c , h ;
ll D [5];
int P [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
int Q [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
int R [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
int main ()
{
scanf ("% d " ,& N );
for ( int i =0; i < N ; i ++)
{
cin > > s ;
if ( s [0]=='M') m ++;
if ( s [0]=='A') a ++;
if ( s [0]=='R') r ++;
if ( s [0]=='C') c ++;
if ( s [0]=='H') h ++;
}
D [0]= m , D [1]= a , D [2]= r , D [3]= c , D [4]= h ;
ll res =0;
for ( int d =0; d <10; d ++)
res += D [ P [ d ]]* D [ Q [ d ]]* D [ R [ d ]];
cout << res;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | private val ACCEPTABLE_HEAD = setOf("M", "A", "R", "C", "H")
fun main(args: Array<String>) {
val n = readLine()?.toInt() ?: return
// 名前の頭文字とその数のmapを作ってしまう
// MARCH以外の頭文字をもつ名前は除外する
val sMap: Map<String, Int> = (0 until n)
.map { readLine()!![0].toString() }
.filter { it in ACCEPTABLE_HEAD }
.groupBy { it }
.mapValues { it.value.size }
// sMapのsizeは今確実に5未満となっている
// 5個から3つ選ぶ組み合わせを計算するために3重ループするが、
// これは十分間に合う速度
var count = 0L
for (entry1 in sMap.entries) {
for (entry2 in sMap.entries) {
for (entry3 in sMap.entries) {
// keyの順序を固定することで重複を排除する
// Kotlin(1.0.0)だとcompareでChar to Numberの変換が行われてClassCastException
// となるので、それを回避
if (entry1.key < entry2.key &&
entry1.key < entry3.key &&
entry2.key < entry3.key)
{
count += (entry1.value * entry2.value * entry3.value)
}
}
}
}
println(count)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<char, int> Head{
{'M', 0}, {'A', 0}, {'R', 0}, {'C', 0}, {'H', 0},
};
for (int i = 0; i < N; i++) {
string S;
cin >> S;
Head[S[0]]++;
}
long long int ans = 0;
vector<int> Human(5);
Human[0] = Head['M'], Human[1] = Head['A'], Human[2] = Head['R'],
Human[3] = Head['C'], Human[4] = Head['H'];
for (int i = 0; i < 5 - 2; i++) {
for (int j = i + 1; j < 5 - 1; j++) {
for (int k = j + 1; k < 5; k++) {
ans += (Human[i] * Human[j] * Human[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;
int result = 0;
cin >> N;
vector<string> S[5];
bool b[5];
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
S[0].push_back(s);
} else if (s[0] == 'A') {
S[1].push_back(s);
} else if (s[0] == 'R') {
S[2].push_back(s);
} else if (s[0] == 'C') {
S[3].push_back(s);
} else if (s[0] == 'H') {
S[4].push_back(s);
} else {
}
}
int count = 0;
for (int i = 0; i < 5; i++) {
if (S[i].size() <= 0) {
count++;
b[i] = false;
} else {
b[i] = true;
}
}
if (N - count <= 2) {
cout << result << endl;
return 0;
}
if (b[0] && b[1] && b[2]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[2].size(); k++) {
result++;
}
}
}
}
if (b[0] && b[1] && b[3]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
}
if (b[0] && b[1] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[1].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
if (b[0] && b[2] && b[3]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
}
if (b[0] && b[2] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
if (b[0] && b[3] && b[4]) {
for (int i = 0; i < S[0].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
if (b[1] && b[2] && b[3]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[3].size(); k++) {
result++;
}
}
}
}
if (b[1] && b[2] && b[4]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[2].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
if (b[1] && b[3] && b[4]) {
for (int i = 0; i < S[1].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
if (b[2] && b[3] && b[4]) {
for (int i = 0; i < S[2].size(); i++) {
for (int j = 0; j < S[3].size(); j++) {
for (int k = 0; k < S[4].size(); k++) {
result++;
}
}
}
}
cout << result << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main() {
int N;
scanf("%d", &N);
char S[N][10];
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
scanf("%s", S[i]);
switch (S[i][0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
default:
break;
}
}
long long ans;
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 | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 要素の入力、格納
int N = sc.nextInt();
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
String head = "";
for (int i = 0; i < N; i++) {
head = sc.next().substring(0, 1);
if (head.equals("M")) {
m++;
} else if (head.equals("A")) {
a++;
} else if (head.equals("R")) {
r++;
} else if (head.equals("C")) {
c++;
} else if (head.equals("H")) {
h++;
}
}
long ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h
+ a * c * h + r * c * h;
// 出力
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int N;
cin >> N;
string S[100010];
int m = 0, a = 0, r = 0, c = 0, h = 0;
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++;
}
cout << m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * c * h + a * r * h + r * c * h;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
int sum[5];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M') sum[0]++;
if (S[0] == 'A') sum[1]++;
if (S[0] == 'R') sum[2]++;
if (S[0] == 'C') sum[3]++;
if (S[0] == 'H') sum[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 += sum[i] * sum[j] * sum[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 next_combination(int sub) {
int x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
int main() {
int n;
cin >> n;
string march = "MARCH";
vector<int> count_march(5);
for (int i = 0; i < n; i++) {
string name;
cin >> name;
char ini = name[0];
int pos = march.find(ini);
if (pos == string::npos)
continue;
else
count_march[pos]++;
}
int64_t ans = 0;
int p = 5;
int q = 3;
int bit = (1 << q) - 1;
for (; bit < (1 << p); bit = next_combination(bit)) {
vector<int> S;
int64_t subtotal = 1;
for (int i = 0; i < n; ++i) {
if (bit & (1 << i)) {
S.push_back(i);
}
}
for (int i = 0; i < S.size(); i++) {
subtotal *= count_march[S[i]];
}
ans += subtotal;
}
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 | fun main(args:Array<String>){
val march = "MARCH".toList().map(Char::toString).toSet()
val n = readLine()!!.toInt()
val bs = (1..n).map { readLine()!!.toList().first().toString() }
val char_freq = mutableMapOf<String, Int>()
for( char in bs ) {
if( march.contains(char) == false )
continue
if( char_freq.get(char) == null )
char_freq[char] = 0
char_freq[char] = char_freq[char]!! + 1
}
//println(char_freq)
val size = char_freq.size
// 3つ選んだアルファベットのsetを作る
val bag = mutableSetOf<MutableSet<String>>()
val keys = char_freq.toList().map { it.first }
for( key1 in keys ) {
for ( key2 in keys ) {
for( key3 in keys ) {
val minibag = mutableSetOf<String>()
minibag.add(key1)
minibag.add(key2)
minibag.add(key3)
if( minibag.size != 3) continue
bag.add(minibag)
}
}
}
bag.map { minibag ->
minibag.map { key ->
char_freq[key]!!
}.reduce { y,x -> y*x }
}.sum().let(::println)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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> a(26);
for (int i = 0; i < N; i++) a[S[i][0] - 'A']++;
long ans = 0;
ans += a['M' - 'A'] * a['A' - 'A'] * a['R' - 'A'];
ans += a['M' - 'A'] * a['A' - 'A'] * a['C' - 'A'];
ans += a['M' - 'A'] * a['A' - 'A'] * a['H' - 'A'];
ans += a['M' - 'A'] * a['R' - 'A'] * a['C' - 'A'];
ans += a['M' - 'A'] * a['R' - 'A'] * a['H' - 'A'];
ans += a['M' - 'A'] * a['C' - 'A'] * a['H' - 'A'];
ans += a['A' - 'A'] * a['R' - 'A'] * a['C' - 'A'];
ans += a['A' - 'A'] * a['R' - 'A'] * a['H' - 'A'];
ans += a['A' - 'A'] * a['C' - 'A'] * a['H' - 'A'];
ans += a['R' - 'A'] * a['C' - 'A'] * a['H' - 'A'];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
using namespace std;
int a[35][35];
int main() {
int n;
cin >> n;
string s;
unsigned long long m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
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;
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;
int used[5][5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
used[i][j][k] = 0;
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = 1; j < 4; j++) {
for (int m = 2; m < 5; m++) {
if (j == m || i == m || i == j) {
continue;
} else {
if (used[i][j][m] == 0) {
ans += cou[i] * cou[j] * cou[m];
used[i][j][m] = 1;
used[j][i][m] = 1;
used[i][m][j] = 1;
used[j][m][i] = 1;
used[m][i][j] = 1;
used[m][j][i] = 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 | java | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
String[] S = new String[N];
long[] count = new long[5];
long ans = 0;
for (int i = 0; i < N; i++){
S[i] = scanner.next();
}
for (int i = 0; i < N; i++){
if(S[i].charAt(0) == 'M'){
count[0]++;
} else if (S[i].charAt(0) == 'A'){
count[1]++;
} else if (S[i].charAt(0) == 'R'){
count[2]++;
} else if (S[i].charAt(0) == 'C'){
count[3]++;
} else if (S[i].charAt(0) == 'H'){
count[4]++;
} else {
return;
}
}
ans = count[0] * count[1] * count[2] + count[0] * count[1]* count[3] +
count[0] * count[1] * count[4] + count[0] * count[2] * count[3] +
count[0] * count[2] * count[4] + count[0] * count[3] * count[4] +
count[1] * count[2] * count[3] + count[1] * count[2] * count[4] +
count[1] * count[3] * count[4] + count[2] * count[3] * count[4];
}
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 | UNKNOWN | using System;
using System.Collections.Generic;
namespace MyProgram{
class AtCoder{
static void Main(){
int N = int.Parse(Console.ReadLine());
string[] S = new string[N];
for(var i=0;i<N;i++){
S[i] = Console.ReadLine();
}
int[] march = {0,0,0,0,0};
for(var 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;
}
}
long sum=0;
for(var i=0;i<3;i++){
for(var j=i+1;j<4;j++){
for(var k=j+1;k<5;k++){
sum += march[i] * march[j] * march[k];
}
}
}
Console.WriteLine(sum);
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int arr[5];
long long ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char name[1000];
scanf("%s", name);
if (name[0] == 'M')
arr[0]++;
else if (name[0] == 'A')
arr[1]++;
else if (name[0] == 'R')
arr[2]++;
else if (name[0] == 'C')
arr[3]++;
else if (name[0] == 'H')
arr[4]++;
}
for (int i = 0; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
for (int k = j + 1; k <= n; k++) {
ans += arr[i] * arr[j] * arr[k];
}
}
}
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | from sequtils import map, mapIt
from strutils import split, parseInt, parseFloat
import macros
macro unpack*(input: seq; count: static[int]): untyped =
result = quote do: ()
when NimMinor <= 13:
for i in 0..<count: result[0].add quote do: `input`[`i`]
else:
for i in 0..<count: result.add quote do: `input`[`i`]
## count == 0 のとき unpackしない(seq)
## count > 0 のとき count個分 unpack した結果の tuple を返す
type UnselectableTypeError = object of Exception
template input*(typ: typedesc; count: Natural = 0): untyped =
let line = stdin.readLine.split
when count == 0:
when typ is int: line.map(parseInt)
elif typ is float: line.map(parseFloat)
elif typ is string: line
else: raise newException(UnselectableTypeError, "You selected a type other than int, float or string")
else:
when typ is int: line.map(parseInt).unpack(count)
elif typ is float: line.map(parseFloat).unpack(count)
elif typ is string: line.unpack(count)
else: raise newException(UnselectableTypeError, "You selected a type other than int, float or string")
template inputs*(typ: typedesc; count = 0; rows = 1): untyped =
(1..rows).mapIt(input(typ, count))
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
template secretEcho*(x: varargs[string, `$`]) =
for v in x:
stderr.write(v)
stderr.writeLine ""
template secretEcho*[T](x: seq[seq[T]]) =
for v in x: secretEcho v
template secretEcho*(x: seq[string]) =
for v in x: secretEcho v
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import tables
from algorithm import nextPermutation, sort
from math import prod
from sequtils import filterIt
let
N = input(int, 1)
S = inputs(string, 1, N)
var ct = initCountTable[char]()
for s in S:
ct.inc(s[0])
var march = initTable[char, int]()
for c in 'A'..'Z':
march[c] = 0
for p in ct.pairs:
march[p[0]] = p[1]
var result = march['M'] * march['A'] * march['R'] +
march['M'] * march['A'] * march['C'] +
march['M'] * march['A'] * march['H'] +
march['M'] * march['R'] * march['C'] +
march['M'] * march['R'] * march['H'] +
march['M'] * march['C'] * march['H'] +
march['A'] * march['R'] * march['C'] +
march['A'] * march['R'] * march['H'] +
march['A'] * march['C'] * march['H'] +
march['R'] * march['C'] * march['H']
echo result
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import numpy as np
N = int(input())
S = np.empty(5, dtype=str)
for i in range(N):
S[i] = input()
S_M = np.array([S[i] for i in range(N) if S[i][0] == 'M'])
S_A = np.array([S[i] for i in range(N) if S[i][0] == 'A'])
S_R = np.array([S[i] for i in range(N) if S[i][0] == 'R'])
S_C = np.array([S[i] for i in range(N) if S[i][0] == 'C'])
S_H = np.array([S[i] for i in range(N) if S[i][0] == 'H'])
souwa = 0
kahi = np.array([0, 0, 0, 0, 0])
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)
kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
print(0)
else:
for i in range(len(kahi_not0)-2):
for j in range(i+1, len(kahi_not0)-1):
for k in range(j+1, len(kahi_not0)):
souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]
if souwa >= 2**32:
print(souwa/(2**32), end='')
print(souwa-(souwa/(2**32))*2**32)
else:
print(souwa) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int N = sc.nextInt();
String[] names = new String[N];
int[] initialCounter = new int[5]; // M A R C H
for (int i = 0; i < names.length; i++) {
names[i] = sc.next();
char initial = names[i].charAt(0);
switch (initial) {
case 'M':
initialCounter[0]++;
break;
case 'A':
initialCounter[1]++;
break;
case 'R':
initialCounter[2]++;
break;
case 'C':
initialCounter[3]++;
break;
case 'H':
initialCounter[4]++;
break;
default:
break;
}
}
long ans = 0;
for (int i = 0; i < initialCounter.length; i++) {
long add = 0;
for (int j = i+1; j < initialCounter.length; j++) {
for (int k = j+1; k < initialCounter.length; k++) {
add = initialCounter[i]*initialCounter[j]*initialCounter[k];
ans+= add;
}
}
}
out.println(ans);
out.close();
}
//-----------http://codeforces.com/blog/entry/7018---------------------------------
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
template<typename ...Ts>
void show(Ts... ts){
cout<<"#:";
auto print=[](auto v){cout<<v<<" ";};
initializer_list<int>{(void(print(ts)),0)...};
cout<<endl;
}
vector<int> subv(vector<int> s,int n,int d){
vector<int> rt;
rep(i,d)rt.push_back(s[n+i]);
return rt;
}
void solve(vector<int> a){
int n=a.size()-2;
int len=0;
rep(i,n+1){
len+=abs(a[i+1]-a[i]);
}
REP(i,1,n+1){
int diff=abs(a[i+1]-a[i-1]) - ( abs(a[i]-a[i-1])+abs(a[i+1]-a[i]) );
cout<<len+diff<<endl;
}
return;
}
int main(void){
int n;
ll ans=0;
string s;
cin>>n;
vector<int> t(5,0);
map<char, ll> mp;
rep(i,n){
cin>>s;
mp[s[0]]++;
}
ll c=0;
for(auto i:"MARCH"){
t[c]=mp[i];
c++;
//cout<<i<<mp[i]<<endl;
}
n=5;
rep(i,n){
//ans+=t[i]*(t[i]-1)*(t[i]-2)/6;
REP(j,i+1,n+1){
//ans+=t[i]*(t[i]-1)*t[j]/3;
REP(k,j+1,n+1){
ans+=t[i]*t[j]*t[k];
}
}
}
cout<<ans<<endl;
//solve(t);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e6 + 10;
int main() {
string str = "MARCH";
int n;
cin >> n;
map<int, int> mc;
while (n--) {
string s;
cin >> s;
if (str.find(s[0]) == str.npos) continue;
mc[s[0]]++;
}
long long ans = 0;
vector<int> v;
for (auto& p : mc) v.push_back(p.second);
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
for (int k = j + 1; k < v.size(); k++) {
ans += v[i] * v[j] * v[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
N = int(input())
members = []
for i in range(N):
member = input()
members.append(member)
members_march = [member for member in members if member[0] in ['M','A','R','C','H'] ]
march_conb = itertools.combinations(members_march,3)
print(len([conb for conb in march_conb if len(set([member[0] for member in conb])) == 3])) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string x = "MARCH";
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> wyst(5, 0);
for (int i = 0; i < n; ++i) {
string im;
cin >> im;
for (int j = 0; j < 5; ++j)
if (x[j] == im[0]) ++wyst[j];
}
long long odp = 0;
for (int i = 0; i < 5; ++i)
for (int j = i + 1; j < 5; ++j)
for (int k = j + 1; k < 5; ++k) odp += wyst[i] * wyst[j] * wyst[k];
cout << odp;
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 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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <typename T>
struct Combination {
vector<T> _fact, _rfact, _inv;
Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
_fact[0] = _rfact[sz] = _inv[0] = 1;
for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
_rfact[sz] /= _fact[sz];
for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
}
inline T fact(int k) const { return _fact[k]; }
inline T rfact(int k) const { return _rfact[k]; }
inline T inv(int k) const { return _inv[k]; }
T P(int n, int r) const {
if (r < 0 || n < r) return 0;
return fact(n) * rfact(n - r);
}
T C(int p, int q) const {
if (q < 0 || p < q) return 0;
return fact(p) * rfact(q) * rfact(p - q);
}
T H(int n, int r) const {
if (n < 0 || r < 0) return (0);
return r == 0 ? 1 : C(n + r - 1, r);
}
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s[n];
int cnt[5];
memset((cnt), 0, sizeof(cnt));
for (long long i = 0; i < (long long)(n); i++) {
cin >> s[i];
if (s[i][0] == 'M')
cnt[0]++;
else if (s[i][0] == 'A')
cnt[1]++;
else if (s[i][0] == 'R')
cnt[2]++;
else if (s[i][0] == 'C')
cnt[3]++;
else if (s[i][0] == 'H')
cnt[4]++;
}
long long ans = 0;
for (long long i = 0; i < (long long)(5); i++)
for (long long j = i + 1; j <= (long long)(4); j++)
for (long long k = j + 1; k <= (long long)(4); k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
template<typename ...Ts>
void show(Ts... ts){
cout<<"#:";
auto print=[](auto v){cout<<v<<" ";};
initializer_list<int>{(void(print(ts)),0)...};
cout<<endl;
}
vector<int> subv(vector<int> s,int n,int d){
vector<int> rt;
rep(i,d)rt.push_back(s[n+i]);
return rt;
}
void solve(vector<int> a){
int n=a.size()-2;
int len=0;
rep(i,n+1){
len+=abs(a[i+1]-a[i]);
}
REP(i,1,n+1){
int diff=abs(a[i+1]-a[i-1]) - ( abs(a[i]-a[i-1])+abs(a[i+1]-a[i]) );
cout<<len+diff<<endl;
}
return;
}
int main(void){
ll n,ans=0;
string s;
cin>>n;
vector<ll> t(5,0);
map<char, ll> mp;
rep(i,n){
cin>>s;
mp[s[0]]++;
}
ll c=0;
for(auto i:"MARCH"){
t[c]=mp[i];
c++;
//cout<<i<<mp[i]<<endl;
}
n=5;
rep(i,n){
//ans+=t[i]*(t[i]-1)*(t[i]-2)/6;
REP(j,i+1,n+1){
//ans+=t[i]*(t[i]-1)*t[j]/3;
REP(k,j+1,n+1){
ans+=t[i]*t[j]*t[k];
}
}
}
cout<<ans<<endl;
//solve(t);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool check(int a, int b) { return a > b; }
int solve(int cnt, int x, int y, vector<int> c, vector<int> s, vector<int> f) {
if (cnt > cnt / f[x] * f[x]) {
cnt = cnt / f[x] * f[x] + f[x];
} else {
cnt = cnt / f[x] * f[x];
}
if (cnt < s[x]) {
cnt = s[x];
}
cnt += c[x];
if (x + 1 == y) {
return cnt;
} else {
return solve(cnt, x + 1, y, c, s, f);
}
}
int main() {
long long int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s.begin(), s.end());
long long int cnt[5] = {};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M' || s[i][0] == 'A' || s[i][0] == 'R' || s[i][0] == 'C' ||
s[i][0] == 'H') {
if (i != 0) {
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
} else {
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
}
}
long long int ans = 0;
long long int tmp;
for (int i = 0; i < 10; i++) {
tmp = 1;
if (i <= 5) {
if (cnt[0] == 0) {
continue;
}
tmp *= cnt[0];
}
if (i <= 2 || 5 <= i && i <= 7) {
if (cnt[1] == 0) {
continue;
}
tmp *= cnt[1];
}
if (i == 0 || i == 3 || i == 4 || 6 <= i && i <= 7 || i == 9) {
if (cnt[2] == 0) {
continue;
}
tmp *= cnt[2];
}
if (i == 1 || i == 3 || i == 5 || i == 6 || i == 8 || i == 9) {
if (cnt[3] == 0) {
continue;
}
tmp *= cnt[3];
}
if (i == 2 || i == 4 || i == 5 || 7 <= i && i <= 9) {
if (cnt[4] == 0) {
continue;
}
tmp *= cnt[4];
}
ans += tmp;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | // not solved by myself
import sun.net.www.content.text.Generic;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.*;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String Ss[] = {"M","A","R","C","H"};
ArrayList<String> targets = new ArrayList<>(Arrays.asList(Ss));
HashMap<Character,Integer> initials = new HashMap<>();
for(int i = 0; i < N; i++){
Character name = sc.next().toCharArray()[0];
if(initials.keySet().contains(name))
initials.put(name,initials.get(name) + 1);
else
initials.put(name,1);
}
int res = 0;
HashSet<ArrayList<String>> combs = new HashSet<>();
combination(targets,3,combs);
for(ArrayList<String> inis: combs){
int tmp = 1;
for(String initial: inis){
if (initials.containsKey(initial.toCharArray()[0]))
tmp *= initials.get(initial.toCharArray()[0]);
else
tmp = 0;
}
res += tmp;
}
System.out.println(res);
}
public static <T> void combination(ArrayList<T> n,Integer r,HashSet<ArrayList<T>> ans){
if (n.size() == r){
ans.add(n);
return;
}
for(int i = 0; i < n.size(); i++){
ArrayList<T> N = new ArrayList<>(n);
N.remove(i);
combination(N,r,ans);
}
}
public static List<Entry<Integer,Integer>> SortMapByValue(HashMap<Integer,Integer> maps,boolean is_reverse){
List<Entry<Integer,Integer>> entries = new ArrayList<>(maps.entrySet());
Collections.sort(entries, new Comparator<Entry<Integer, Integer>>() {
@Override
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
return (is_reverse ? -1 : 1) * o1.getValue().compareTo(o2.getValue());
}
});
return entries;
}
public static long max(int[] ar,int size){
long max = 0;
for(int i = 0; i< size;i++)
if(max < ar[i])
max = ar[i];
return max;
}
public static long max(List<Long> ar){
long max = 0;
for(int i = 0; i< ar.size();i++)
if(max < ar.get(i))
max = ar.get(i);
return max;
}
public static Integer min(List<Integer> ar){
int min = 10000;
int index = 0;
for(int i = 0; i< ar.size();i++){
if(min > ar.get(i)){
min = ar.get(i);
index = i;
}
}
return min;
}
public static long gcd(long m, long n) {
if(m == 0)
return n;
if(n == 0)
return m;
if(m < n) return gcd(n, m);
if(n == 0) return m;
return gcd(n, m % 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 | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
int[] march = new int[5];
String l;
int i;
while(n-- > 0){
l = sc.nextLine();
i = getInd(l.charAt(0));
if(i != -1)
march[i]++;
}
int res = 1;
for(i = 1; i < 5; i++){
if(march[i] > 0)
res = res*march[i];
}
System.out.println(res);
}
private static int getInd(char c){
if(c == 'M')
return 0;
else if(c == 'A')
return 1;
else if(c == 'R')
return 2;
else if(c == 'C')
return 3;
else if(c == 'H')
return 4;
return -1;
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
s = [input() for _ in range(n)]
ans = 0
check_list = ['M','A','R','C','H']
for bit in range(2 ** n):
print(bin(bit))
if bin(bit).count('1') != 3:
continue
mans = []
check = []
for i in range(n):
if bit >> i & 1:
if not s[i][0] in mans and s[i][0] in check_list:
mans.append(s[i][0])
else:
break
if len(mans) == 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 | UNKNOWN | #include <bits/stdc++.h>
int main() {
int N;
scanf("%d", &N);
char head[6] = {'M', 'A', 'R', 'C', 'H'};
int march[5] = {0, 0, 0, 0, 0};
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int i = 0; i < N; i++) {
char S[15];
scanf("%s", S);
for (int j = 0; j < 5; j++) {
if (S[0] == head[j]) march[j]++;
}
}
long long int ans = 0;
for (int i = 0; i < 10; i++) ans += march[P[i]] * march[Q[i]] * march[R[i]];
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;
vector<string> S(N);
for (int i = 0; i < N; ++i) cin >> S[i];
vector<int> num(5, 0);
for (int i = 0; i < N; ++i) {
if (S[i][0] == 'M') num[0]++;
if (S[i][0] == 'A') num[1]++;
if (S[i][0] == 'R') num[2]++;
if (S[i][0] == 'C') num[3]++;
if (S[i][0] == 'H') num[4]++;
}
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 += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
String[] s = new String[n];
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
int[] march = new int[5];
for(int i=0;i<n;i++){
s[i] = sc.next();
if(s[i].charAt(0) == 'M') {m++; march[0]++;}
else if(s[i].charAt(0) == 'A') {a++; march[1]++;}
else if(s[i].charAt(0) == 'R') {r++; march[2]++;}
else if(s[i].charAt(0) == 'C') {c++; march[3]++;}
else if(s[i].charAt(0) == 'H') {h++; march[4]++;}
}
long ans = 0;
for(int i=0; i<n-2; i++) {
for(int j=i+1; j<n-1; j++) {
for(int k=j+1; k<n; k++) {
ans += march[i]*march[j]*march[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 | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
HashMap<Character, HashSet<String>> hashMap = new HashMap<>();
char[] prefixs = new char[5];
prefixs[0] = 'M';
prefixs[1] = 'A';
prefixs[2] = 'R';
prefixs[3] = 'C';
prefixs[4] = 'H';
long ans = 0;
for(int i=0; i<5; i++){
hashMap.put(prefixs[i], new HashSet<>());
}
for(int i=0; i<N; i++){
String S = scanner.next();
char firstChar = S.charAt(0);
if(hashMap.containsKey(firstChar)){
hashMap.get(firstChar).add(S);
}else{
hashMap.put(firstChar, new HashSet<>());
hashMap.get(firstChar).add(S);
}
}
for(int i=0; i<3; i++){
for(int j=i+1; j<4; j++){
for(int k=j+1; k<5; k++){
ans += hashMap.get(prefixs[i]).size() * hashMap.get(prefixs[j]).size() * hashMap.get(prefixs[k]).size();
}
}
}
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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;
#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace competitive_programming
{
public class Program
{
static void Main(string[] args)
{
#if DEBUG
var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open));
#else
var scanner = new IO.StreamScanner(Console.OpenStandardInput());
#endif
var n = scanner.Integer();
var ss = new List<string>();
for (int i = 0; i < n; i++) ss.Add(scanner.ScanLine());
var strsDict = new Dictionary<char, int>();
foreach(var s in ss)
{
if (!"MARCH".Contains(s[0])) continue;
if (!strsDict.ContainsKey(s[0])) strsDict.Add(s[0], 0);
strsDict[s[0]]++;
}
var ret = 0L;
var combi = new List<char[]>();
var array = "MARCH".ToCharArray();
GetPermutation(ref combi, array, 0, array.Length - 1);
var allCombi = new HashSet<string>();
foreach(var c in combi)
{
allCombi.Add(new string(c.Take(3).OrderBy(d => d).ToArray()));
}
foreach(var ptn in allCombi.ToList())
{
if (!strsDict.ContainsKey(ptn[0]) || !strsDict.ContainsKey(ptn[1]) || !strsDict.ContainsKey(ptn[2]))
continue;
ret += (strsDict[ptn[0]] * strsDict[ptn[1]] * strsDict[ptn[2]]);
}
IO.Printer.Out.WriteLine(ret);
IO.Printer.Out.Flush();
}
static public void GetPermutation<T>(ref List<T[]> ret, T[] arry, int i, int n)
{
int j;
if (i == n)
ret.Add(new List<T>(arry).ToArray());
else
{
for (j = i; j <= n; j++)
{
Swap(ref arry[i], ref arry[j]);
GetPermutation(ref ret, arry, i + 1, n);
Swap(ref arry[i], ref arry[j]); //backtrack
}
}
}
static public void Swap<T>(ref T a, ref T b)
{
T tmp;
tmp = a;
a = b;
b = tmp;
}
// m種類から重複なくn個を選ぶ組み合わせ
public static Int64 GetMcn(int m, int n)
{
Int64 val;
if (m < n) return 0;
n = Math.Min(n, m - n);
if (n == 0) val = 1;
else val = GetMcn(m - 1, n - 1) * m / n;
return val;
}
}
}
#if DEBUG
#endif
#region INOUT
namespace IO
{
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter
{
static Printer()
{
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
}
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider
{
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true))
{
}
public Printer(Stream stream, Encoding encoding)
: base(stream, encoding)
{
}
public void Write<T>(string format, T[] source)
{
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source)
{
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
public class StreamScanner
{
public StreamScanner(Stream stream)
{
str = stream;
}
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream
{
get { return isEof; }
}
private byte read()
{
if (isEof) return 0;
if (ptr < len) return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++];
isEof = true;
return 0;
}
public char Char()
{
byte b;
do b = read(); while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan()
{
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine()
{
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0) break;
else if (b != '\r') sb.Append(b);
return sb.ToString();
}
public long Long()
{
if (isEof) return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0) return long.MinValue;
if (b == '-')
{
ng = true;
b = read();
}
for (; ; b = read())
{
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer()
{
return (isEof) ? int.MinValue : (int)Long();
}
public double Double()
{
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f)
{
var a = new T[n];
for (int i = 0; i < n; ++i) a[i] = f();
return a;
}
public char[] Char(int n)
{
return enumerate(n, Char);
}
public string[] Scan(int n)
{
return enumerate(n, Scan);
}
public double[] Double(int n)
{
return enumerate(n, Double);
}
public int[] Integer(int n)
{
return enumerate(n, Integer);
}
public long[] Long(int n)
{
return enumerate(n, Long);
}
}
}
#endregion |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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>
#pragma warning(disable : 4996)
int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);
int _gcd(int a, int b);
int _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b) {
return (strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
return (strcmp((char*)b, (char*)a));
}
int i_dsort(const void* a, const void* b) { return (*(int*)b - *(int*)a); }
int i_asort(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int i_gcd(int a, int b);
int i_gcd(int a, int b) {
if (!b) return a;
return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) { return (a * b) / i_gcd(a, b); }
int ll_gcd(long long a, long long b);
int ll_gcd(long long a, long long b) {
if (!b) return a;
return ll_gcd(b, a % b);
}
int ll_lcm(long long a, long long b);
int ll_lcm(long long a, long long b) { return (a * b) / ll_gcd(a, b); }
int _swp(int* a, int* b) {
int tmp;
tmp = *b;
*b = *a;
*a = tmp;
return 0;
}
int _cknum(char* a, int n) {
int i;
char t = '0';
for (i = 0; i < n; i++) {
if (a[i] < '0' || a[i] > '9') return 1;
}
return 0;
}
int _atoi(char* s, int len) {
char tmp[20];
memcpy(tmp, s, len);
tmp[len] = 0x00;
return (atoi(tmp));
}
long long _pfact(long long a);
static long long pf[100000000];
static long long pc;
long long _pfact(long long a) {
long i, r;
if (a % 2 == 0) {
pf[pc] = 2;
pc++;
return (_pfact(a / 2));
}
r = sqrt(a);
for (i = 3; i <= r; i += 2) {
if (a % i == 0) {
pf[pc] = i;
pc++;
return (_pfact(a / i));
}
}
if (a != 1) {
pf[pc] = a;
pc++;
}
return 0;
}
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
char rc;
rc = strcmp((char*)b, (char*)a);
if (rc == 0) {
*(char*)a = 0x00;
return (1);
}
return (rc);
}
static int a[5];
int main(void) {
long long cnt;
int n, i;
char s[11];
int fa[5] = {0, 0, 0, 0, 0};
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
a[0]++;
fa[0] = 1;
break;
case 'A':
a[1]++;
fa[1] = 1;
break;
case 'R':
a[2]++;
fa[2] = 1;
break;
case 'C':
a[3]++;
fa[3] = 1;
break;
case 'H':
a[4]++;
fa[4] = 1;
break;
default:
break;
}
}
int f = fa[0] + fa[1] + fa[2] + fa[3] + fa[4];
if (f < 3) {
printf("0\n");
return 0;
}
long long ans = 0;
ans = f * (f - 1) * (f - 2) / (1 * 2 * 3);
for (i = 0; i < 5; i++) {
if (a[i] <= 1) continue;
ans = ans + ((long long)a[i] - 1) * ((f - 1) * (f - 2) / (1 * 2));
}
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char s[1000];
int main() {
long m, a, r, c, h, i, n, sum = 0;
scanf("%ld", &n);
for (i = 1; i <= n; i++) {
scanf("%s", s);
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
sum = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * c * h + r * c * h + a * r * h;
printf("%ld", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string temp;
char cc;
int m, a, r, c, h;
m = a = r = c = h = 0;
for (int i = 0; i < N; i++) {
cin >> temp;
cc = temp[0];
if (cc == 'M')
m++;
else if (cc == 'A')
a++;
else if (cc == 'R')
r++;
else if (cc == 'C')
c++;
else if (cc == 'H')
h++;
}
int count = 0;
count += m * a * r;
count += m * a * c;
count += m * a * h;
count += m * r * c;
count += m * r * h;
count += m * c * h;
count += a * r * c;
count += a * r * h;
count += a * c * h;
count += r * c * h;
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N;
int march[5];
char pattern[5] = {'M', 'A', 'R', 'C', 'H'};
vector<int> perm = {0, 1, 2, 3, 4};
long long ans = 0;
int main() {
cin >> N;
for (int i = 0; i < N; ++i) {
string S;
cin >> S;
for (int i = 0; i < 5; ++i) {
if (S[0] == pattern[i]) {
++march[i];
}
}
}
for (int a = 0; a < 5; ++a) {
for (int b = a + 1; b < 5; ++b) {
for (int c = b + 1; c < 5; ++c) {
ans += march[a] * march[b] * march[c];
}
}
}
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;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n;
cin >> n;
long long c[5] = {};
for (int i = 0, i_len = (n); i < i_len; ++i) {
string s;
cin >> s;
switch (s[0]) {
case 'M':
c[0]++;
break;
case 'A':
c[1]++;
break;
case 'R':
c[2]++;
break;
case 'C':
c[3]++;
break;
case 'H':
c[4]++;
break;
}
}
long long ans = 0;
ans += c[0] * c[1] * c[2];
ans += c[0] * c[1] * c[3];
ans += c[0] * c[1] * c[4];
ans += c[0] * c[2] * c[3];
ans += c[0] * c[2] * c[4];
ans += c[1] * c[2] * c[3];
ans += c[1] * c[2] * c[4];
ans += c[2] * c[3] * c[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
char s[100000][11];
int i, n;
int h[5] = {0};
int x;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", s[i]);
switch (s[i][0]) {
case 'M':
h[0]++;
break;
case 'A':
h[1]++;
break;
case 'R':
h[2]++;
break;
case 'C':
h[3]++;
break;
case 'H':
h[4]++;
break;
}
}
x = h[0] * h[1] * h[2];
x += h[0] * h[1] * h[3];
x += h[0] * h[1] * h[4];
x += h[0] * h[2] * h[3];
x += h[0] * h[2] * h[4];
x += h[0] * h[3] * h[4];
x += h[1] * h[2] * h[3];
x += h[1] * h[2] * h[4];
x += h[1] * h[3] * h[4];
x += h[2] * h[3] * h[4];
printf("%d\n", x);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
set<int> st;
int n;
vector<string> s(100005);
queue<int> num;
long long cntm = 0, cnta = 0, cntr = 0, cntc = 0, cnth = 0, ans = 0;
vector<int> a(105, 0);
vector<int> b(105, 0);
int main(int argc, char const* argv[]) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') cntm++;
if (s[i][0] == 'A') cnta++;
if (s[i][0] == 'R') cntr++;
if (s[i][0] == 'C') cntc++;
if (s[i][0] == 'H') cnth++;
}
ans += (cntm * cnta * cntr);
ans += (cntm * cnta * cntc);
ans += (cntm * cnta * cnth);
ans += (cntm * cntr * cntc);
ans += (cntm * cntr * cnth);
ans += (cntm * cntc * cnth);
ans += (cnta * cntr * cntc);
ans += (cntm * cnta * cnth);
ans += (cnta * cntc * cnth);
ans += (cntr * cntc * cnth);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N;
int M=0,A=0,R=0,C=0,H=0;
N = sc.nextInt();
ArrayList<String> List = new ArrayList<String>();
for (int a = 0; a < N; a++) {
String name = sc.next();
if(name.indexOf("M")==0){
M++;
}
else if(name.indexOf("A")==0){
A++;
}
else if(name.indexOf("R")==0){
R++;
}
else if(name.indexOf("C")==0){
C++;
}
else if(name.indexOf("H")==0){
H++;
}
}
int num = M*A*R*C*H;
int num2 = num/M;
num2 = num2/A;
num2 = num2/R;
num2= num2/C;
num2 = num2/H;
System.out.println(num2);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<char, int> Head{
{'M', 0}, {'A', 0}, {'R', 0}, {'C', 0}, {'H', 0},
};
for (int i = 0; i < N; i++) {
string S;
cin >> S;
Head[S[0]]++;
}
long long int ans = 0;
vector<int> Human(5);
Human[0] = Head['M'], Human[1] = Head['A'], Human[2] = Head['R'],
Human[3] = Head['C'], Human[4] = Head['H'];
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
for (int k = j + 1; k < N; k++) {
ans += (Human[i] * Human[j] * Human[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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main(void)
{
int N;
std::cin >> N;
std::vector<std::string> S;
for(int i=0;i<N;i++)
{
std::string a;
std::cin >> a;
S.push_back(a);
}
int m=0,a=0,r=0,c=0,h=0;
for(int i=0;i<N;i++)
{
if(S[i][0] == 'M'){
m = 1;
}
else if(S[i][0] == 'A'){
a = 1;
}
else if(S[i][0] == 'R'){
r = 1;
}
else if(S[i][0] == 'C'){
c = 1;
}
else if(S[i][0] == 'H'){
h = 1;
}
}
int x;
x = m + a + r + c + h;
if(x >=3){
std::cout << (x*(x-1)*(x-2))/6 << std::endl;
}
else{
std::cout << 0 << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N;
map<char, int> S;
vector<char> H = {'M', 'A', 'R', 'C', 'H'};
vector<string> H_COMB = {"MAR", "MAC", "MAH", "MRC", "MRH",
"MCH", "ARC", "ARH", "ACH", "RCH"};
long ans;
void solve() {
if (S.size() < 3)
ans = 0;
else {
for (string h : H_COMB) {
ans += S[h[0]] * S[h[1]] * S[h[2]];
}
}
cout << ans << endl;
}
int main() {
cin >> N;
for (int i = 0; i < N; ++i) {
string str;
cin >> str;
for (char h : H) {
if (h == str[0]) {
++S[h];
break;
}
}
}
solve();
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int n;
string s[100005];
char march[] = {'M', 'A', 'R', 'C', 'H'};
int cnt[5];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < (n); ++i) {
cin >> s[i];
for (int j = 0; j < (5); ++j) {
if (march[j] == s[i][0]) cnt[j]++;
}
}
long long ans = 0;
int a = cnt[0], b = cnt[1], c = cnt[2], d = cnt[3], e = cnt[4];
ans = a * b * (c + d + e) + a * c * (d + e) + a * d * e + b * c * (d + e) +
b * d * e + c * d * e;
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
string s, init = "MARCH";
int main() {
cin >> N;
map<char, int> num;
for (int i = 0; i < (N); ++i) cin >> s, num[s[0]]++;
ll ans = 0;
for (int i = 0; i <= (4); ++i)
for (int j = i + 1; j <= (4); ++j)
for (int k = j + 1; k <= (4); ++k)
ans += num[init[i]] * num[init[j]] * num[init[k]];
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 | UNKNOWN | macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
let mut next = || { iter.next().unwrap() };
input_inner!{next, $($r)*}
};
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes
.by_ref()
.map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr, ) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, ( $($t:tt),* )) => {
( $(read_value!($next, $t)),* )
};
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, usize1) => {
read_value!($next, usize) - 1
};
($next:expr, $t:ty) => {
$next().parse::<$t>().expect("Parse error")
};
}
use std::cmp::max;
use std::collections::HashMap;
fn main(){
input!{
n:usize,
sn:[chars;n],
}
let master = vec!['M','A','R','C','H'];
let mut map = HashMap::new();
for s in sn {
*map.entry(s[0]).or_insert(0) += 1;
}
let mut ans = 0;
for bit in 0usize..1 << 5 {
if bit.count_ones() != 3 {
continue;
}
let mut sub = 1;
for j in 0..5 {
if bit&(1<<j) != 0 {
sub *= map.get(&master[j]).cloned().unwrap_or(0);
}
}
ans += sub;
}
println!("{}",ans);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
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;
switch (s[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
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
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct edge {
int to, cost;
};
const int INF = 100000000;
int main() {
int n, num[10] = {}, ans = 0;
cin >> n;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
num[0]++;
} else if (s[0] == 'A') {
num[1]++;
} else if (s[0] == 'R') {
num[2]++;
} else if (s[0] == 'C') {
num[3]++;
} else if (s[0] == 'H') {
num[4]++;
}
}
for (int Bit = 0; Bit < (1 << 5); Bit++) {
int e = 1, count = 0;
bitset<5> b(Bit);
for (int i = 0; i < (5); i++) {
if (b[i] == 1) {
count++;
e *= num[i];
}
}
if (count == 3) {
{} {}
ans += e;
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, count[5], ans = 0;
string s;
for (int i = 0; i < 5; i++) count[i] = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') count[0]++;
if (s[0] == 'A') count[1]++;
if (s[0] == 'R') count[2]++;
if (s[0] == 'C') count[3]++;
if (s[0] == 'H') count[4]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <stdio.h>
int main(){
unsigned long n;
scanf("%lu¥n",&n);
unsigned long m=0;
unsigned long r=0;
unsigned long c=0;
unsigned long a=0;
unsigned long h=0;
for(unsigned long i = 0;i<n;i++){
char str[64];
scanf("%s¥n",&str);
if(str[0] == "M"){m++;}
if(str[0] == "C"){c++;}
if(str[0] == "A"){a++;}
if(str[0] == "R"){r++;}
if(str[0] == "H"){h++;}
}
unsigned long ans=0;
ans = (m+c+a+r+h)*(m+c+a+r+h)*(m+c+a+r+h);
ans -= (m+c+a+r+h)*3*a*a-2*a*a*a;
ans -= (m+c+a+r+h)*3*m*m-2*m*m*m;
ans -= (m+c+a+r+h)*3*h*h-2*h*h*h;
ans -= (m+c+a+r+h)*3*r*r-2*r*r*r;
ans -= (m+c+a+r+h)*3*c*c-2*c*c*c;
printf("%lu",ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n=int(input())
M=set();A=set();R=set();C=set();H=set()
for i in range(n):
a=input()
if a.startswith("M"):
M.add(a)
elif a.startswith("A"):
A.add(a)
elif a.startswith("R"):
R.add(a)
elif a.startswith("C"):
C.add(a)
elif a.startswith("H"):
H.add(a)
m=len(M);a=len(A);r=len(R);c=len(C);h=len(H)
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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;
for (int i = 0; i < n; i++) {
cin >> s;
switch (s[0]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
H++;
break;
default:
break;
}
}
unsigned int a =
3 * 2 * 1 * M * A * R + 3 * 2 * 1 * M * A * C + 3 * 2 * 1 * M * A * H +
3 * 2 * 1 * M * R * C + 3 * 2 * 1 * M * R * H + 3 * 2 * 1 * A * R * C +
3 * 2 * 1 * A * R * H + 3 * 2 * 1 * A * C * H + 3 * 2 * 1 * R * C * H;
cout << a << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] a = new long[5];
long total = 0;
for (int i = 0; i < n; i++) {
char s = sc.next().charAt(0);
switch (s) {
case 'M':
a[0]++;
total++;
break;
case 'A':
a[1]++;
total++;
break;
case 'R':
a[2]++;
total++;
break;
case 'C':
a[3]++;
total++;
break;
case 'H':
a[4]++;
total++;
break;
}
}
if (total < 3) {
System.out.println("0");
return;
}
long x = combination(total, 3);
long y = 0;
for (int i = 0; i < 5; i++) {
if (a[i] > 1) {
y += combination(a[i], 2) * total - a[i];
}
}
System.out.println(x - y);
}
private static long factorial(long x) {
long f = 1;
while(x > 0) {
f *= x;
x -= 1;
}
return f;
}
private static long combination(long n, long r) {
return factorial(n) / (factorial(n - r) * factorial(r));
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
void recursive_comb(int *indexes, int s, int rest,
std::function<void(int *)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
void foreach_comb(int n, int k, std::function<void(int *)> f) {
int indexes[k];
recursive_comb(indexes, n - 1, k, f);
}
int name[5];
int pat[10][3] = {{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}, {0, 1, 4},
{0, 2, 4}, {1, 2, 4}, {0, 3, 4}, {1, 3, 4}, {2, 3, 4}};
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
name[0]++;
else if (s[0] == 'A')
name[1]++;
else if (s[0] == 'R')
name[2]++;
else if (s[0] == 'C')
name[3]++;
else if (s[0] == 'H')
name[4]++;
}
long long ans = 0;
for (int i = 0; i < 10; i++) {
int p = pat[i][0];
int q = pat[i][1];
int r = pat[i][2];
ans += name[p] * name[q] * name[r];
}
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 s[] = {'M', 'A', 'R', 'C', 'H'};
int c[5] = {0};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string t;
cin >> t;
for (int j = 0; j < 5; j++) {
if (t[0] == s[j]) {
c[j]++;
}
}
}
int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | n = gets.to_i
arr = []
n.times{arr << gets.chomp}
arr = arr.map{|x| x[0]}.uniq
if arr.size<=2
puts 0
elsif arr.size==3
puts 1
elsif arr.size==4
puts 4
elsif arr.size==5
puts 10
end |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
String[] strArr = new String[N];
int x = 0;
for (int i = 0; i < N; i++) {
strArr[i] = s.next();
}
for (int i = 0; i < N - 2; i++) {
if (strArr[i].charAt(0)=='M'
|| strArr[i].charAt(0)=='A'
|| strArr[i].charAt(0)=='R'
|| strArr[i].charAt(0)=='C'
|| strArr[i].charAt(0)=='H') {
for (int j = i + 1; j < N - 1; j++) {
if (strArr[j].charAt(0)=='M'
|| strArr[j].charAt(0)=='A'
|| strArr[j].charAt(0)=='R'
|| strArr[j].charAt(0)=='C'
|| strArr[j].charAt(0)=='H') {
for (int k = j + 1; k < N; k++) {
if (strArr[k].charAt(0)=='M'
|| strArr[k].charAt(0)=='A'
|| strArr[k].charAt(0)=='R'
|| strArr[k].charAt(0)=='C'
|| strArr[k].charAt(0)=='H') {
if (strArr[i].charAt(0)==(strArr[j].charAt(0))
|| strArr[i].charAt(0)==(strArr[k].charAt(0))
|| strArr[j].charAt(0)==(strArr[k].charAt(0))) {
}else{
x++;
}
}
}
}
}
}
}
System.out.println(x);
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.