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;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "[";
for (auto vv : v) os << vv << ",";
return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> v) {
os << "[";
for (auto vv : v) os << vv << ",";
return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
T sq(T a) {
return a * a;
}
template <typename T>
T gcd(T a, T b) {
if (a > b) return gcd(b, a);
return a == 0 ? b : gcd(b % a, a);
}
template <typename T, typename U>
T mypow(T b, U n) {
if (n == 0) return 1;
if (n == 1) return b;
if (n % 2 == 0) {
return mypow(b * b, n / 2);
} else {
return mypow(b, n - 1) * b;
}
}
ll pcnt(ll b) { return __builtin_popcountll(b); }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
const string march = "MARCH";
int cnt[5];
int N;
cin >> N;
for (ll i = (0); i < (N); i++) {
string S;
cin >> S;
if (S[0] == march[i]) cnt[i]++;
}
ll ans = 0;
for (ll i = (0); i < (3); i++) {
for (ll j = (i + 1); j < (4); j++) {
for (ll k = (j + 1); k < (5); k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T1, typename T2>
using P = pair<T1, T2>;
using Pii = P<int, int>;
using Pdd = P<double, double>;
template <typename T>
using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;
template <typename T1, typename T2>
using M = map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;
const int MOD = 1000000007;
const int INF = 1999999999;
const LL INFLL = 999999999999999LL;
const double EPS = 1e-10;
const int DX[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int DY[8] = {0, -1, 0, 1, -1, 1, 1, -1};
const double PI = 3.141592653589793;
void SCAN(int *a) { scanf("%d", a); }
void SCAN(int *a, int n) {
for (int(i) = 0; (i) < (n); (i)++) {
scanf("%d", &a[i]);
}
}
void SCAN(Pii *a) {
scanf("%d", &a->first);
scanf("%d", &a->second);
}
void SCAN(LL *a) { scanf("%lld", a); }
void SCAN(LL *a, int n) {
for (int(i) = 0; (i) < (n); (i)++) {
scanf("%lld", &a[i]);
}
}
void SCAN(char *c) { scanf(" %c", c); }
void SCAN(char *c, int n) {
for (int(i) = 0; (i) < (n); (i)++) {
scanf(" %c", &c[i]);
}
}
void PRINT(int a) { printf("%d\n", a); }
void PRINT(int *a, int s, char c = '\n') {
for (int(i) = 0; (i) < (s); (i)++) {
if (i == s - 1) {
c = '\n';
}
printf("%d%c", a[i], c);
}
}
void PRINT(Vi a, char c = '\n') {
for (int(i) = 0; (i) < (a.size()); (i)++) {
if (i == a.size() - 1) {
c = '\n';
}
printf("%d%c", a[i], c);
}
}
void PRINT(LL a) { printf("%lld\n", a); }
void PRINT(LL *a, int s, char c = '\n') {
for (int(i) = 0; (i) < (s); (i)++) {
if (i == s - 1) {
c = '\n';
}
printf("%lld%c", a[i], c);
}
}
void PRINT(double a) { printf("%.15f\n", a); }
void PRINT(double *a, int s, char c = '\n') {
for (int(i) = 0; (i) < (s); (i)++) {
if (i == s - 1) {
c = '\n';
}
printf("%f%c", a[i], c);
}
}
void PRINT(char a) { printf("%c\n", a); }
void PRINT(string a) { printf("%s\n", a.c_str()); }
template <typename A>
void UNIQUE(vector<A> &a, int mode = 0) {
if (mode == 0) {
sort((a).begin(), (a).end(), greater<A>());
} else {
sort((a).begin(), (a).end());
}
a.erase(unique((a).begin(), (a).end()), a.end());
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
template <typename T>
int sgn(T val) {
return (T(0) < val) - (val < T(0));
}
LL pascalTri(LL n, LL r) {
LL tri[n + 1][n + 1];
for (int(i) = 0; (i) < (n + 1); (i)++) {
for (int(j) = 0; (j) < (n + 1); (j)++) {
tri[i][j] = 0;
}
}
for (int(i) = 0; (i) < (n + 1); (i)++) {
for (int(j) = 0; (j) < (n + 1); (j)++) {
if (j > i) {
break;
}
if (j == 0 || j == i) {
tri[i][j] = 1;
} else {
tri[i][j] = (tri[i - 1][j - 1] + tri[i - 1][j]);
}
}
}
return tri[n][r];
}
LL GCD(LL a, LL b) {
LL t;
LL r;
if (a < b) {
t = a;
a = b;
b = t;
}
if (b == 0) {
return a;
}
while (a % b != 0) {
r = a % b;
a = b;
b = r;
}
return b;
}
LL LCM(LL a, LL b) {
LL ab = (a * b) % MOD;
return ab / GCD(a % b, b);
}
LL BMPow(int x, int n, int m = 0) {
LL ans = 1;
LL p = x;
if (m == 0) {
while (n > 0) {
if (n & 1 == 1) {
ans *= p;
}
p *= p;
n >>= 1;
}
} else {
while (n > 0) {
if (n & 1 == 1) {
ans = (ans * p) % m;
}
p = (p * p) % m;
n >>= 1;
}
}
return ans;
}
LL modInv(LL x, int m) { return BMPow(x, m - 2, m); }
LL factorial(int x, int m = 0) {
LL a = 1;
if (m == 0) {
for (int(i) = (x); (i) >= (1); (i)--) {
a *= i;
}
} else {
for (int(i) = (x); (i) >= (1); (i)--) {
a = (a * i) % m;
}
}
return a;
}
P<Vll, Vll> primeFactor(LL n) {
Vll p, e;
LL m = n;
int c;
for (LL i = 2; i * i <= n; i++) {
if (m % i != 0) {
continue;
}
c = 0;
while (m % i == 0) {
c++;
m /= i;
}
p.push_back(i);
e.push_back(c);
}
if (m > 1) {
p.push_back(m);
e.push_back(1);
}
return make_pair(p, e);
}
template <typename T>
using coordinate = P<T, T>;
template <typename T>
using coordinateSet = V<coordinate<T>>;
template <typename T>
coordinate<double> centroidPolygon(coordinateSet<T> &a) {
coordinate<double> G;
G.first = 0.;
G.second = 0.;
int n = a.size();
for (auto &(i) : a) {
G.first += i.first;
G.second += i.second;
}
G.first /= n;
G.second /= n;
return G;
}
double area(coordinate<int> a, coordinate<int> b, coordinate<int> c) {
return ((b.first - a.first) * (c.second - a.second) -
(b.second - a.second) * (c.first - a.first)) /
2.;
}
int checkCross(coordinate<int> v1, coordinate<int> v2, coordinate<int> a,
coordinate<int> b) {
if (area(a, b, v1) * area(a, b, v2) >= 0) {
return 0;
}
if (area(v1, v2, a) * area(v1, v2, b) >= 0) {
return 0;
}
return 1;
}
struct edge {
int src;
int dst;
int weight;
edge() : src(0), dst(0), weight(0) {}
edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using edges = V<edge>;
using graph = V<edges>;
void add_edge(edges &g, int s, int d, int w = 1) { g.push_back(edge(s, d, w)); }
void add_edge(graph &g, int s, int d, int w = 1) {
g[s].push_back(edge(s, d, w));
}
V<Vi> floyd(const graph &g) {
int i, j, k;
int n = g.size();
V<Vi> dist(n, Vi(n, INF / 2));
for (int(i) = 0; (i) < (n); (i)++) {
dist[i][i] = 0;
}
for (int(i) = 0; (i) < (n); (i)++) {
for (auto &e : g[i]) {
dist[e.src][e.dst] = e.weight;
}
}
for (int(k) = 0; (k) < (n); (k)++) {
for (int(i) = 0; (i) < (n); (i)++) {
for (int(j) = 0; (j) < (n); (j)++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
return dist;
}
Vi dijkstra(graph &g, int s) {
int i, j, k;
int n = g.size();
int visit[n];
Vi dist(n);
priority_queue<Pii, V<Pii>, greater<Pii>> q;
for (int(i) = 0; (i) < (n); (i)++) {
visit[i] = 0;
dist[i] = INF / 2;
}
dist[s] = 0;
q.push(make_pair(0, s));
int nv;
int min_cost = 0;
while (!q.empty()) {
int d, t;
tie(d, t) = q.top();
q.pop();
if (visit[t] == 1) {
continue;
}
visit[t] = 1;
dist[t] = d;
for (auto &e : g[t]) {
if (dist[e.dst] <= d + e.weight) {
continue;
}
q.push(make_pair(d + e.weight, e.dst));
}
}
return dist;
}
template <typename T>
struct binaryIndexedTree {
private:
int n;
V<T> x;
public:
binaryIndexedTree(int num = 0) : n(num), x(n, 0) {}
void add(int a, T w) {
for (int i = a; i < n; i |= i + 1) {
if (x[i] < w) {
x[i] = w;
}
}
}
T maximum(int a) {
T m = -1;
for (int k = a - 1; k >= 0; k = (k & (k + 1)) - 1) {
m = max(m, x[k]);
}
return m;
}
};
struct unionFind {
private:
Vi data;
public:
unionFind(int size) : data(size, -1) {}
bool unionSet(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x]) {
swap(x, y);
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return ((data[x] < 0) ? x : (data[x] = root(data[x]))); }
int size(int x) { return -data[root(x)]; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL n;
cin >> n;
string s;
string m = "MARCH";
M<char, int> ss;
for (int(i) = 0; (i) < (n); (i)++) {
cin >> s;
ss[s[0]]++;
}
LL a = 0;
for (int(i) = 0; (i) < (m.size()); (i)++) {
a += ss[m[i]];
}
if (a == 0) {
cout << 0 << endl;
return 0;
}
LL ans = pascalTri(a, 3);
for (int(i) = 0; (i) < (m.size()); (i)++) {
if (ss[m[i]] <= 1) {
continue;
}
ans -= pascalTri(ss[m[i]], 2) * pascalTri(a - ss[m[i]], 1);
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
using namespace std;
int main(){
int N;
cin >> N;
char a[100000][11];
for(int i=0;i<N;i++){
cin >> a[i];
}
int m=0,a=0,r=0,c=0,h=0;
for(int i=0;i<N;i++){
switch(a[i][1]){
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*c*h+0;
cout << ans;
return 0
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string str;
long long num[5];
for (int i = 0; i < (5); ++i) {
num[i] = 0;
}
for (int i = 0; i != N; ++i) {
cin >> str;
switch (str[0]) {
case 'M':
num[0]++;
break;
case 'A':
num[1]++;
break;
case 'R':
num[2]++;
break;
case 'C':
num[3]++;
break;
case 'H':
num[4]++;
break;
}
}
long long ans = 0;
for (int i = 0; i <= 2; ++i) {
for (int j = i + 1; j <= 3; ++j) {
for (int k = j + 1; k <= 4; ++k) {
cout << "num[" << i << "]:" << num[i] << " num[" << j << "]:" << num[j]
<< " num[" << k << "]:" << num[k] << ":"
<< num[i] * num[j] * num[k] << endl;
ans += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
const int M = 0;
const int A = 1;
const int R = 2;
const int C = 3;
const int H = 4;
vector<int> counts(5);
for (int i = 0; i < N; i++) {
string name;
cin >> name;
if (name.at(0) == 'M') {
counts.at(M)++;
} else if (name.at(0) == 'A') {
counts.at(A)++;
} else if (name.at(0) == 'R') {
counts.at(R)++;
} else if (name.at(0) == 'C') {
counts.at(C)++;
} else if (name.at(0) == 'H') {
counts.at(H)++;
}
}
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 += counts.at(i) * counts.at(j) * counts.at(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;
long long march[6];
int main() {
long long n, sum = 0;
map<string, int> mp;
map<string, int>::iterator iter;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
mp[s] = 1;
}
for (iter = mp.begin(); iter != mp.end(); iter++) {
string s = iter->first;
if (s[0] == 'M')
march[1]++;
else if (s[0] == 'A')
march[2]++;
else if (s[0] == 'R')
march[3]++;
else if (s[0] == 'C')
march[4]++;
else if (s[0] == 'H')
march[5]++;
}
for (int j = 1; j <= 5; j++)
if (march[j] > 0) sum++;
if (sum < 3)
cout << 0 << endl;
else {
long long ans = 1;
for (int j = 1; j <= 5; j++)
if (march[j] > 0) ans *= march[j];
if (sum == 3)
cout << ans << endl;
else if (sum == 4) {
long long num = 0;
for (int j = 1; j <= 5; j++)
if (march[j] > 0) num += (ans / march[j]);
cout << num << endl;
} else if (sum == 5) {
long long num = 0;
for (int j = 1; j <= 5; j++) {
for (int k = j + 1; k <= 5; k++) num += (ans / (march[j] * march[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;
int main() {
int N;
long 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') {
data.push_back(temp);
}
}
if (data.size() < 3) {
cout << counter << endl;
return 0;
}
for (vector<string>::size_type i = 0; i < data.size() - 2; i++) {
for (vector<string>::size_type j = i + 1; j < data.size() - 1; j++) {
for (vector<string>::size_type k = j + 1; k < data.size(); k++) {
if (data[i][0] != data[j][0] && data[k][0] != data[j][0] &&
data[i][0] != data[k][0]) {
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 | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int n;
char s[100000][11];
long long ans = 0;
int a[5];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", 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]++;
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
if (i != j && i != k && j != k) ans += a[i] * a[j] * a[k];
}
}
}
printf("%lld\n", ans / 6);
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;
#pragma GCC optimize(3)
template <class T>
inline T min(T &x, const T &y) {
return x > y ? y : x;
}
template <class T>
inline T max(T &x, const T &y) {
return x < y ? y : x;
}
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
struct ios {
inline char gc() {
static const int IN_LEN = 1 << 18 | 1;
static char buf[IN_LEN], *s, *t;
return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)),
s == t ? -1 : *s++;
}
template <typename _Tp>
inline ios &operator>>(_Tp &x) {
static char ch, sgn;
ch = gc(), sgn = 0;
for (; !isdigit(ch); ch = gc()) {
if (ch == -1) return *this;
sgn |= ch == '-';
}
for (x = 0; isdigit(ch); ch = gc()) x = (((x << 2) + x) << 1) + (ch ^ '0');
sgn && (x = -x);
return *this;
}
} io;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
int n;
int a[6];
long long ans;
string s;
int main() {
n = read();
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
++a[1];
else if (s[0] == 'A')
++a[2];
else if (s[0] == 'R')
++a[3];
else if (s[0] == 'C')
++a[4];
else if (s[0] == 'H')
++a[5];
}
ans += a[1] * a[2] * a[3];
ans += a[1] * a[2] * a[4];
ans += a[1] * a[2] * a[5];
ans += a[1] * a[3] * a[4];
ans += a[1] * a[3] * a[5];
ans += a[1] * a[4] * a[5];
ans += a[2] * a[3] * a[4];
ans += a[2] * a[3] * a[5];
ans += a[3] * a[4] * a[5];
ans += a[2] * a[4] * a[5];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main() {
int N;
cin >> N;
string s;
long long m, a, r, c, h;
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;
}
long long D[5];
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]];
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import java.io.PrintWriter
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)
val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)
fun main(args: Array<String>) {
main()
pw.flush()
}
fun main() {
val N = nextInt()
val S = CharArray(N) {
next()[0]
}
val T = S.filter { "MARCH".contains(it) }.groupBy { it }.map { it.value.size }
var ans = 0
for (i in 0 until T.size) {
for (j in i + 1 until T.size) {
for (k in j + 1 until T.size) {
ans += T[i] * T[j] * T[k]
}
}
}
println(ans)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
int guki(int a) {
if (a % 2 == 0)
return 0;
else
return 1;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) {
int x = gcd(a, b);
return (a * b / x);
}
using namespace std;
int main() {
bool fl[5];
int n, ans = 0, x, f;
cin >> n;
string S;
map<char, int> mp;
char X[5] = {'M', 'A', 'C', 'R', 'H'};
for (int i = (int)(0); i < (int)(n); ++i) {
cin >> S;
mp[S[0]]++;
}
for (int i = 0; i <= 3; i++) {
for (int j = i + 1; j <= 4; j++) {
for (int k = (int)(0); k < (int)(5); ++k) fl[k] = 1;
fl[i] = false;
fl[j] = false;
x = 1;
f = 0;
for (int k = (int)(0); k < (int)(5); ++k) {
if (fl[k]) x *= mp[X[k]];
}
ans += x;
}
}
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 | // SeeAlso: https://atcoder.jp/contests/abc089/tasks/abc089_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MAX 100000
typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
int n;
int main() {
cin >> n;
int m,a,r,c,h;
REP(i, n) {
string s;
cin >> s;
if(s[0]=='M')m++;
if(s[0]=='A')a++;
if(s[0]=='R')r++;
if(s[0]=='C')c++;
if(s[0]=='H')h++;
}
int d[5];
d[0]=m;
d[1]=a;
d[2]=r;
d[3]=c;
d[4]=h;
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 z[10]={2,3,4,3,4,4,3,4,4,4};
ll ans = 0;
REP(i, 10) {
ans += d[p[i]]*d[q[i]]*d[z[i]];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S[110000];
char c[110000];
long long int a = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
c[i] = S[i][0];
}
for (int i = 0; i < N; i++) {
if (c[i] == 'M' || c[i] == 'A' || c[i] == 'R' || c[i] == 'C' ||
c[i] == 'H') {
for (int j = i + 1; j < N; j++) {
if (c[j] == 'M' || c[j] == 'A' || c[j] == 'R' || c[j] == 'C' ||
c[j] == 'H' && c[i] != c[j]) {
for (int k = j + 1; k < N; k++) {
if (c[k] == 'M' || c[k] == 'A' || c[k] == 'R' || c[k] == 'C' ||
c[k] == 'H' && c[i] != c[j] && c[i] != c[k] && c[j] != c[k]) {
a += 1;
}
}
}
}
}
}
cout << a << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long count[5] = {0, 0, 0, 0, 0};
long a;
cin >> a;
string b;
for (int i = 0; i < a; ++i) {
cin >> b;
if (b[0] == 'M') {
count[0]++;
} else if (b[0] == 'A') {
count[1]++;
} else if (b[0] == 'R') {
count[2]++;
} else if (b[0] == 'C') {
count[3]++;
} else if (b[0] == 'H') {
count[4]++;
}
}
long sum = 0;
for (int j = 0; j < 5; ++j) {
for (int i = j + 1; i < 5; ++i) {
for (int k = i + 1; k < 5; ++k) {
sum += count[j] * count[i] * count[k];
}
}
}
printf("%d\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long get_factorial(long n) {
long result = 1;
for (long i = 2; i <= n; i++) {
result *= i;
}
return result;
}
long get_combination(long n, long r) {
return get_factorial(n) / (get_factorial(n - r) * get_factorial(r));
}
long solve(vector<int> count) {
int result = 0;
int char_count, elem_combination;
bitset<5> combination;
for (int i = 0; i < (1 << 5); i++) {
char_count = 0;
elem_combination = 1;
combination = i;
for (int j = 0; j < 5; j++) {
if (combination[j] == 1) {
char_count++;
elem_combination *= count[j];
}
}
if (char_count == 3) {
result += elem_combination;
}
}
return result;
}
int main() {
int N;
cin >> N;
string str;
vector<int> count(5, 0);
long answer;
for (int i = 0; i < N; i++) {
cin >> str;
switch (str[0]) {
case 'M':
count[0]++;
break;
case 'A':
count[1]++;
break;
case 'R':
count[2]++;
break;
case 'C':
count[3]++;
break;
case 'H':
count[4]++;
break;
}
}
answer = solve(count);
cout << answer << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func init() {
sc.Split(bufio.ScanWords)
sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}
func next() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
a, _ := strconv.Atoi(next())
return a
}
var M map[string]bool
func main() {
N := nextInt()
var S []string
M = map[string]bool{"M": true, "A": true, "R": true, "C": true, "H": true}
for i := 0; i < N; i++ {
s := next()
if IsMarch(s[0:1]) {
S = append(S, s)
}
}
if len(S) < 3 {
fmt.Println(0)
return
}
var ANS int
for i := 0; i < len(S)-2; i++ {
for j := i + 1; j < len(S)-1; j++ {
for k := j + 1; k < len(S); k++ {
if solve(S[i], S[j], S[k]) {
ANS++
}
}
}
}
fmt.Println(ANS)
}
func IsMarch(s string) bool {
return M[s]
}
func solve(a, b, c string) bool {
m := make(map[string]int, 3)
m[a[0:1]]++
m[b[0:1]]++
m[c[0:1]]++
for _, v := range m {
if v > 1 {
return false
}
}
return true
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main() {
int N;
cin >> N;
int M, A, R, C, H;
M = A = R = C = H = 0;
for (int i = 0; i < N; ++i) {
string name;
cin >> name;
switch (name.at(0)) {
case 'M':
++M;
break;
case 'A':
++A;
break;
case 'R':
++R;
break;
case 'C':
++C;
break;
case 'H':
++H;
break;
}
}
int ma = M * A;
int mr = M * R;
int mc = M * C;
int ar = A * R;
int ac = A * C;
int rc = R * C;
int ans = ma * (R + C + H);
ans += mr * (C + H);
ans += mc * H;
ans += ar * (C + H);
ans += ac * H;
ans += rc * H;
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
int main() {
int N;
cin >> N;
string MARCH = "MARCH", s;
int l = MARCH.length();
vector<int> count(l);
for (int i = (0); i <= ((N)-1); ++i) {
cin >> s;
for (int j = (0); j <= ((l)-1); ++j) {
if (MARCH[j] == s[0]) {
count[j]++;
}
}
}
long long ans = 0;
for (int i = (0); i <= ((l)-1); ++i) {
for (int j = (i + 1); j <= (l - 1); ++j) {
for (int k = (j + 1); k <= (l - 1); ++k) {
ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
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;
cin >> S;
char s = S[0];
if (s == 'M')
M++;
else if (s == 'A')
A++;
else if (s == 'R')
R++;
else if (s == 'C')
C++;
else if (s == 'H')
H++;
}
vector<int> V = {M, A, R, C, H};
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += V[i] * V[j] * V[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import*;d={};g=d.get
for t in open(0).read().split():d[t]=g(t,0)+1
print(sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',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 | python3 | from itertools import combinations
import collections
N = int(input())
A = []
for i in range(N):
A.append(input()[0])
AA = set(A)
C = collections.Counter(A)
print(sum(C[a]*C[b]*C[c] for a, b, c in combinations(AA, 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 | python3 | from itertools import combinations
n, *S = open(0).read().split()
n = int(n)
march = []
for c in 'MARCH':
march.append(len([s for s in S if s[0] == c]))
print(march)
ans = 0
for a, b, c in combinations(march, 3):
ans += a*b*c
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int h[5];
int main() {
int N;
char S[11];
for (int i = 0; i < 5; i++) h[i] = 0;
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%s", S);
if (S[0] == 'M') h[0]++;
if (S[0] == 'A') h[1]++;
if (S[0] == 'R') h[2]++;
if (S[0] == 'C') h[3]++;
if (S[0] == 'H') h[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++)
for (int k = j + 1; k < 5; k++) {
ans += h[i] * h[j] * h[k];
}
return (printf("%lld\n", ans));
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long ans = 0;
int N;
cin >> N;
string st;
vector<pair<char, int> > input(5);
(input[0].first, input[0].second) = ('M', 0);
input[1].first, input[2].second = ("A", 0);
input[2].first, input[2].second = ("R", 0);
input[3].first, input[3].second = ("C", 0);
input[4].first, input[4].second = ("H", 0);
for (int i = 0; i < N; i++) {
cin >> st;
if (st[0] == 'M') input[0].second++;
if (st[0] == 'A') input[1].second++;
if (st[0] == 'R') input[2].second++;
if (st[0] == 'C') input[3].second++;
if (st[0] == 'H') input[4].second++;
}
bool m = input[0].second, a = input[1].second, r = input[2].second,
c = input[3].second, h = input[4].second;
int portion = m + a + r + c + h;
if (portion < 3) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k < 4; k++) {
ans += input[i].second * input[j].second * input[k].second;
}
}
}
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 | <?php
error_reporting(0);
//$N = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
//list($H,$W) = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$N;$i++) {
$v = trim(fgets(STDIN));
if ($v[0]=='M'||$v[0]=='A'||$v[0]=='R'||$v[0]=='C'||$v[0]=='H') {
$S[]=$v;
}
}
$S = array_unique($S);
foreach($S as $v) {
$V[]=$v[0];
}
$cn = array_count_values($V);
$res=0;
//3つづつの組み合わせ数を足し合わせればいい?
if (isset($cn["M"])&&isset($cn["A"])&&isset($cn["R"])) {
$res += $cn["M"]*$cn["A"]*$cn["R"];
}
if (isset($cn["M"])&&isset($cn["A"])&&isset($cn["C"])) {
$res += $cn["M"]*$cn["A"]*$cn["C"];
}
if (isset($cn["M"])&&isset($cn["A"])&&isset($cn["H"])) {
$res += $cn["M"]*$cn["A"]*$cn["H"];
}
if (isset($cn["M"])&&isset($cn["R"])&&isset($cn["C"])) {
$res += $cn["M"]*$cn["R"]*$cn["C"];
}
if (isset($cn["M"])&&isset($cn["R"])&&isset($cn["H"])) {
$res += $cn["M"]*$cn["R"]*$cn["H"];
}
if (isset($cn["M"])&&isset($cn["C"])&&isset($cn["H"])) {
$res += $cn["M"]*$cn["C"]*$cn["H"];
}
if (isset($cn["A"])&&isset($cn["R"])&&isset($cn["C"])) {
$res += $cn["A"]*$cn["R"]*$cn["C"];
}
if (isset($cn["A"])&&isset($cn["R"])&&isset($cn["H"])) {
$res += $cn["A"]*$cn["R"]*$cn["H"];
}
if (isset($cn["R"])&&isset($cn["C"])&&isset($cn["H"])) {
$res += $cn["R"]*$cn["C"]*$cn["H"];
}
printf("%d\n",$res);
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
long long INF = 1000000000000000000;
long long mod = 1000000007;
using namespace std;
int main() {
long long ans = 0;
int N;
cin >> N;
int member[5] = {};
for (int i = 0; i < N; i++) {
char c;
string s;
cin >> s;
c = s[0];
if (c == 'M') member[0]++;
if (c == 'A') member[1]++;
if (c == 'R') member[2]++;
if (c == 'C') member[3]++;
if (c == 'H') member[4]++;
}
long long t = member[0] * member[1];
for (int i = 0; i < 3; i++) {
ans += t * member[2 + i];
}
t = member[0] * member[2];
for (int i = 0; i < 2; i++) ans += t * member[3 + i];
ans += member[0] * member[3] * member[4];
t = member[1] * member[2];
for (int i = 0; i < 2; i++) ans += t * member[3 + i];
t = member[3] * member[4];
for (int i = 0; i < 2; i++) ans += t * member[1 + i];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 1000000000;
int main() {
int n;
cin >> n;
long long int a[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
a[0]++;
} else if (s[0] == 'A') {
a[1]++;
} else if (s[0] == 'R') {
a[2]++;
} else if (s[0] == 'C') {
a[3]++;
} else if (s[0] == 'H') {
a[4]++;
}
}
long long int ans = 1;
bool f = true;
long long int s = 0;
for (int i = 0; i < 5; i++) {
if (a[i] != 0) {
f = false;
ans *= a[i];
s++;
}
}
if (f) {
ans = 0;
} else if (s == 4 || s == 5) {
ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i; j < 4; j++) {
for (int k = j; k < 5; k++) {
if (a[i] == 0 || a[j] == 0 || a[k] == 0) {
continue;
}
if (i == j || j == k || i == k) {
continue;
}
ans += a[i] * a[j] * a[k];
}
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n, i, j, k, ans = 0;
int ma[5] = {};
char str[10] = {};
char march[5] = {'M', 'A', 'R', 'C', 'H'};
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str);
for (j = 0; j < 5; j++) {
if (str[0] == march[j]) ma[j]++;
}
}
for (i = 0; i < 5; i++) {
for (j = i + 1; j < 5; j++) {
for (k = j + 1; k < 5; k++) {
ans += ma[i] * ma[j] * ma[k];
}
}
}
printf("%d", 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())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0
for i in range(N):
if S[i][0]=='M':
cnt[0]+=1
elif S[i][0]=='A':
cnt[1]+=1
elif S[i][0]=='R':
cnt[2]+=1
elif S[i][0]=='C':
cnt[3]+=1
elif S[i][0]=='H':
cnt[4]+=1
for i in range(N):
if cnt[i]!=0:
cnt2.append(cnt[i])
import math
import itertools
ans=0
for v in itertools.combinations(cnt2, 3):
ans+=v[0]*v[1]*v[2]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
template <typename T>
void printA(vector<T> &printArray, char between = ' ') {
int paSize = printArray.size();
for (int i = 0; i < paSize; i++) {
cerr << printArray[i] << between;
}
if (between != '\n') {
cerr << endl;
}
}
int main() {
int n;
cin >> n;
int S[5] = {0};
string march = "MARCH";
for (int(i) = (0); (i) < (n); ++(i)) {
string s;
cin >> s;
auto p = march.find(s[0]);
if (p == string::npos) continue;
S[p]++;
}
long long sum = 0;
for (int(i) = (0); (i) < (5); ++(i)) {
for (int(j) = (i + 1); (j) < (5); ++(j)) {
for (int(k) = (j + 1); (k) < (5); ++(k)) {
sum += S[i] * S[j] * S[k];
}
}
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool print(T& x) {
cout << x << endl;
return true;
}
template <class T>
inline bool print_(T& x) {
cout << x << " ";
return true;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll gcd(ll x, ll y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int INF = 1e9;
const ll llINF = 1LL << 60;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; (i) < (n); ++(i)) cin >> s[i];
vector<int> v(5, 0);
for (int i = 0; (i) < (n); ++(i)) {
switch (s[i][0]) {
case 'M':
v[0]++;
break;
case 'A':
v[1]++;
break;
case 'R':
v[2]++;
break;
case 'C':
v[3]++;
break;
case 'H':
v[4]++;
break;
}
}
int ans = 0;
for (int i = 0; (i) < (3); ++(i)) {
for (int j = (i + 1); (j) < (4); ++(j)) {
for (int k = (j + 1); (k) < (5); ++(k)) {
ans += v[i] * v[j] * v[k];
}
}
}
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long ans, cnt;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long N;
string s;
map<char, int> m;
string march = "MARCH";
for (long long i = 0; i < (long long)(march.size()); ++i) {
m[march[i]] = 0;
}
cin >> N;
for (long long i = 0; i < (long long)(N); ++i) {
cin >> s;
m[s[0]]++;
}
ans += m['M'] * m['A'] * m['R'];
ans += m['M'] * m['A'] * m['C'];
ans += m['M'] * m['A'] * m['H'];
ans += m['M'] * m['R'] * m['C'];
ans += m['M'] * m['R'] * m['H'];
ans += m['M'] * m['C'] * m['H'];
ans += m['A'] * m['R'] * m['C'];
ans += m['A'] * m['R'] * m['H'];
ans += m['A'] * m['C'] * m['H'];
ans += m['R'] * m['C'] * m['H'];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from math import *
from itertools import combinations
n = int(input())
s = [input() for _ in range(n)]
s = list(map(lambda x: x[0], s))
s = list(filter(lambda x: x in 'MARCH', s))
t = {}
for x in range(len(s)):
if s[x] in t: t[s[x]] += 1
else: t[s[x]] = 1
t = list(t.values())
a = 0
for c in combinations(t, 3):
m = 1
for e in c:
m *= factorial(e)
a += m
print(a)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
template <int mod>
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using mint = ModInt<(int)(1e9 + 7)>;
int main() {
int N;
cin >> N;
vector<string> S(N);
map<char, mint> M;
for (int i = 0; i < (N); i++) {
cin >> S[i];
char c = S[i][0];
if (c == 'M' or c == 'A' or c == 'R' or c == 'C' or c == 'H') {
M[c] += 1;
}
}
mint ans(0);
for (auto i : M) {
for (auto j : M) {
for (auto k : M) {
if (i != k and i != j and j != k) {
ans += i.second * j.second * k.second;
}
}
}
}
const mint l(6);
cout << (ans / l).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;
int main() {
int arr[6];
for (int i = 0; i < 5; i++) arr[i] = 0;
int n;
cin >> n;
string d;
while (n--) {
cin >> d;
switch (d[0]) {
case 'A':
arr[0]++;
break;
case 'C':
arr[1]++;
break;
case 'H':
arr[2]++;
break;
case 'M':
arr[3]++;
break;
case 'R':
arr[4]++;
break;
}
}
int e = 0;
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++) e += (arr[i] * arr[j] * arr[k]);
cout << e;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long combination(long n, int r) {
long long dividend = 1;
long long divisor = 1;
for (int i = 1; i < r + 1; i += 1) {
dividend *= (n - i + 1);
divisor *= i;
}
return dividend / divisor;
}
int main() {
int n;
string input;
int march[5] = {0};
cin >> n;
for (int i = 0; i < n; i += 1) {
cin >> input;
switch (input[0]) {
case 'M':
march[0] += 1;
break;
case 'A':
march[1] += 1;
break;
case 'R':
march[2] += 1;
break;
case 'C':
march[3] += 1;
break;
case 'H':
march[4] += 1;
break;
}
}
long long two = 0, marchsum = 0;
for (int i = 0; i < 5; i += 1) {
marchsum += march[i];
}
long long sum = combination(marchsum, 3);
for (int i = 0; i < 5; i += 1) {
if (march[i] >= 2) {
two += (marchsum - march[i]) * combination(march[i], 2);
}
}
long long three = 0;
for (int i = 0; i < 5; i += 1) {
three += combination(max(march[i] - 3, 0), 3);
}
sum - two - three;
cout << sum - two - three << 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 n = readLine()!!.toInt()
val s = (1..n).map { readLine()!!.first() }
.filter { it in "MARCH" }.groupBy { it }.map { it.value.size.toInt() }
if (s.size<3) {
println(0)
return
}
var ans = 0L
for (i in 0 until s.size-2) for (j in i+1 until s.size-1) for (k in j+1 until s.size) {
ans += s[i]*s[j]*s[k]
}
println(ans)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
#include <vector>
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_buck(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;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 | cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
s = input()[0]
if s in march:
S[s] += 1
for i in range(5**2):
tmp = []
for j in range(N):
if (i >> j) & 1:
tmp.append(S[march[j]])
if len(tmp) == 3:
cnt += tmp[0] * tmp[1] * tmp[2]
print(cnt) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif // !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
int main()
{
size_t N;
std::cin >> N;
std::vector<int64_t> P(5);
for (size_t i = 0; i < N; ++i) {
std::string s;
std::cin >> s;
switch (s[0]) {
case 'M':
P[0]++;
break;
case 'A':
P[1]++;
break;
case 'R':
P[2]++;
break;
case 'C':
P[3]++;
break;
case 'H':
P[4]++;
break;
default:
break;
}
}
int64_t count = 0;
// MAR--
count += P[0]*P[1]*P[2];
// MA-C-
count += P[0]*P[1]*P[3];
// MA--H
count += P[0]*P[1]*P[4];
// M-RC-
count += P[0]*P[2]*P[3];
// M-R-H
count += P[0]*P[2]*P[4];
// M--CH
count += P[0]*P[3]*P[4];
// -ARC-
count += P[1]*P[2]*P[3];
// -AR-H
count += P[1]*P[2]*P[4];
// -A-CH
count += P[1]*P[3]*P[4];
std::cout << count << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
}
int count[5] = {0};
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M') count[0]++;
if (S[i][0] == 'A') count[1]++;
if (S[i][0] == 'R') count[2]++;
if (S[i][0] == 'C') count[3]++;
if (S[i][0] == 'H') count[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M = 0, A = 0, R = 0, C = 0, H = 0;
long long ans = 0;
cin >> N;
string s[N];
for (int i = 0; i < N; i++) {
cin >> s[i];
}
for (int i = 0; i < N; i++) {
if (s[i][0] == 'M') {
M++;
} else if (s[i][0] == 'A') {
A++;
} else if (s[i][0] == 'R') {
R++;
} else if (s[i][0] == 'C') {
C++;
} else if (s[i][0] == 'H') {
H++;
}
}
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
int main() {
string T = "MARCH";
int N;
cin >> N;
vector<int> v(5, 0);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == T[j]) v[j]++;
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += (v[i] * v[j] * v[k]);
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, a[1010];
long long ans;
char s[101010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s);
if (s[0] == 'M') a[1]++;
if (s[0] == 'A') a[2]++;
if (s[0] == 'R') a[3]++;
if (s[0] == 'C') a[4]++;
if (s[0] == 'H') a[5]++;
}
for (int i = 1; i <= 3; i++)
for (int j = i + 1; j <= 4; j++)
for (int k = j + 1; k <= 5; k++) ans += a[i] * a[j] * a[k];
printf("%d", 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;
long long combination(long long t, long long r) {
if (t == r || r == 0)
return 1;
else
return combination(t, r - 1) * (t - r + 1) / r;
}
int main(void) {
long long n;
long long d = 0;
long long a[5] = {};
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') a[0]++;
if (s[0] == 'A') a[1]++;
if (s[0] == 'R') a[2]++;
if (s[0] == 'C') a[3]++;
if (s[0] == 'H') a[4]++;
}
for (int i = 0; i < 5; i++) {
if (a[i] == 0) {
d++;
}
}
if (d >= 3) {
cout << '0' << endl;
return 0;
}
long long cnt1 = 0;
long long cnt2 = 0;
long long cnt3 = 0;
for (int i = 0; i < 5; i++) {
if (a[i] == 1) cnt1++;
if (a[i] != 0) cnt2++;
if (a[i] != 0 && a[i] != 1) cnt3++;
}
long long ans1 = 0;
if (cnt1 >= 3)
ans1 = combination(cnt1, 3);
else
ans1 = 0;
long long ans2;
if (cnt1 >= 2)
ans2 = combination(cnt1, 2);
else if (cnt1 == 1 || cnt1 == 0)
ans2 = 1;
for (int i = 0; i < 5; i++) {
if (a[i] != 0) ans2 *= a[i];
}
cout << ans1 + ans2 << 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, ma = 0, aa = 0, ra = 0, ca = 0, ha = 0;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
if (t[0] == 'M') ma++;
if (t[0] == 'A') aa++;
if (t[0] == 'R') ra++;
if (t[0] == 'C') ca++;
if (t[0] == 'H') ha++;
}
cout << ma * aa * ra + ma * aa * ca + ma * aa * ha + ma * ra * ca +
ma * ra * ha + ma * ca * ha + aa * ra * ca + aa * ra * ha +
aa * ca * ha + ra * ca * ha
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
n=int(input())
s=[input()[0] for _ in range(n)]
a=[]
for i in ['M','A','R','C','H']:
a+=[s.count(i)]
print(a)
ans=0
for i in combinations(a,3):
ans+=i[0]*i[1]*i[2]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<array>
using namespace std;
int main(void){
int N;
cin >> N;
string S;
long MARCH[5] = {0};
for (int i = 0; i < N; i++) {
cin >> S;
switch(S[0]) {
case 'M':
MARCH[0]++;
break;
case 'A':
MARCH[1]++;
break;
case 'R':
MARCH[2]++;
break;
case 'C':
MARCH[3]++;
break;
case 'H':
MARCH[4]++;
break;
}
}
long count = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
count += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
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;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
int n;
cin >> n;
vector<string> lis(n);
vector<int> name(5, 0);
for (int i = 0, i_len = (n); i < i_len; ++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 < 5; i++) {
if (name[i] == 0) {
continue;
}
for (int l = i + 1; l < 5; l++) {
if (name[l] == 0) {
continue;
}
for (int k = l + 1; k < 5; k++) {
if (name[k] == 0) {
continue;
}
ans += name[i] * name[l] * name[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
unsigned long ans = 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++;
}
ans += M * A * (R + C + H);
ans += M * R * (C + H);
ans += M * C * H;
ans += A * R * (C + H);
ans += (A + R) * C * H;
printf("%lu\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp2
{
class Program
{
static void Main()
{
var x = int.Parse(Console.ReadLine());
long count = 0;
var counts = new int[5];
for (int i = 0; i < x; i++)
{
var s = Console.ReadLine();
switch (s[0])
{
case 'M':
counts[0]++;
break;
case 'A':
counts[1]++;
break;
case 'R':
counts[2]++;
break;
case 'C':
counts[3]++;
break;
case 'H':
counts[4]++;
break;
default:
break;
}
}
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;
}
count += counts[i] * counts[j] * counts[k];
}
}
}
Console.WriteLine(count);
Console.ReadLine();
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
template <typename T>
void say(T s) {
cout << s << "\n";
}
template <typename T>
void say(vector<T> s) {
auto itr = s.begin();
cout << *(itr++);
while (itr != s.end()) {
cout << " " << *(itr++);
}
cout << "\n";
}
int main() {
int march[] = {0, 0, 0, 0, 0};
ll ans = 0;
int N;
cin >> N;
;
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
switch (s[0]) {
case 'M':
++march[0];
break;
case 'A':
++march[1];
break;
case 'R':
++march[2];
break;
case 'C':
++march[3];
break;
case 'H':
++march[4];
break;
}
}
for (int i = 0; i < 5; ++i)
for (int j = i + 1; j < 5; ++j)
for (int k = j + 1; k < 5; ++k) {
ans += march[i] * march[j] * march[k];
}
printf("%lld\n", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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];
}
}
}
do {
ans += march[perm[0]] * march[perm[1]] * march[perm[2]];
} while (next_permutation(perm.begin(), perm.end()));
cout << ans / 12 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int Len(int n) {
int s = 0;
while (n != 0) s++, n /= 10;
return s;
}
int Sint(int n) {
int m = 0, s = 0, a = n;
while (a != 0) s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int Svec(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++) n += v[i];
return n;
}
int GCD(int a, int b) {
int r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
int LCM(int a, int b) {
int c = a, d = b, r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
int Factorial(int n) {
int m = 1;
while (n >= 1) m *= n, n--;
return m;
}
int main() {
int n;
cin >> n;
vector<int> c(5);
for (int i = 0; i < (5); i++) c[i] = 0;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
c[0]++;
} else if (s[0] == 'A') {
c[1]++;
} else if (s[0] == 'R') {
c[2]++;
} else if (s[0] == 'C') {
c[3]++;
} else if (s[0] == 'H') {
c[4]++;
}
}
int cnt = 0;
for (int i = 0; i < (5); i++)
if (c[i] > 0) cnt++;
if (cnt <= 2) {
cout << 0 << endl;
return 0;
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += 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 | java | import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
int[] num = new int[5];
scn.nextLine();
for (int i = 0; i < N; i++) {
char[] buf = scn.nextLine().toCharArray();
switch (buf[0]) {
case 'M':
num[0]++;
break;
case 'A':
num[1]++;
break;
case 'R':
num[2]++;
break;
case 'C':
num[3]++;
break;
case 'H':
num[4]++;
break;
default:
break;
}
}
long ans = 0;
for(int i = 0;i < 3;i++) {
for(int j = i+1;j < 4;j++) {
for(int k = j+1;k < 5;k++) {
ans += num[i] * num[j] * num[k];
}
}
}
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
unsigned long long res = 0;
vector<int> v = {0, 0, 0, 0, 0};
string tmp;
for (int(i) = 0; (i) < (n); (i)++) {
cin >> tmp;
char f = tmp.at(0);
if (f == 'M')
v[0]++;
else if (f == 'A')
v[1]++;
else if (f == 'R')
v[2]++;
else if (f == 'C')
v[3]++;
else if (f == 'H')
v[4]++;
}
for (int(i) = 0; (i) < (5); (i)++) {
for (int(j) = 0; (j) < (5); (j)++) {
for (int(k) = 0; (k) < (5); (k)++) {
if (i < j && j < k) {
res += v[i] * v[j] * v[k];
}
}
}
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | // SeeAlso: https://atcoder.jp/contests/abc089/tasks/abc089_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MAX 100000
typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
int n;
int main() {
cin >> n;
int m,a,r,c,h;
REP(i, n) {
string s;
cin >> s;
if(s[0]=='M')m++;
if(s[0]=='A')a++;
if(s[0]=='R')r++;
if(s[0]=='C')c++;
if(s[0]=='H')h++;
}
int d[5];
d[0]=m;
d[1]=a;
d[2]=r;
d[3]=c;
d[4]=h;
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 z[10]={2,3,4,3,4,4,3,4,4,4};
ll ans = 0;
REP(i, 10) {
ans += d[p[i]]*d[q[i]]*d[z[i]];
}
print(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[100000][11];
int main() {
int N;
cin >> N;
int n[5] = {0};
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M')
n[0]++;
else if (S[i][0] == 'A')
n[1]++;
else if (S[i][0] == 'R')
n[2]++;
else if (S[i][0] == 'C')
n[3]++;
else if (S[i][0] == 'H')
n[4]++;
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += n[i] * n[j] * n[k];
}
}
}
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<char, int> mp;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
mp[s[0]]++;
}
int a[5] = {};
for (int i = 0; i < 5; i++) {
a[i] = mp[c[i]];
}
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 += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char name[1005 * 10][1005];
long long m, a, r, c, h;
long long ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", name[i]);
for (int i = 1; i <= n; i++) {
if (name[i][0] == 'M') m++;
if (name[i][0] == 'A') a++;
if (name[i][0] == 'R') r++;
if (name[i][0] == 'C') c++;
if (name[i][0] == 'H') h++;
}
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);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
long long int sum = 0;
int num[5], i, n, j, k, x;
char name[11];
for (i = 0; i < 5; i++) num[i] = 0;
scanf("%d", &n);
while (n > 0) {
scanf("%s", name);
if (name[0] == 'M')
num[0]++;
else if (name[0] == 'A')
num[1]++;
else if (name[0] == 'R')
num[2]++;
else if (name[0] == 'C')
num[3]++;
else if (name[0] == 'H')
num[4]++;
n--;
}
for (i = 0; i < 3; i++) {
x = 0;
for (j = i + 1; j < 4; j++)
for (k = j + 1; k < 5; k++) x += num[j] * num[k];
sum += x * num[i];
}
printf("%lld", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | # -*- coding: utf-8 -*-
N = int(input())
name = []
for i in range(0,N):
data = input()
name.append(data)
check = 0
check_m = 0
check_a = 0
check_r = 0
check_c = 0
check_h = 0
for i in name:
if i[0] == "M":
if check_m == 0:
check += 1
check_m += 1
elif i[0] == "A":
if check_a == 0:
check += 1
check_a += 1
elif i[0] == "R":
if check_r == 0:
check += 1
check_r += 1
elif i[0] == "C":
if check_c == 0:
check += 1
check_c += 1
elif i[0] == "H":
if check_h == 0:
check += 1
check_h += 1
if check < 3:
print(0)
elif check == 3:
s = []
if check_m != 0:
s.append(check_m)
if check_a != 0:
s.append(check_a)
if check_r != 0:
s.append(check_r)
if check_c != 0:
s.append(check_c)
if check_h != 0:
s.append(check_h)
se = 1
for i in s:
se = se*i
print(int(se))
elif check == 4:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = (check*(check-1)*(check-2))/6
if len(s) == 0:
print(int(n))
else:
se = 1
for i in s:
se += i*(n-1)
print(int(se))
elif check == 5:
s = []
if 1 < check_m:
s.append(check_m)
if 1 < check_a:
s.append(check_a)
if 1 < check_r:
s.append(check_r)
if 1 < check_c:
s.append(check_c)
if 1 < check_h:
s.append(check_h)
n = (check*(check-1)*(check-2))/6
if len(s) == 0:
print(int(n))
else:
se = 1
for i in s:
se += i*(n-1)
print(int(se)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// File file = new File("test.txt");
// Scanner sc = new Scanner(file);
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] MARCH = new int[5];
long ans = 0;
for(int i = 0; i < N; i++){
char ch = sc.next().charAt(0);
switch(ch){
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;
}
}
sc.close();
for(int i = 0; i < 3; i++){
for(int j = i+1; j < 4; j++){
for(int k = j+1; k < 5; 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, ans = 0;
cin >> n;
vector<char> march = {'M', 'A', 'R', 'C', 'H'};
vector<char> a(5);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == march[j]) {
a[j]++;
break;
}
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | num = gets.to_i
initial = {M: 0,A: 0,R: 0,C: 0,H: 0}
person = []
while num > 0 do
num -= 1
if gets.to_s[0] == ("M"||"A"||"R"||"C"||"H")
initial[gets.to_s[0]] += 1
end
end
#{M: 1,A: 2,R: 1,C: 0,H: 1}
initial = intial.select {|k, v| v > 0 }
#{M: 1,A: 2,R: 1,H: 1} A=1 => 3 A=2 =>6
sum_1 = initial.keys.combination(3)
initial2 = intial.select {|k, v| v > 1 }
# {A: 2}
initial2.each{|key, value|
sum_1 = sum_1 * value
}
puts sum_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 | import itertools
from collections import Counter
n = int(input())
s = [input()[0] for _ in range(n)]
cnt = Counter(s)
print(cnt)
ans = 0
for x,y,z in itertools.combinations("MARCH",3):
# print(x,y,z)
ans += cnt[x]*cnt[y]*cnt[z]
#print(cnt[x],cnt[y],cnt[z])
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
long long ans = 0, a[N];
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string str;
cin >> str;
if (str[0] == 'M') a[1]++;
if (str[0] == 'A') a[2]++;
if (str[0] == 'R') a[3]++;
if (str[0] == 'C') a[4]++;
if (str[0] == 'H') a[5]++;
}
for (int i = 1; i <= 5; i++)
for (int j = i + 1; j <= 5; j++)
for (int k = j + 1; k <= 5; k++) ans += a[i] * a[j] * a[k];
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] count = new int[5];
List<Character> symbols = new ArrayList<Character>() {
{
add('M');
add('A');
add('R');
add('C');
add('H');
}
};
for (int i = 0; i < N; i++) {
String name = sc.next();
int index = symbols.indexOf(name.toCharArray()[0]);
if (index != -1) {
count[index] = count[index] + 1;
}
}
int ans = 0;
for (int i = 0; i < symbols.size(); i++) {
for (int j = i + 1; j < symbols.size(); j++) {
for (int k = j + 1; k < symbols.size(); k++) {
ans += count[i] * count[j] * count[k];
}
}
}
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python2 | import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
if fileobject == None :
return raw_input
else:
return fileobject.readline
def is_tasai(S):
appare_set = set([])
for s in S:
if s in appare_set:
return False
appare_set.add(s)
return True
table = {}
def comb(n, r):
if (n, r) in table:
return table[(n, r)]
if n == r:
table[(n, r)] = 1L
return 1L
if r == 0:
table[(n, r)] = 1L
return 1L
if n == 0:
return 0L
table[(n, r)] = comb(n-1, r-1)+ comb(n-1, r)
return table[(n, r)]
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = None
read_func = get_read_func(f);
input_raw = read_func().strip().split()
[N] = [int(input_raw[0])]
initial_dict = {}
initial_dict["M"] = 0
initial_dict["A"] = 0
initial_dict["R"] = 0
initial_dict["C"] = 0
initial_dict["H"] = 0
for i in range(N):
input_raw = read_func().strip().split()
if input_raw[0][0] in initial_dict:
initial_dict[input_raw[0][0]] += 1
M = 0
for s in initial_dict:
M += initial_dict[s]
remove_num = 0
for s in initial_dict:
remove_num += comb(initial_dict[s], 2) * (M - 2)
print comb(M, 3) - remove_num
if __name__ == '__main__':
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<char> a = {'M', 'A', 'R', 'C', 'H'};
vector<int> b(5, 0);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
char c = s.at(0);
for (int j = 0; j < 5; j++) {
if (c == a.at(j)) {
b.at(j) += 1;
}
}
}
int sum = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
sum += b.at(i) * b.at(j) * b.at(k);
}
}
}
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
int N;
std::cin >> N;
std::vector<int> vs(N);
char march[] = {'M', 'A', 'R', 'C', 'H'};
int marchNum[5] = {0};
for (int i = 0; i < N; i++) {
std::string str;
std::cin >> str;
for (int j = 0; j < 5; j++) {
if (str[0] == march[j]) marchNum[j]++;
}
}
unsigned long long comNum = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
comNum += marchNum[i] * marchNum[j] * marchNum[k];
}
}
}
std::cout << comNum << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int mod = 1000000007;
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> prime_factorize(int64_t x) {
vector<pair<int64_t, int64_t>> p;
for (int64_t i = 2; i * i <= x; i++) {
int cnt = 0;
if (x % i == 0) {
while (x % i == 0) {
cnt++;
x /= i;
}
p.push_back(make_pair(i, cnt));
}
}
if (x != 1) {
p.push_back(make_pair(x, 1));
}
return p;
}
int main() {
int N;
cin >> N;
vector<string> s(N);
for (int i = 0; i < N; i++) {
cin >> s[i];
}
map<char, int> k;
for (int i = 0; i < N; i++) {
k[s[i][0]]++;
}
string t = "MARCH";
int64_t ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int r = j + 1; r < 5; r++) {
ans += k[t[i]] * k[t[j]] * k[t[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 | python3 | n=int(input())
l=[0]*10
for i in range(n):
x=input()
y=x[0]
if y=='M':
l[0]+=1
elif y=='A':
l[1]+=1
elif y=='R':
l[2]+=1
elif y=='C':
l[3]+=1
elif y=='H':
l[4]+=1
ans=0
for i in range(3):
for j in range(i+1,i+4):
for k in range(j+1,j+4):
sum+=l[i]*l[j]*l[k]
print(sum)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long fn(long long mh, long long nm) {
if (nm < 2) {
return 0;
}
long long sa = mh - nm;
long long rt = sa;
if (nm == 2) {
return rt;
}
return rt + nm * (nm - 1) * (nm - 2) / 6;
}
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
char s1 = s.at(0);
if (s1 == 'M') {
m++;
} else if (s1 == 'A') {
a++;
} else if (s1 == 'R') {
r++;
} else if (s1 == 'C') {
c++;
} else if (s1 == 'H') {
h++;
}
}
long long ans = 0;
long long mh = m + a + r + c + h;
long long cm = mh * (mh - 1) * (mh - 2) / 6;
ans = cm - fn(mh, m) - fn(mh, a) - fn(mh, r) - fn(mh, c) - fn(mh, h);
if (m * a * r == 0 && m * a * c == 0 && m * a * h == 0 && m * r * c == 0 &&
m * r * h == 0 && m * c * h == 0 && a * r * c == 0 && a * r * h == 0 &&
a * c * h == 0 && c * h * r == 0) {
ans = 0;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
}
long long ans = 0;
map<string, bool> M;
vector<int> C(5, 0);
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 (M[S[i]] == false) {
M[S[i]] = true;
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]++;
}
}
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
if (C[i] != 0 && C[j] != 0 && C[k] != 0) {
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 | python3 | N=int(input())
i=0
s=[]
con=["M","A","R","C","H"]
select_1=[]
while i<N:
a=input()
s.append(a)
i+=1
for ss in s:
if ss[0] in con:
select_1.append(ss)
i=0
l=len(select_1)
select=[]
count=0
while i<l:
select.append(select_1[i])
j=i
while j<l:
select.append(select_1[j])
k=j
while k<l:
select.append(select_1[k])
if select[0][0]!=select[1][0] and select[0][0]!=select[2][0] and select[1][0]!=select[2][0]:
count+=1
select.pop()
k+=1
select.pop()
j+=1
select.pop()
i+=1
print(count) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#define itn int
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
int main(){
int n;
cin >> n;
vector<string> sv(n);
string s="MARCH";
set<char> st;
int ans[5]={};
rep(i,n){
cin >> sv[i];
int tmp=s.find(sv[i][0]);
if(tmp!=-1){
st.insert(s[tmp]);
ans[tmp]++;
}
}
int a=0;
rep(i,3){
int tmp=ans[i];
for(int j=i+1;i!=4;i++){
tmp*=ans[j];
for(int k=j+1;k!=5;k++){
tmp*=ans[k];
}
}
a+=tmp;
}
cout << a << 3ndl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | "use strict";
// 組み合わせ(被りなし)
const combineWithoutRepetitions = (comboOptions, comboLength) => {
if (comboLength === 1) {
return comboOptions.map(comboOption => [comboOption]);
}
// Init combinations array.
const combos = [];
// Eliminate characters one by one and concatenate them to
// combinations of smaller lengths.
comboOptions.forEach((currentOption, optionIndex) => {
const smallerCombos = combineWithoutRepetitions(
comboOptions.slice(optionIndex + 1),
comboLength - 1
);
smallerCombos.forEach((smallerCombo) => {
combos.push([currentOption].concat(smallerCombo));
});
});
return combos;
}
const main = arg => {
arg = arg.trim().split("\n");
const N = parseInt(arg[0]);
const names = arg.slice(1, N + 1).filter(n => {
if(n[0] === "M" ||
n[0] === "A" ||
n[0] === "R" ||
n[0] === "C" ||
n[0] === "H") {
return true;
}
});
if(!names.length) {
console.log(0);
return;
}
const initial = names.map(n=>n[0]);
const iniSet = new Set(initial);
const duplicate = (names.length - [...iniSet].length) * 2;
let allComb = combineWithoutRepetitions(names, 3);
console.log(allComb.length - (names.length - duplicate));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8')); |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 = "MARCH"
cnt = [0, 0, 0, 0, 0]
for i in range(n):
name = input()
for j in range(len(s)):
if name[0] == s[j]:
cnt[j] += 1
cnt = [c for c in cnt if c > 0]
if len(cnt) < 3:
print(0)
elif len(cnt) == 3:
print(cnt[0]*cnt[1]*cnt[2])
elif len(cnt) == 4:
ans = 0
for i in range(4):
ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
print(ans)
else:
ans = 0
for i in range(5):
cnt_4 =[cnt[_] for _ in range(5) if _ != i]
for j in range(4):
ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
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 | //Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
if(x==0)
return "0";
string ret="";
while(x){
ret=ret+(char)(x%10+'0');
x/=10;
}
reverse(ret.begin(),ret.end());
return ret;
}
string add(string a,string b){
if(a=="")
a="0";
if(b=="")
b="0";
if(a.length()<b.length())
swap(a,b);
while(b.length()<a.length()){
b='0'+b;
}
for(int i=0;i<a.length();i++){
a[i]=a[i]+(b[i]-'0');
}
bool big=false;
for(int i=a.length()-1;i>=0;i--){
if(big){
a[i]++;
}
big=false;
if(a[i]>'9'){
a[i]=a[i]-10;
big=true;
}
}
if(big)
a='1'+a;
return a;
}
string mul(string a,string b){
vector<int> va,vb;
if(a=="0" || b=="0")
return "0";
string ans;
for(int i=0;i<a.length();i++){
va.push_back(a[i]-'0');
}
for(int i=0;i<b.length();i++){
vb.push_back(b[i]-'0');
}
reverse(va.begin(),va.end());
reverse(vb.begin(),vb.end());
vector<int> res;
res.clear();
res.resize(1005);
for(int i=0;i<a.length();i++){
for(int j=0;j<b.length();j++){
res[i+j]+=(va[i]*vb[j]);
}
}
for(int i=0;i<1005;i++){
if(res[i]>9){
res[i+1]+=(res[i]/10);
res[i]%=10;
}
}
for(int i=0;i<1005;i++){
ans+=(res[i]+'0');
}
reverse(ans.begin(),ans.end());
int k=0;
while(ans[k]=='0'){
k++;
}
ans=ans.substr(k);
return ans;
}
bool is_prime(int n){
if(n<2)
return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return false;
return true;
}
ll c(ll n,ll k){
if(n==0 || n<k)
return 0;
if(n==k || k==0)
return 1;
else
return c(n-1,k)+c(n-1,k-1);
}
int n;
string s;
int a[10],b[10];
ll ans;
int main(){
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>s;
if(s[0]=='M')
a['M']++;
if(s[0]=='A')
a['A']++;
if(s[0]=='R')
a['R']++;
if(s[0]=='C')
a['C']++;
if(s[0]=='H')
a['H']++;
}
b[1]=a['M'];
b[2]=a['A'];
b[3]=a['R'];
b[4]=a['C'];
b[5]=a['H'];
ans+=c(b[1],3)+c(b[2],3)+c(b[3],3)+c(b[4],3)+c(b[5],3)+
b[1]*b[2]*b[3]+b[1]*b[2]*b[4]+b[1]*b[2]*b[5]+b[1]*b[3]*b[4]+b[1]*b[3]*b[5]+b[1]*b[4]*b[5]+
b[2]*b[3]*b[4]+b[2]*b[3]*b[5]+b[3]*b[4]*b[5];
cout<<ans;
//system("pause");
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import numpy as np
num=int(input())
#valid=["M","A","R","C","H"]
arr=np.zeros(5)
#print(arr)
for i in range(num):
chara=list(input())[0]
if chara == "M":
arr[0]+=1
if chara == "A":
arr[1]+=1
if chara == "R":
arr[2]+=1
if chara == "C":
arr[3]+=1
if chara == "H":
arr[4]+=1
ans=0
for i in range(3):
for k in range(3-i):
for j in range(3-k-i):
ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]
print(arr[i]*arr[1+i+k]*arr[2+i+k+j])
print(int(ans))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderBS
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string[] nameList = new string[n];
string[] threeNames = new string[3];
string checkFirst = "MARCH";
int pair = 0;
int nListSize = 0;
for (int i = 0; i < n; i++)
{
string check = "";
check = Console.ReadLine();
if (checkFirst.IndexOf(check[0]) != -1)
{
nameList[nListSize] = check;
nListSize++;
}
}
for (int j = 0; j < nListSize - 2; j++)
{
for (int k = j + 1; k < nListSize - 1; k++)
{
for (int l = k + 1; l < nListSize; l++)
{
threeNames[0] = nameList[j];
threeNames[1] = nameList[k];
threeNames[2] = nameList[l];
if (threeNames[0][0] != threeNames[1][0] &&
threeNames[0][0] != threeNames[2][0] &&
threeNames[1][0] != threeNames[2][0])
{
pair++;
}
}
}
}
Console.Write(pair);
Console.Read();
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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 count[5];
int combine[10][3] = {{0, 1, 2}, {0, 1, 3}, {0, 1, 4}, {0, 2, 3}, {0, 2, 4},
{0, 3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}};
int main() {
int n, ans;
char str[15];
while (~scanf("%d", &n)) {
ans = 0;
for (int i = 0; i < 4; i++) count[i] = 0;
for (int i = 0; i < n; i++) {
scanf("%s", str);
if (str[0] == 'M')
count[0]++;
else if (str[0] == 'A')
count[1]++;
else if (str[0] == 'R')
count[2]++;
else if (str[0] == 'C')
count[3]++;
else if (str[0] == 'H')
count[4]++;
else
continue;
}
for (int i = 0; i < 9; i++) {
ans += count[combine[i][0]] * count[combine[i][1]] * count[combine[i][2]];
}
printf("%d\n", ans);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<char, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
mp[s[0]]++;
}
long long ans = 0;
ans += mp['M'] * mp['A'] * mp['R'];
ans += mp['M'] * mp['A'] * mp['C'];
ans += mp['M'] * mp['A'] * mp['H'];
ans += mp['M'] * mp['R'] * mp['C'];
ans += mp['M'] * mp['R'] * mp['H'];
ans += mp['M'] * mp['C'] * mp['H'];
ans += mp['A'] * mp['R'] * mp['C'];
ans += mp['A'] * mp['R'] * mp['H'];
ans += mp['A'] * mp['C'] * mp['H'];
ans += mp['R'] * mp['C'] * mp['H'];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
char a[100000][10];
int b, h = 0;
int c = 0, d = 0, e = 0, f = 0, g = 0;
cin >> b;
for (int i = 0; i < b; i++) cin >> a[i];
for (int i = 0; i < b; i++) {
if (a[i][0] == 'M') c++;
if (a[i][0] == 'A') d++;
if (a[i][0] == 'R') e++;
if (a[i][0] == 'C') f++;
if (a[i][0] == 'H') g++;
}
h = c * d * e + c * d * f + c * d * g + c * e * f + c * e * g + c * f * g +
d * e * f + d * e * g + d * f * g + e * f * g;
cout << h << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
int n;
cin >> n;
int march[5] = {};
int A[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int B[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int C[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') march[0]++;
if (s[0] == 'A') march[1]++;
if (s[0] == 'R') march[2]++;
if (s[0] == 'C') march[3]++;
if (s[0] == 'H') march[4]++;
}
ll res = 0;
for (int i = 0; i < 10; i++) {
res += march[A[i]] * march[B[i]] * march[C[i]];
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
long long ans;
int s[10];
char str[50];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", &str);
if (str[0] == 'M') s[1]++;
if (str[0] == 'A') s[2]++;
if (str[0] == 'R') s[3]++;
if (str[0] == 'C') s[4]++;
if (str[0] == 'H') s[5]++;
}
for (int i = 1; i <= 5; i++)
for (int j = i + 1; j <= 5; j++)
for (int k = j + 1; k <= 5; k++) ans += s[i] * s[j] * s[k];
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long i, j, n, ans = 0;
int m = 0, a = 0, r = 0, c = 0, h = 0;
string s[100001];
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n; i++) {
if (s[i][0] == 'M') {
m++;
}
if (s[i][0] == 'A') {
a++;
}
if (s[i][0] == 'R') {
r++;
}
if (s[i][0] == 'C') {
c++;
}
if (s[i][0] == 'H') {
h++;
}
}
ans = (m * a * r) + (m * a * c) + (m * a * h) + (m * r * c) + (m * r * h) +
(m * c * h) + (a * r * c) + (a * r * h) + (a * c * h) + (r * c * h);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, cnt[5] = {0};
long long int ans = 0;
char str[16];
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%s", str);
switch (str[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
default:
break;
}
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
string key = "MARCH";
vector<int> c(5);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == key[j]) c[j]++;
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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() {
int32_t n;
cin >> n;
int64_t m, a, r, c, h;
m = a = r = c = h = 0;
for (int32_t i = 0; i < n; i++) {
string s;
cin >> s;
switch (s.at(0)) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
}
}
int64_t answer = m * a * (r + c + h) + m * r * (c + h) + m * c * h +
a * r * (c + h) + r * c * h;
cout << answer << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const int MAX = 10000;
static const long long INFTY = 1e12;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
long long conv3(long long x) { return x * (x - 1) * (x - 2) / (6); }
long long conv2(long long x) { return x * (x - 1) / (2); }
int main() {
long long N;
cin >> N;
map<char, long long> name;
for (int i = 0, i_len = (N); i < i_len; ++i) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
name[s[0]]++;
}
}
if (name.size() <= 2) {
cout << 0 << endl;
return 0;
}
long long c = conv3(name.size());
for (auto itr = name.begin(); itr != name.end(); itr++) {
if (itr->second > 1) {
c += (itr->second - 1) * conv2(name.size() - 1);
}
}
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 | cpp | #include <bits/stdc++.h>
using namespace std;
long long ans;
int main() {
long long n, f[10], i, g;
ans = g = 0;
char a[15];
memset(f, 0, sizeof(f));
scanf("%lld", &n);
for (i = 0; i < n; i++) {
scanf("%s", a);
if (a[0] == 'A')
f[1] += 1;
else if (a[0] == 'M')
f[2] += 1;
else if (a[0] == 'R')
f[3] += 1;
else if (a[0] == 'H')
f[4] += 1;
else if (a[0] == 'C')
f[5] += 1;
}
ans = f[1] * f[2] * f[3] + f[1] * f[2] * f[4] + f[1] * f[2] * f[5] +
f[2] * f[3] * f[4] + f[2] * f[3] * f[5] + f[1] * f[3] * f[4] +
f[1] * f[3] * f[5];
+f[1] * f[4] * f[5] + f[2] * f[4] * f[5] + f[3] * f[4] * f[5];
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M')
m++;
else if (S[0] == 'A')
a++;
else if (S[0] == 'R')
r++;
else if (S[0] == 'C')
c++;
else if (S[0] == 'H')
h++;
else
continue;
}
int ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + r * c * h + a * c * h;
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, j, k, ans = 0, march[5] = {0, 0, 0, 0, 0};
string s;
cin >> n;
for (i = 0; cin >> s; i++) {
if (s[0] == 'M') march[0]++;
if (s[0] == 'A') march[1]++;
if (s[0] == 'R') march[2]++;
if (s[0] == 'C') march[3]++;
if (s[0] == 'H') march[4]++;
}
for (i = 0; i < 5; i++) {
for (j = i + 1; j < 5; j++) {
for (k = j + 1; k < 5; k++) {
if (march[i] > 0 && march[j] > 0 && march[k] > 0) {
ans += march[i] * march[j] * march[k];
}
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
long long count[5] = {};
string S;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
if (S[0] == 'M')
count[0]++;
else if (S[0] == 'A')
count[1]++;
else if (S[0] == 'R')
count[2]++;
else if (S[0] == 'C')
count[3]++;
else if (S[0] == 'H')
count[4]++;
}
int sum = 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];
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;
const int maxn = 1e5 + 5;
string s[maxn];
int main() {
int n;
cin >> n;
int ans = 1, sum[5], vis[5], cnt = 0;
memset(sum, 0, sizeof(sum));
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++) {
cin >> s[i];
if (s[i][0] == 'M') {
sum[0]++;
if (!vis[0]) {
cnt++;
vis[0] = 1;
}
} else if (s[i][0] == 'A') {
sum[1]++;
if (!vis[1]) {
cnt++;
vis[1] = 1;
}
} else if (s[i][0] == 'R') {
sum[2]++;
if (!vis[2]) {
cnt++;
vis[2] = 1;
}
} else if (s[i][0] == 'C') {
sum[3]++;
if (!vis[3]) {
cnt++;
vis[3] = 1;
}
} else if (s[i][0] == 'H') {
sum[4]++;
if (!vis[4]) {
cnt++;
vis[4] = 1;
}
}
}
if (cnt < 3) {
cout << "0" << endl;
return 0;
} else if (cnt == 3) {
for (int i = 0; i < 5; i++)
if (sum[i] != 0) ans *= sum[i];
} else if (cnt == 4) {
int a[4];
int k = 0;
for (int i = 0; i < 4 && sum[i] != 0; i++) a[k++] = sum[i];
ans = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[2] * a[3] +
a[1] * a[2] * a[3];
} else if (cnt == 5) {
ans = sum[0] * sum[1] * sum[2] + sum[0] * sum[1] * sum[3] +
sum[0] * sum[1] * sum[4] + sum[0] * sum[2] * sum[3] +
sum[0] * sum[2] * sum[4] + sum[0] * sum[3] * sum[4] +
sum[1] * sum[2] * sum[3] + sum[1] * sum[2] * sum[4] +
sum[2] * sum[3] * sum[4] + sum[1] * sum[3] * sum[4];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]
for name in name_list:
if name[0] in char_list:
count_list[char_list.index(name[0])] += 1
score=0
for x in range(len(count_list)):
for y in range(x+1,len(count_list)):
for z in range(y+1,len(count_list)):
score+=count_list[x]*count_list[y]*count_list[z]
print(score)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string a[100000];
int b[5] = {0};
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
if (a[i][0] == 'M') b[0]++;
if (a[i][0] == 'A') b[1]++;
if (a[i][0] == 'R') b[2]++;
if (a[i][0] == 'C') b[3]++;
if (a[i][0] == 'H') b[4]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += b[i] * b[j] * b[k];
}
}
}
cout << sum << endl;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.