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; const long long mod = 1000000007; const long long INF = mod * mod; const int INF_N = 1e+9; const long double eps = 1e-12; const long double pi = acos(-1.0); long long mod_pow(long long a, long long n, long long m) { long long res = 1; while (n) { if (n & 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } struct modint { long long n; modint() : n(0) { ; } modint(long long m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((long long)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } long long inv(long long a, long long p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; void solve() { int N; cin >> N; vector<int> a(5, 0); 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]++; } long long res = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { res += a[i] * a[j] * a[k]; } } } cout << res << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string s = "MARCH"; int c[5] = {0}; int n; cin >> n; for (int i = 0; i < (n); i++) { string t; cin >> t; for (int j = 0; j < 5; j++) { if (t[0] == s[j]) { c[j]++; } } } int ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += c[i] * c[j] * c[k]; } } } cout << ans << endl; 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 vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vll = vector<long long>; using vvll = vector<vector<long long>>; using vvvll = vector<vector<vector<long long>>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vvvd = vector<vector<vector<double>>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vs = vector<string>; using pint = pair<int, int>; using Graph = vvi; string s = "MARCH"; int c[5] = {0}; int main() { int n; cin >> n; for (int i = 0; i < (int)(n); i++) { string t; cin >> t; for (int j = 0; j < (int)(5); j++) { if (t[0] == s[j]) c[j]++; } } long long ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += c[i] * c[j] * c[k]; } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; else return GCD(b, a % b); } bool sosuu_check(int num) { int i; for (i = 2; i <= sqrt(num); ++i) { if (num % i == 0) return false; } return (num < 2) ? false : true; } int main() { unsigned long long ans; string s; int N, i, m, a, r, c, h; m = a = r = c = h = 0; cin >> N; for (i = 0; i < (N); ++i) { cin >> s; if (s[0] == 'M') m++; if (s[0] == 'A') a++; if (s[0] == 'R') r++; if (s[0] == 'C') c++; if (s[0] == 'H') h++; } ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h; cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #include <iostream> #include <cmath> #include <climits> #include <stdio.h> #include <stdlib.h> #include <vector> #include <string> #include <stack> #include <algorithm> #include <map> #include <numeric> #include <set> #include <queue> #include <bitset> using namespace std; #define ll long long #define ld long double #define pi 3.14159265359; // %llu %lf // double result = 0; // printf("%.12f\n", result); // v:vector type:型 order:greater(大きい順) or less(小さい順) #define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0) /* ◆pairでもソートは可能 vector<pair<int32_t, int32_t>> pr(n); sort(pr.begin(), pr.end(),_compare); bool _compare(pair<int32_t, int32_t> a, pair<int32_t, int32_t> b) { #if 0 // first での sort #if 0 // 昇順 if (a.first != b.first) { return a.first < b.first; } // secondが同じならfirstでソート return a.second < b.second; #else // 降順 if (a.first != b.first) { return a.first > b.first; } // secondが同じならfirstでソート return a.second > b.second; #endif #else // second での sort #if 1 // 昇順 if (a.second != b.second) { return a.second < b.second; } // secondが同じならfirstでソート return a.first < b.first; #else // 降順 if (a.second != b.second) { return a.second > b.second; } // secondが同じならfirstでソート return a.first > b.first; #endif #endif } */ // vector 要素の総和算出 // v:vector default_value:初期値 #define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value ) /* int32_t n = 21; ---------------------------- int32_t sum = 0; for (int32_t i = 1; i <= n; i++) { sum += i; } ---------------------------- ↑と同じ結果が得られる ---------------------------- sum = n * (n + 1) / 2; ---------------------------- */ // vector 最大値( return ite ) #define _max_element(v) max_element(v.begin(),v.end()) // vector 最小値( return ite ) #define _min_element(v) min_element(v.begin(),v.end()) // vector 最大値が格納されている要素値 #define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end())) // 特定コンテナの中から特定の値をカウントする #define _count(v,value) count(v.begin(),v.end(),value) //set<uint32_t> member; // 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1 // member.emplace(2)とかも同じ member.size()で確認すると同じ値の挿入ではサイズ変化はない //multiset<uint32_t> v; // 重複するデータも保持する事はできる member.insert(2) member.insert(2) ⇒ member.count(2)は2 // 丸め #define _round(v) round(v) // 2乗 / 3乗 #define _square(v) pow(v,2) #define _cube(v) pow(v,3) // 大小判定 #define _max(x,y) max(x,y) #define _min(x,y) min(x,y) 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; } // string ⇒ int #define _stringtoi(s) stoi(s) // double 平方根 #define _sqrt(x) sqrt(x) // double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4 #define _ceil(x) ceil(x) // 指定された要素 【以上の】  値が現れる最初の位置のイテレータを取得する #define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min) // 指定された要素 【より大きい】値が現れる最初の位置のイテレータを取得する #define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min) // 順列 n個の数が与えられる // 0,1,2,...,n-1 // 全ての並べ方を1行ごとに出力する // ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0 /* do { for (auto num : v) { printf("%d ", num); } printf("\n"); } while (next_permutation(v.begin(), v.end())) // ※ 昇順である必要がある // ※ pair も pair.firstで可能 */ // ■bitset // 100 桁の 2 進数を定義する。 // bitset<100> bs; // // 8桁 の 2進数を定義し、10進数 131で初期化 // bitset<8> bs(131); // 7 ビット目から 0 ビット目への順番で、10000011 になる // // 8桁 の 2進数を定義し、2進数で初期化 // bitset<8> bs("10000011"); // 7 ビット目から 0 ビット目への順番で、10000011 となる。 // string _bs; cin >> _bs; bitset<100> bs(_bs); _bs = "10000011"であれば上記と同様 // // 与えられる数値について、それぞれの和を算出する場合 // 下記コードでビットが立っている要素値=和の値となる // ex.) AGC 020 C https://atcoder.jp/contests/agc020/tasks/agc020_c // bitset<1000> dp; // p[0] = 1; // for (int i = 0; i < N; ++i) { // dp |= (dp << A[i]); // } // 絶対値 template<typename T> static T _abs(const T x) { return (x > 0 ? x : -x); } // 最大公約数 int64_t gcd(int64_t a, int64_t b) { while (b) { int64_t c = b; b = a % b; a = c; } return a; } // 最小公倍数 int64_t lcm(int64_t a, int64_t b) { if (!a || !b) return 0; return a * b / gcd(a, b); } // 多次元 std::vector 生成 template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2); // // 2次元 vector の初期化 // vector< vector<int> > s( n, vector<int>(m, 0) ); // pair // vector<vector<pair<int32_t,int32_t>>> f(n); // ⇒ 挿入 f[i].push_back(make_pair(x, y)); ////////////////////////////////////////////////// // ABC 146 C Buy an Integer // 10進桁数算出 int32_t digit(int64_t a) { int32_t digit_count = 0; while (a > 0) { a /= 10; digit_count++; } return digit_count; } // 2分探索 int64_t a, b; int64_t x; int64_t find_binary_search(bool is_upper, int64_t left, int64_t right) { int64_t mid; while (right - left > 1) { mid = (left + right) / 2; if ((a*mid) + (b*digit(mid)) > x) { right = mid; } else { left = mid; } } if (is_upper) { return right; } return left; } ////////////////////////////////////////////////// // Union Find Tree class UnionFind { public: vector <int32_t> par; // 各元の親を表す配列 vector <int32_t> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor 初期では親は自分自身 UnionFind(int32_t sz_) : par(sz_), siz(sz_, 1LL) { for (int32_t i = 0; i < sz_; ++i) par[i] = i; } void init(int32_t sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (int32_t i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Find int32_t root(int32_t x) { // x の親の親を x の親とする while (par[x] != x) { x = par[x] = par[par[x]]; // printf("%d\n", x); } return x; } // Union(Unite, Merge) bool merge(int32_t x, int32_t y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } // 連結判定 bool is_same(int32_t x, int32_t y) { return root(x) == root(y); } // 素集合のサイズ int32_t size(int32_t x) { return siz[root(x)]; } // 参照 void view(void) { for (size_t i = 0; i < par.size(); i++) { printf("%d\n", par[i]); } } }; // ■ // UINT32_MAX // 4294967295 ≒ 4 * 1e9 // ■ // 割り算した結果との比較での丸め対処時 // ABC 161 B // https://atcoder.jp/contests/abc161/tasks/abc161_b // double border = _sum(v, 0 / (double)(4 * m); // ↓ // uint32_t border = (_sum(v, 0) + (4 * m) - 1) / (4 * m); // ■ // l~r 間でdで割り切れる数の個数 // r/d - (l-1)/d; // ■ // 和がKの倍数である数の組が存在する時、それぞれの数の mod Kの和はKの倍数 // という考え方がよく出てくるみたい。数式で表すと、 // // ( a + b + ... ) % K = 0 のとき、a % K + b % K +... = nK (n=1,2,...) /*************************************************************/ // ABC 089 // C - March // https://atcoder.jp/contests/abc089/tasks/abc089_c /* ■問題文 N 人の人がいて、i 番目の人の名前は Si です。 この中から、以下の条件を満たすように 3 人を選びたいです。 ・全ての人の名前が M,A,R,C,H のどれかから始まっている ・同じ文字から始まる名前を持つ人が複数いない これらの条件を満たすように 3 人を選ぶ方法が何通りあるか、求めてください。ただし、選ぶ順番は考えません。 答えが 32 bit整数型に収まらない場合に注意してください。 ■制約 ・1 ≤ N ≤ 1e5 ・Si は英大文字からなる ・1 ≤ |Si| ≤ 10 ・Si≠Sj(i≠j) ■入力 N S1 : SN ■出力 与えられた条件を満たすように 3 人を選ぶ方法が x 通りのとき、x を出力せよ。 ■入力例 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI ■出力例 2 次のような名前の 3 人を選ぶと良いです。 ・MASHIKE,RUMOI,HABORO ・MASHIKE,RUMOI,HOROKANAI よって、2 通りとなります。 */ int main() { #if 1 int32_t n; cin >> n; string temp; map<char, int32_t> mp; for (int32_t i = 0; i < n; i++) { cin >> temp; if (temp[0] != 'M' && temp[0] != 'A' && temp[0] != 'R' && temp[0] != 'C' && temp[0] != 'H') { continue; } mp[temp[0]]++; } if (mp.empty()) { printf("0\n"); return 0; } char list[] = { 'M','A','R','C','H' }; int64_t result = 0; for (int32_t i = 0; i < 5 - 2; i++) { for (int32_t j = i + 1; j < 5 - 1; j++) { for (int32_t k = j + 1; k < 5; k++) { result += mp[list[i]] * mp[list[j]] * mp[list[k]]; } } } cout << result << endl; return 0; #else // TLEで NG コード int32_t n; cin >> n; string temp; vector<string> v; vector<int32_t> arr; for (int32_t i = 0; i < n; i++) { cin >> temp; if (temp[0] != 'M' && temp[0] != 'A' && temp[0] != 'R' && temp[0] != 'C' && temp[0] != 'H') { continue; } v.push_back(temp); arr.push_back(0); } if (v.empty()) { printf("0\n"); return 0; } for (int32_t i = 0; i < 3; i++) { arr[arr.size()-1 - i] = 3-i; } int64_t result = 0; vector<vector<string>> all; do { //for (size_t i = 0; i < arr.size(); i++) { // printf("%d ", arr[i]); //} //printf("\n"); map<char, int32_t> mp; vector<string>temp; size_t i; for (i = 0; i < arr.size(); i++) { if (!arr[i]) { continue; } char c = v[i][0]; if (mp[c]) { break; } mp[c]++; temp.push_back(v[i]); //printf("%s\n", v[i].c_str()); } //printf("\n"); if (i >= arr.size()) { sort(temp.begin(), temp.end()); auto ite = find(all.begin(), all.end(), temp); if (ite == all.end()) { all.push_back(temp); result++; } } } while (next_permutation(arr.begin(), arr.end())); cout << result << endl; return 0; #endif } // プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー // プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー // 作業を開始するためのヒント: // 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します // 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します // 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します // 4. エラー一覧ウィンドウを使用してエラーを表示します // 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します // 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\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> freq; for (int i = 0; i < n; i++) { string s; cin >> s; freq[s[0]]++; } long ans = 0; vector<int> choices; for (char c : {'M', 'A', 'R', 'C', 'H'}) choices.push_back(freq[c]); for (int i = 0; i <= choices.size() - 3; i++) for (int j = i + 1; j <= choices.size() - 2; j++) for (int k = j + 1; k <= choices.size() - 1; k++) { ans += choices[i] * choices[j] * choices[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; const int INF = 1 << 30; const int MOD = (int)1e9 + 7; const int MAX_N = (int)1e5 + 5; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; } void solve() { int n; cin >> n; map<char, int> mp; const string key = "MARCH"; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < key.size(); j++) { if (s.front() == key[j]) mp[s.front()]++; } } ll ans = 0; for (int bit = 0; bit < (1 << (int)key.size()); bit++) { if (__builtin_popcount(bit) != 3) continue; ll cnt = 1; for (int i = 0; i < key.size(); i++) { if (bit & (1 << i)) { cnt *= (ll)mp[key[i]]; cnt %= MOD; } } ans += cnt; ans %= MOD; } cout << ans << endl; } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python2
import os,sys import itertools if __name__ == "__main__": n = int(raw_input()) t = [] for i in range(n): t.append(raw_input()) c = list(itertools.combinations(t,3)) #print(c) result = 0 for comb in c: march_list = {} for k in "MARCH": march_list[k] = 0 for i in range(3): try: march_list[comb[i][0]] += 1 except: pass c_sum = 0 is_ok = True for k,v in march_list.items(): c_sum += v if v >= 2: is_ok = False if c_sum != 3: is_ok = False if is_ok: result += 1 print(result)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int inf = 1e9 + 7; int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; int dx[] = {1, -1, 0, 0, -1, 1, 1, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); map<char, int> mp; int n; cin >> n; string can = "MARCH"; for (int i = 0; i < n; ++i) { string s; cin >> s; for (int j = 0; j < can.size(); ++j) { if (s[0] == can[j]) { mp[s[0]]++; } } } if (mp.size() <= 2) { cout << 0 << endl; return 0; } else if (mp.size() == 3) { long long ans = 1; for (auto e : mp) { ans *= (long long)e.second; } cout << ans << endl; return 0; } else if (mp.size() == 4) { long long ans = 0; ans += (long long)mp['M'] * mp['A'] * mp['R']; ans += (long long)mp['M'] * mp['A'] * mp['C']; ans += (long long)mp['M'] * mp['A'] * mp['H']; ans += (long long)mp['M'] * mp['R'] * mp['C']; ans += (long long)mp['M'] * mp['R'] * mp['H']; ans += (long long)mp['M'] * mp['C'] * mp['H']; ans += (long long)mp['A'] * mp['R'] * mp['C']; ans += (long long)mp['A'] * mp['R'] * mp['H']; ans += (long long)mp['A'] * mp['C'] * mp['H']; ans += (long long)mp['R'] * mp['C'] * mp['H']; cout << ans << endl; } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } long long nCr(long long n, long long r) { if (n == r) return 1; if (n - r < r) r = n - r; if (r == 0) return 0; if (r == 1) return n; long long res = 1; for (long long i = 1; i <= r; i++) { res *= n--; res /= i; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long N; cin >> N; vector<int> cnt(5, 0); for (int i = 0; i < (int)(N); i++) { string S; cin >> S; if (S[0] == 'M') cnt[0]++; if (S[0] == 'A') cnt[1]++; if (S[0] == 'R') cnt[2]++; if (S[0] == 'C') cnt[3]++; if (S[0] == 'H') cnt[4]++; } long long res = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { res += cnt[i] * cnt[j] * cnt[k]; } } } 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 main() { int N; cin >> N; string IN; int num[5] = {}; for (int i = 0; i < N; i++) { cin >> IN; if (IN[0] == 'M') num[0]++; if (IN[0] == 'A') num[1]++; if (IN[0] == 'R') num[2]++; if (IN[0] == 'C') num[3]++; if (IN[0] == 'H') num[4]++; } long long ans = 0; ans += num[0] * num[1] * num[2]; ans += num[0] * num[1] * num[3]; ans += num[0] * num[1] * num[4]; ans += num[0] * num[2] * num[3]; ans += num[0] * num[2] * num[4]; ans += num[0] * num[3] * num[4]; ans += num[1] * num[2] * num[3]; ans += num[1] * num[2] * num[4]; ans += num[1] * num[3] * num[4]; ans += num[2] * num[3] * num[4]; cout << ans << endl; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; map<char, int> m; long long a[10]; int main() { int n, sum; while (cin >> n) { m.clear(); sum = 0; string str; while (n--) { cin >> str; char c = str[0]; if (!m[c]) { sum++, m[c]++; } else { m[c]++; } } int i = 0; if (m['M']) a[++i] = m['M']; if (m['A']) a[++i] = m['A']; if (m['R']) a[++i] = m['R']; if (m['C']) a[++i] = m['C']; if (m['H']) a[++i] = m['H']; if (sum == 3) { cout << a[1] * a[2] * a[3] << endl; } else if (sum == 4) { long long ans = a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[3] * a[4] + a[2] * a[3] * a[4]; cout << ans << endl; } else if (sum == 5) { long long ans = a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[2] * a[5] + a[1] * a[3] * a[4] + a[1] * a[3] * a[5] + a[1] * a[4] * a[5] + a[2] * a[3] * a[4] + a[2] * a[3] * a[5] + a[2] * a[4] * a[5] + a[3] * 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 main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < (int)(n); i++) cin >> s[i]; vector<int> c1 = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2}; vector<int> c2 = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3}; vector<int> c3 = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4}; vector<int> c(5); for (int i = 0; i < (int)(n); i++) { if (s[i][0] == 'M') c[0]++; if (s[i][0] == 'A') c[1]++; if (s[i][0] == 'R') c[2]++; if (s[i][0] == 'C') c[3]++; if (s[i][0] == 'H') c[4]++; } long long int ans = 0; for (int i = 0; i < (int)(11); i++) { ans += c[c1[i]] * c[c2[i]] * c[c3[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() { string a[100000]; int b, h; 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].find("M") == 0) c++; if (a[i].find("A") == 0) d++; if (a[i].find("R") == 0) e++; if (a[i].find("C") == 0) f++; if (a[i].find("H") == 0) g++; } h = c * d * e + c * d * f + c * d * g + d * e * f + d * e * 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 namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> v(5, 0); for (ll i = 0; i < ll(N); i++) { string s; cin >> s; if (s[0] == 'M') v[0]++; if (s[0] == 'A') v[1]++; if (s[0] == 'R') v[2]++; if (s[0] == 'C') v[3]++; if (s[0] == 'H') v[4]++; } ll sum = 0; for (ll i = 0; i < ll(5); i++) for (ll j = 0; j < ll(5); j++) for (ll k = 0; k < ll(5); k++) if (i != j && j != k && k != i) sum += v[i] * v[j] * v[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; int main() { int n; cin >> n; vector<vector<string> > vec(6); for (int i = 0; i < int(n); i++) { string s; cin >> s; if (s[0] == 'M') vec.at(0).push_back(s); else if (s[0] == 'A') vec.at(1).push_back(s); else if (s[0] == 'R') vec.at(2).push_back(s); else if (s[0] == 'C') vec.at(3).push_back(s); else if (s[0] == 'H') vec.at(4).push_back(s); else vec.at(5).push_back(s); } int res = 0; for (int bit = 1; bit < (1 << 5); bit++) { vector<int> s; for (int i = 0; i < int(5); i++) { if (bit & (1 << i)) s.push_back(i); } if (s.size() == 3) { int num = 1; for (int i = 0; i < (int)s.size(); i++) { num *= vec.at(s.at(i)).size(); } res += num; } } 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
UNKNOWN
n = gets.to_i s = [] a = ['M', 'A', 'R', 'C', 'H'] cnt = 0 n.times do s << gets.chomp! end s.each_with_index do |ss, i| unless a.include?(s[i][0]) s.delete(ss) end end s.combination(3) do |i, j, k| h = [] h.push(i[0], j[0], k[0]) if h.uniq.size == 3 cnt += 1 end end p cnt
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long N; long long i = 0; long long M = 0; long long A = 0; long long R = 0; long long C = 0; long long H = 0; string name; set<char> not_zero = {}; cin >> N; while (i < N && cin >> name) { if (name.substr(0, 1) == "M") { ++M; not_zero.insert('M'); } else if (name.substr(0, 1) == "A") { ++A; not_zero.insert('A'); } else if (name.substr(0, 1) == "R") { ++R; not_zero.insert('R'); } else if (name.substr(0, 1) == "C") { ++C; not_zero.insert('C'); } else if (name.substr(0, 1) == "H") { ++H; not_zero.insert('H'); } ++i; } if (not_zero.size() < 3) { cout << 0 << endl; return 0; } map<char, long long> counts = { {'M', M}, {'A', A}, {'R', R}, {'C', C}, {'H', H}}; long long ans = 1; if (not_zero.size() == 3) { auto i = not_zero.begin(); while (i != not_zero.end()) { ans *= counts.at(*i); ++i; } } else if (not_zero.size() == 4) { vector<char> chars; auto i = not_zero.begin(); while (i != not_zero.end()) { chars.push_back(*i); ++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
UNKNOWN
fun main(args :Array<String>){ val N :Int = readLine()!!.toInt() val name : ArrayList<String> = ArrayList(N) var m :Int = 0 var a :Int = 0 var r :Int = 0 var c :Int = 0 var h :Int = 0 var sum :Int var ans :Int = 0 repeat(N){ name.add(readLine()!!) } for(i in name.indices){ if(name[i].get(0) == 'M'){ m++ } if(name[i].get(0) == 'A'){ a++ } if(name[i].get(0) == 'R'){ r++ } if(name[i].get(0) == 'C'){ c++ } if(name[i].get(0) == 'H'){ h++ } } //println("$m $a $r $c $h") val march : List<Int> = listOf(m ,a ,r ,c ,h) for(x in march.indices){ for(y in march.indices){ for(z in march.indices){ if(x != y && x != z && y != z){ sum = march[x] * march[y] * march[z] ans += sum sum = 0 } } } } println(ans / 6) }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using vi = std::vector<int>; using vvi = std::vector<std::vector<int>>; using vll = std::vector<long long int>; using vvll = std::vector<std::vector<long long int>>; using P = std::pair<int, int>; using vp = std::vector<P>; using namespace std; int comb(int n, int k) { int res = 1; for (int i = n; i > n - k; i--) res = res * i; for (int i = k; i > 0; i--) res = res / i; return res; } int main(void) { int n; cin >> n; vi a(5, 0); 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]++; } int m = 0; for (int i = 0; i < 5; i++) { if (a[i] != 0) m++; } if (m < 3) { cout << 0 << endl; return 0; } long long int ans = comb(m, 3); long long int b = comb(m - 1, 2); for (int i = 0; i < 5; i++) { if (a[i] == 0) continue; ans += b * (a[i] - 1); } cout << ans << endl; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import itertools N = int(input()) # 頭文字Mグループ、頭文字Aグループ、のように分割する # どの3つのグループから1人選ぶかを考える n_initial_MARCH = [0]*5 match_initial = ["M", "A", "R", "C", "H"] for _ in range(N): s = input() for idx in range(5): if s[0] == match_initial[idx]: n_initial_MARCH[idx] += 1 taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3)) ans = 0 for groups in taken_indices: ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[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; #define pb push_back #define mp make_pair #define int long long int q[200]; main(){ int n,i,c,k,l=0; cin>>n; string s; for (i=0;i<n;++i){ cin>>s; q[s[0]]++; } int r=1; c=q['M']+q['A']+q['R']+q['C']+q['H']; if (q['M']>1){ l+=q['A']+q['R']+q['C']+q['H']; } if (q['A']>1){ l+=q['M']+q['R']+q['C']+q['H']; } if (q['R']>1){ l+=q['M']+q['A']+q['C']+q['H']; } if (q['C']>1){ l+=q['M']+q['A']+q['R']+q['H']; } if (q['H']>1){ l+=q['M']+q['A']+q['R']+q['C']; } if (c-3>3){ k=1; int pr=0; for (i=c-2;i<=c;++i){ k*=i; if (k%6==0){ k/=6; pr=1; } } if (pr==0) r=6; } else { k=1; for (i=4;i<=c;++i){ k*=i; } for (i=2;i<=c-3;++i){ r*=i; } } if (k/r-l==1) cout <<0; else cout <<k/r-l; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\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.util.* fun main(args: Array<String>) { val sc = Scanner(System.`in`) val n = sc.nextInt() val counts = IntArray(5) while (sc.hasNext()) { val line = sc.nextLine().trim() if (line.isNotEmpty()) { when (line[0]) { 'M' -> ++counts[0] 'A' -> ++counts[1] 'R' -> ++counts[2] 'C' -> ++counts[3] 'H' -> ++counts[4] } } } var ret:Long = 0L for (i in 0 until 5 - 2) { for (j in i + 1 until 5 - 1) { for (k in j + 1 until 5 - 0) { ret += counts[i] * counts[j] * counts[k] } } } println(ret) }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import Data.List combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations n xs = [ y:ys | y:xs' <- tails xs , ys <- combinations (n-1) xs' ] main :: IO () main = do _ <- getLine s <- lines <$> getContents :: IO [String] let s' = combinations 3 [ head i | i <- s, head i `elem` "MARCH" ] print . length $ [ is | is <- s', 3 == (length . nub $ is)]
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ArCorder { class Program { class inner : IEquatable<inner> { string m_First; string m_Second; string m_Therd; public inner (string first, string second, string therd) { m_First = first; m_Second = second; m_Therd = therd; } public Boolean IsTarget() { if (m_First.First().Equals(m_Second.First()) || m_First.First().Equals(m_Therd.First()) || m_Second.First().Equals(m_Therd.First())) { return false; } else { return true; } } public bool Equals(inner obj) { return obj.GetHashCode() == this.GetHashCode(); } public override int GetHashCode() { return this.m_First.GetHashCode() ^ this.m_Second.GetHashCode() ^ this.m_Therd.GetHashCode(); } } static void Main() { int max = int.Parse(Console.ReadLine()); List<string> names = new List<string>(); for (int i = 0; i < max; i++) { names.Add(Console.ReadLine()); } List<string> targetNames = names.Where(x => x.StartsWith("M") || x.StartsWith("A") || x.StartsWith("R") || x.StartsWith("C") || x.StartsWith("H")).ToList(); List<inner> allPatern = new List<inner>(); foreach (string first in targetNames){ foreach(string second in targetNames.Where(x => !x.Equals(first))) { foreach (string therd in targetNames.Where(x => !x.Equals(first) && !x.Equals(second))) { allPatern.Add(new inner(first, second, therd)); } } } Console.WriteLine(allPatern.Where(x => x.IsTarget()).Distinct().LongCount()); } } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import java.util.Scanner object Main { def main(args: Array[String]): Unit = { val sc = new Scanner(System.in) val n = sc.nextInt() val a = Array(0, 0, 0, 0, 0) // m a r c h for(i <- 0 until n) { val s = sc.next() if (s.charAt(0) == 'M') { a(0) += 1 } else if (s.charAt(0) == 'A') { a(1) += 1 } else if (s.charAt(0) == 'R') { a(2) += 1 } else if (s.charAt(0) == 'C') { a(3) += 1 } else if (s.charAt(0) == 'H') { a(4) += 1 } } var ans = 0L for(i <- 0 until a.length) { for(j <- (i+1) until a.length) { for(k <- (j+1) until a.length) { ans += a(i)*a(j)*a(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 PRIME = 1000000007; const int INF = 2147483647; const double PI = acos(-1); const double EPS = 0.000000001; using namespace std; int main() { int i, n, cnts[5], cnt = 0; for (i = 0; i < 5; i++) cnts[i] = 0; cin >> n; for (i = 0; i < n; i++) { string tmp; cin >> tmp; if (tmp[0] == 'M') cnts[0]++; if (tmp[0] == 'A') cnts[1]++; if (tmp[0] == 'R') cnts[2]++; if (tmp[0] == 'C') cnts[3]++; if (tmp[0] == 'H') cnts[4]++; } for (int a = 0; a < n - 2; a++) { for (int b = a + 1; b < n - 1; b++) { for (int c = b + 1; c < n; c++) { cnt += cnts[a] * cnts[b] * cnts[c]; } } } 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; void slove(vector<string> &a, vector<string> &tres, long long &res, int pos) { if (tres.size() == 3) { set<char> b; for (int i = 0; i < 3; ++i) { b.insert(tres[i][0]); } if (b.size() == 3) ++res; return; } if (pos >= a.size()) return; slove(a, tres, res, pos + 1); tres.push_back(a[pos]); slove(a, tres, res, pos + 1); tres.pop_back(); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<string> a; --n; while (n >= 0) { string s; cin >> s; if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') a.push_back(s); --n; } vector<string> tres; long long res = 0; slove(a, tres, res, 0); cout << res; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
package main import ( "fmt" ) // var sc = bufio.NewScanner(os.Stdin) // func nextInt() int { // sc.Scan() // i, e := strconv.Atoi(sc.Text()) // if e != nil { // panic(e) // } // return i // } // func nextLine() string { // sc.Scan() // return sc.Text() // } func main() { // sc.Split(bufio.ScanWords) var n int fmt.Scan(&n) m := map[string]int{} var s string for i := 0; i < n; i++ { fmt.Scan(&s) m[s[:1]]++ } march := "MARCH" ans := 0 for i := 0; i < n; i++ { for j := i + 1; j < n; j++ { for k := j + 1; k < n; k++ { ans += m[march[i:i+1]] * m[march[j:j+1]] * m[march[k:k+1]] } } } fmt.Println(ans) }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import Counter def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) def combination(n, r, mod=10**9+7): r = min(r, n-r) res = 1 for i in range(r): res = res * (n - i) * modinv(i+1, mod) % mod return res n = int(readline()) s = [input()[0] for i in range(n)] memo = list(Counter(s).items()) check = ['M', 'A', 'R', 'C', 'H'] cnt = 0 ans = 0 cnt_v = 0 for x, y in memo: if x in check: ans += y if y > 1: cnt += 1 cnt_v += y print(combination(ans, 3) - (ans * cnt - cnt_v))
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long ans = 0; vector<int> lis(5, 0); for (int i = 0; i < n; i++) { string s; cin >> s; char c = s[0]; if (c == 'M') lis[0]++; else if (c == 'A') lis[1]++; else if (c == 'R') lis[2]++; else if (c == 'C') lis[3]++; else if (c == 'H') lis[4]++; } for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += lis[i] * lis[j] * lis[k]; } } } cout << ans << endl; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
n = gets.to_i names = "" while name = gets name = name[0] if name == "M" || name == "A" || name == "R" || name == "C" || name == "H" names += name end end count = 0 for i in 0..names.length-3 for j in i+1..names.length-2 if names[i] == names[j] next end for k in j+1..names.length-1 if names[i] == names[k] || names[j] == names[k] next end count += 1 end end end puts count
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int cnt = 0; char g[20]; string s[10010]; long long int ans = 1; int ini[5]; int main() { cin >> n; for (int i = (0); i < (n); i++) { cin >> g; if (g[0] == 'M') { ini[0]++; } if (g[0] == 'A') { ini[1]++; } if (g[0] == 'R') { ini[2]++; } if (g[0] == 'C') { ini[3]++; } if (g[0] == 'H') { ini[4]++; } } for (int i = (0); i < (5); i++) { if (ini[i] == 0) continue; ans *= pow(2, ini[i] - 1); } int c = 0; for (int i = (0); i < (5); i++) { if (ini[i] > 0) c++; } if (c < 3) { cout << 0 << endl; return 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
java
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Map<String, Integer> map = new HashMap<>(); map.put("M",0); map.put("A",0); map.put("R",0); map.put("C",0); map.put("H",0); for (int i = 0; i < n; i++){ String s = String.valueOf(sc.next().charAt(0)); if (map.containsKey(s)) { map.put(s, map.get(s) + 1); } } long sum = 0; sum += map.get("M")*map.get("A")*map.get("R"); sum += map.get("M")*map.get("A")*map.get("C"); sum += map.get("M")*map.get("A")*map.get("H"); sum += map.get("M")*map.get("R")*map.get("C"); sum += map.get("M")*map.get("R")*map.get("H"); sum += map.get("M")*map.get("C")*map.get("H"); sum += map.get("A")*map.get("R")*map.get("C"); sum += map.get("A")*map.get("R")*map.get("H"); sum += map.get("A")*map.get("C")*map.get("H"); sum += map.get("R")*map.get("C")*map.get("H"); System.out.println(sum); } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int A[5]; long long cal(void) { long long sum = 0; for (int i = 0; i < 3; ++i) { for (int j = i + 1; j < 4; ++j) { for (int k = j + 1; k < 5; ++k) { sum += A[i] * A[j] * A[k]; } } } return sum; } int main() { string s; int N; cin >> N; while (N--) { 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]; } cout << cal() << "\n"; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <stdio.h> #include <string.h> main() { long a[5] = {0,0,0,0,0}; int N; scanf("%d", &N); int k; for(k = 1; k <= N; k++); { char s[11]; scanf("%s", s); if(s[0] == 'M') a[0]++; if(s[0] == 'A') a[1]++; if(s[0] == 'R') a[2]++; if(s[0] == 'C') a[3]++; if(s[0] == 'H') a[4]++; } int O = 0; int s, t, r; for(s=1; s<=3; s++) {for(t=s+1; t<=4; t++) {for(r=s+2; r<=5; r++) O += a[s]*a[t]*a[r] } printf("%d", O); }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long s = 0; int n, i, a = 0, b = 0, c = 0, d = 0, e = 0; char arr; scanf("%d", &n); getchar(); for (i = 0; i < n; i++) { char tmp[15]; scanf("%s", tmp); getchar(); arr = tmp[0]; if (arr == 'M') e++; if (arr == 'A') a++; if (arr == 'R') b++; if (arr == 'C') c++; if (arr == 'H') d++; } s += a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e + b * c * d + b * c * e + b * d * e + c * d * e; printf("%d", s); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #include<algorithm> using namespace std; template <class T> using V = vector<T>; using ll = long long; using db = double; using st = string; using ch = char; using vll = V<ll>; using vpll =V<pair<ll,ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; #define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++) #define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--) #define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn,(a).en) #define REV(a) reverse((a).bgn,(a).en) #define M(a,b) max(a,b) #define rM(a,b) min(a,b) #define fi first #define se second #define sz size() #define gcd(a,b) __gcd(a,b) #define lcm(a,b) __lcm(a,b) #define co(a) cout<<a<<endl; #define ci(a) cin>>a; ll sum(ll n) { ll m=0; FOR(i,0,12){ m+=n%10; n/=10; } return m; } /****************************************\ | Thank you for viewing my code:) | | Written by RedSpica a.k.a. RanseMirage | | Twitter:@asakaakasaka | \****************************************/ signed main() { ll n; ci(n); vll A(5); FOR(i,0,n){ st s; ci(s); if(s[i]=='M'){ A[0]++; } else if(s[i]=='A'){ A[1]++; } else if(s[i]=='R'){ A[2]++; } else if(s[i]=='C'){ A[3]++; } else if(s[i]=='H'){ A[4]++; } } ll ans=0; FOR(i,0,4){ if(A[i]!==0){ if(ans==0){ ans++; } ans*=A[i]; } } co(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 MX = 100005, INF = 1001001001; const long long int LINF = 1e18; const double eps = 1e-10; const int DIV = 1e9 + 7; int n; vector<string> s; int main() { cin >> n; s.resize(n); for (int i = 0; i < (n); ++i) cin >> s[i]; map<char, set<string>> namesMap; for (int i = 0; i < (n); ++i) { namesMap[s[i][0]].insert(s[i]); } vector<int> candsNum; candsNum.push_back(namesMap['M'].size()); candsNum.push_back(namesMap['A'].size()); candsNum.push_back(namesMap['R'].size()); candsNum.push_back(namesMap['C'].size()); candsNum.push_back(namesMap['H'].size()); for (int v : candsNum) cout << v << " "; cout << endl; long long int ans = 0; for (int v1 = 0; v1 < 3; v1++) { for (int v2 = v1 + 1; v2 < 4; v2++) { for (int v3 = v2 + 1; v3 < 5; v3++) { ans += (candsNum[v1] * candsNum[v2] * candsNum[v3]); } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
fun main(args: Array<String>) { val n = readLine()!!.toInt() val l = (1 .. n).map{ readLine()!!.toString()} var ll = mutableListOf(0, 0, 0, 0, 0) for(i in 0 until n){ when(l[i][0]){ 'M' -> ll[0] += 1 'A' -> ll[1] += 1 'R' -> ll[2] += 1 'C' -> ll[3] += 1 'H' -> ll[4] += 1 } } var a = 0.toLong() for(i in 0 .. 2) for (j in i + 1..3) for (k in j + 1..4){ a += (ll[i] * ll[j] * ll[k]) } println(a) }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); Set<String> topM = new HashSet<>(); Set<String> topA = new HashSet<>(); Set<String> topR = new HashSet<>(); Set<String> topC = new HashSet<>(); Set<String> topH = new HashSet<>(); for (int i=0;i<N;i++){ String name = sc.next(); if (name.startsWith("M")){ topM.add(name); }else if (name.startsWith("A")){ topA.add(name); }else if (name.startsWith("R")){ topR.add(name); }else if (name.startsWith("C")){ topC.add(name); }else if (name.startsWith("H")){ topH.add(name); } } List<Set<String>> names = new ArrayList<>(); names.add(topM); names.add(topA); names.add(topR); names.add(topC); names.add(topH); double result = 0; for (int i=0;i<5;i++){ for (int j=i+1;j<5;j++){ for (int k=j+1;k<5;k++){ result += names.get(i).size() * names.get(j).size() * names.get(k).size(); } } } System.out.printf("%.0f", result); } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int main(void) { int n; long long int head[5] = {}; std::cin >> n; std::string s[n]; for (int i = 0; i < n; i++) { std::cin >> s[i]; switch (s[i][0]) { case 'M': head[0]++; break; case 'A': head[1]++; break; case 'R': head[2]++; break; case 'C': head[3]++; break; case 'H': head[4]++; break; } } long long int total = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { std::cout << head[i] << " " << head[j] << " " << head[k] << std::endl; std::cout << i << " " << j << " " << k << std::endl; total += head[i] * head[j] * head[k]; } } } std::cout << total << std::endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 2e9; int main() { vector<int> a(5, 0); string s; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s; switch (s[0]) { case 'M': a[0]++; break; case 'A': a[1]++; break; case 'R': a[2]++; break; case 'C': a[3]++; break; case 'H': a[4]++; break; } } long long ans = 0; for (int i = 0; i < 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
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); int N; cin >> N; string march = "MARCH"; int cnt[5] = {}; for (ll i = (0); i < (N); i++) { string S; cin >> S; for (ll j = (0); j < (5); j++) { if (S[0] == march[j]) cnt[j]++; } } ll ans = 0; for (ll i = (0); i < (3); i++) { for (ll j = (i + 1); j < (4); j++) { for (ll k = (j + 1); k < (5); k++) { ans += cnt[i] * cnt[j] * cnt[k]; } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> C(5, 0); for (int i = 0; i < N; ++i) { string s; cin >> s; char c = s[0]; if (c == 'M') { ++C[0]; } else if (c == 'A') { ++C[1]; } else if (c == 'R') { ++C[2]; } else if (c == 'C') { ++C[3]; } else if (c == 'H') { ++C[4]; } } int count = 0; for (unsigned int i = 0; i < 1 << 5; ++i) { if (__builtin_popcount(i) != 3) { continue; } int count_c = 1; for (int j = 0; j < 5; ++j) { if ((i & (1 << j)) != 0) { count_c *= C[j]; } } count += count_c; } cout << count << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt[5] = {0}; long long ans = 0; cin >> n; string s; for (int i = 0; i < n; i++) { cin >> s; if (s[0] == 'M') cnt[0]++; if (s[0] == 'A') cnt[1]++; if (s[0] == 'R') cnt[2]++; if (s[0] == 'C') cnt[3]++; if (s[0] == 'H') cnt[4]++; } for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += cnt[i] * cnt[j] * cnt[k]; } } } cout << ans << endl; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { int N; cin >> N; vector<int> num(5, 0); for (int i = 0; i < N; i++) { string tmp; cin >> tmp; if (tmp[0] == 'M') num[0]++; else if (tmp[0] == 'A') num[1]++; else if (tmp[0] == 'R') num[2]++; else if (tmp[0] == 'C') num[3]++; else if (tmp[0] == 'H') num[4]++; } long long int ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += (num[i] * num[j] * num[k]); } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> S(N); vector<int> rec(5); for (int i = 0; i < N; ++i) { cin >> S[i]; switch (S[i][0]) { case 'M': rec[0]++; break; case 'A': rec[1]++; break; case 'R': rec[2]++; break; case 'C': rec[3]++; break; case 'H': rec[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++) { ans += rec[i] * rec[j] * rec[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; char s[11]; int a[5]; int main() { int n; scanf("%d",&n); memset(a,0,sizeof(a)); for(int i=0;i<n;i++) { scanf("%s",s); if(s[0]=='M') a[0]++; else if(s[0]=='A') a[1]++; else if(s[0]=='R') a[2]++; else if(s[0]=='C') a[3]++; else if(s[0]=='H') a[4]++; } sort(a,a+5); int t=upper_bound(a,a+5,0)-a; long long ans=0; if(t>=3) printf("0\n"); else if(t==2) { ans=a[2]*a[3]*a[4]; printf("%lld\n",ans); } else if(t==1) { ans+= a[1]*a[2]*a[3]+a[1]*a[2]*a[4]+a[2]*a[3]*[4]+a[1]*a[3]*a[4]; printf("%lld\n",ans); } else if(t==0) { ans+=a[0]*a[1]*a[2]+a[0]*a[1]*a[3]+a[0]*a[1]*a[4]; ans+=a[1]*a[2]*a[3]+a[1]*a[2]*a[4]+a[2]*a[3]*a[4]; ans+=a[0]*a[3]*a[4]+a[0]*a[2]*a[3]+a[0]*a[2]*a[4]+a[1]*a[3]*a[4]; printf("%lld\n",ans); } return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <iostream> #include <string> using namespace std; int main() { long long n; cin>>n; int arr[26]; for(int i=0;i<26;i++){ arr[i]=0; } for(int i=0;i<n;i++) { string s; cin>>s; arr[s[0]-65]++; } long long ar[5]; ar[0]=arr['M'-65]; ar[1]=arr['A'-65]; ar[2]=arr['R'-65]; ar[3]=arr['C'-65]; ar[4]=arr['H'-65]; long long sum=0; for(int i=0;i<3;i++) { for(int j=i+1;j<4;j++) { for(int k=j+1;k<5;k++) { sum+=ar[i]*ar[j]*ar[k]; } } } cout<<sum; return 0; } #include <iostream> #include <string> using namespace std; int main() { long long n; cin>>n; int arr[26]; for(int i=0;i<26;i++){ arr[i]=0; } for(int i=0;i<n;i++) { string s; cin>>s; arr[s[0]-65]++; } long long ar[5]; ar[0]=arr['M'-65]; ar[1]=arr['A'-65]; ar[2]=arr['R'-65]; ar[3]=arr['C'-65]; ar[4]=arr['H'-65]; long long sum=0; for(int i=0;i<3;i++) { for(int j=i+1;j<4;j++) { for(int k=j+1;k<5;k++) { sum+=ar[i]*ar[j]*ar[k]; } } } cout<<sum; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
#!C:\Users\daichi\Anaconda3/python.exe # -*- coding: utf-8 -*- import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(input()) a = [] T = [0,0,0,0,0] for i in range(N): a.append(input()) i=0 for i in range(N): if( a[i].startswith('M') ): T[0] = T[0]+1 if( a[i].startswith('A') ): T[1] = T[1]+1 if( a[i].startswith('R') ): T[2] = T[2]+1 if( a[i].startswith('C') ): T[3] = T[3]+1 if( a[i].startswith('H') ): T[4] = T[4]+1 SUM = T[0]+T[1]+T[2]+T[3]+T[4] print(combinations_count(SUM, 3) )
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; int M = 0, A = 0, R = 0, C = 0, H = 0; long long cnt; vector<string> name; cin >> N; for (int i = 0; i < N; i++) { string s; cin >> s; name.push_back(s); } cnt = 0; for (vector<string>::iterator i = name.begin(); i != name.end(); i++) { if ((*i)[0] == 'M') { M++; } else if ((*i)[0] == 'A') { A++; } else if ((*i)[0] == 'R') { R++; } else if ((*i)[0] == 'C') { C++; } else if ((*i)[0] == 'H') { H++; } } cnt += M * R * C; cnt += M * R * A; cnt += M * R * H; cnt += M * C * A; cnt += M * C * H; cnt += M * A * H; cnt += H * A * C; cnt += H * R * C; cnt += A * R * H; cnt += A * R * C; 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
UNKNOWN
_, *names = readlines.map(&:chomp) marchs = names.select {|n| 'MARCH'.each_char.any?{|c| n.start_with?(c)}} marchs.length < 3 && p(0) && exit x = marchs.reduce(Hash.new {|h, k| h[k]=0}) {|r, n| r[n[0]]+=1; r} p x.keys.combination(3).map {|c| c.reduce(1) {|r, k| r *= x[k]}}.reduce(:+)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\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[n]; int m, a, r, c, h; long long num; m = 0; a = 0; r = 0; c = 0; h = 0; for (int i = 0; i < n; ++i) cin >> str[i]; for (int i = 0; i < n; ++i) { if (str[i].at(0) == 'M') { m = m + 1; } else if (str[i].at(0) == 'A') { a = a + 1; } else if (str[i].at(0) == 'R') { r = r + 1; } else if (str[i].at(0) == 'C') { c = c + 1; } else if (str[i].at(0) == 'H') { h = h + 1; } } num = 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 << num << endl; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vll = vector<long long>; long long mod = 1e9 + 7; using namespace std; using Graph = vector<vector<int>>; int cnt_digit(long long N) { int digit = 0; while (N > 0) { N /= 10; digit++; } return digit; } long long gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } long long lcm(long long a, long long b) { long long g = gcd(a, b); return a / g * b; } struct union_find { vector<int> par, r; union_find(int n) { par.resize(n); r.resize(n); init(n); } void init(int n) { for (int i = 0; i < n; i++) par[i] = i; for (int i = 0; i < n; i++) r[i] = 0; } int find(int x) { if (par[x] == x) return x; else return find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (r[x] < r[y]) { par[x] = y; } else { par[y] = x; if (r[x] == r[y]) { r[x]++; } } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); map<char, int> map; string m = "MARCH"; int n; cin >> n; for (int i = 0; i < n; ++i) { string c; cin >> c; map[c[0]]++; } int ans = 0; for (int i = 0; i < 5; ++i) { for (int j = i + 1; j < 5; ++j) { for (int q = j + 1; q < 5; ++q) { ans += map[m[i]] * map[m[j]] * map[m[q]]; } } } 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 = ['M','A','R','C','H'] m = [] a = [] r = [] c = [] h = [] for i in range(n): s = input() if not s[0] in l: continue if s[0] == 'M': m.append(s) elif s[0] == 'A': a.append(s) elif s[0] == 'R': r.append(s) elif s[0] == 'C': c.append(s) else: h.append(s) n = sum([len(i) for i in [m,a,r,c,h]]) all = n * (n - 1) * (n - 2) // 6 print(r) for t in [m,a,r,c,h]: i = len(t) if i >= 2: k = i * (i -1) // 2 all -= k*(n-2) if i >= 3: k = i * (i - 1) * (i - 2) // 6 all -= k print(all)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); long long m, a, r, c, h; long long num[5]; string s; 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++; } num[0] = m; num[1] = a; num[2] = r; num[3] = c; num[4] = h; long long res = 0; int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2}; int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3}; int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4}; for (int i = 0; i < 10; i++) { res += num[x[i]] * num[y[i]] * num[z[i]]; } printf("%lld\n", res); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main { public static void main(String[] args ){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Map<Character, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { String s = sc.next(); char c = s.charAt(0); if (c != 'M' && c != 'A' && c != 'R' && c != 'C' && c != 'H') continue; int count = map.getOrDefault(c, 0); map.put(c, ++count); } if (map.size() < 3) { System.out.println(0); return; } 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++) { ans += (long)map.get(i) * map.get(j) * map.get(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; const double PI = 3.1415926535897932; const double EPS = 1e-15; const long long mod = 1e+9 + 7; int index(string s) { if (s[0] == 'M') return 0; if (s[0] == 'A') return 1; if (s[0] == 'R') return 2; if (s[0] == 'C') return 3; if (s[0] == 'H') return 4; return -1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> cnt(5, 0); for (int i = 0; i < n; ++i) { string s; cin >> s; int hoge = index(s); if (hoge == -1) continue; ++cnt[hoge]; } long long res = 0; for (int i = 0; i < 5; ++i) { for (int j = i + 1; j < 5; ++j) { for (int k = j + 1; k < 5; ++k) { res += cnt[i] * cnt[j] * cnt[k]; } } } 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 main() { int N, count = 0; vector<int> f(5, 0); long long int ans = 0, sum = 1; string name; cin >> N; for (int i = 0; i < N; i++) { cin >> name; if (name[0] == 'M') { f[0]++; } else if (name[0] == 'A') { f[1]++; } else if (name[0] == 'R') { f[2]++; } else if (name[0] == 'C') { f[3]++; } else if (name[0] == 'H') { f[4]++; } } for (int i = 0; i < 5; i++) { if (0 < f[i]) { count++; sum *= f[i]; } } if (count < 3) { cout << "0" << endl; } else if (count == 3) { cout << sum << endl; } else if (count == 4) { for (int i = 0; i < 5; i++) { if (f[i] != 0) { ans += sum / f[i]; } } cout << ans << endl; } else { for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { ans += sum / f[i] / f[j]; } } 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 sc = new Scanner(System.in); int N = sc.nextInt(); String[] S = new String[N]; for(int i = 0 ; i < N ; i++){ S[i] = sc.next(); } sc.close(); int tmp = N; int M = 0; int A = 0; int R = 0; int C = 0; int H = 0; for(int i = 0 ; i < N ; i++){ if(!S[i].substring(0, 1).equals("M") && !S[i].substring(0, 1).equals("A") && !S[i].substring(0, 1).equals("R") && !S[i].substring(0, 1).equals("C") && !S[i].substring(0, 1).equals("H")){ tmp--; } else if(S[i].substring(0, 1).equals("M")){ M++; } else if(S[i].substring(0, 1).equals("A")){ A++; } else if(S[i].substring(0, 1).equals("R")){ R++; } else if(S[i].substring(0, 1).equals("C")){ C++; } else if(S[i].substring(0, 1).equals("H")){ H++; } } if(tmp == 0){ System.out.println("0"); } else{ int[] T = {M,A,R,C,H}; 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 += (T[i]*T[j]*T[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; size_t N; string S; char headc[5] = {'M', 'A', 'R', 'C', 'H'}; vector<long long> head_num(5, 0); void mysort(string s) { for (size_t i = 0; i < 5; i++) { if (s.front() == headc[i]) { head_num[i]++; return; } } return; } int main() { cin >> N; S.resize(N); for (size_t i = 0; i < N; i++) { cin >> S; mysort(S); } sort(head_num.begin(), head_num.end()); int times = 1; int sump = 0; if (head_num[0] > 0) { for (size_t i = 0; i < 4; i++) { for (size_t j = i + 1; j < 5; j++) { cout << i << ":" << j << " "; for (size_t k = 0; k < 5; k++) { if (k != i && k != j) { times *= head_num[k]; } } cout << times << endl; sump += times; times = 1; } } cout << sump << endl; } else if (head_num[1] > 0) { for (size_t i = 1; i < 5; i++) { for (size_t k = 1; k < 5; k++) { if (k != i) { times *= head_num[k]; } } sump += times; times = 1; } cout << sump << endl; } else { for (size_t k = 2; k < 5; k++) { times *= head_num[k]; } cout << times << endl; } return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> p = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2}; vector<int> q = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3}; vector<int> s = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4}; int m = 0, a = 0, r = 0, c = 0, h = 0; for (int i = 0; i < (int)(n); i++) { string tmp; cin >> tmp; if (tmp.at(0) == 'M') m++; if (tmp.at(0) == 'A') a++; if (tmp.at(0) == 'R') r++; if (tmp.at(0) == 'C') c++; if (tmp.at(0) == 'H') h++; } vector<int> D = {m, a, r, c, h}; ll ans = 0; for (int i = 0; i < (int)(10); i++) { ans += D.at(p.at(i)) * D.at(q.at(i)) * D.at(s.at(i)); } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
from itertools import combinations N = int(input()) SSS = [input() for _ in range(N)] # Filter1 filter_1 = {'M', 'A', 'R', 'C', 'H'} canditates = [S for S in SSS if S[0] in filter_1] n_satisfied = 0 for cand in combinations(canditates, 3): cond1 = cand[0][0] != cand[1][0] cond2 = cand[1][0] != cand[2][0] cond3 = cand[2][0] != cand[0][0] if cond1 and cond2 and cond3: n_satisfied += 1 print(n_satisfied)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\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 int_len(int n) { int s = 0; while (n != 0) s++, n /= 10; return s; } int int_sum(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; } long long int gcd(long long int a, long long int b) { long long 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 fac(int n) { int m = 1; while (n >= 1) m *= n, n--; return m; } int vec_sum(vector<int> v) { int n = 0; for (int i = 0; i < v.size(); i++) n += v[i]; return n; } int main() { int n, ans = 0, count = 0, c[5]; cin >> n; 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]++; } } for (int i = 0; i < (5); i++) if (c[i] > 0) count++; if (count <= 2) { cout << 0 << endl; return 0; } for (int p = 0; p < 3; p++) { for (int q = p + 1; q < 4; q++) { for (int r = q + 1; r < 5; r++) { ans += c[p] * c[q] * c[r]; } } } 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> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma warning(disable : 4996) using namespace std; template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } std::random_device rd; std::mt19937 mt(rd()); constexpr long long MOD = 998244353; constexpr long long MAX = 2000020; const double pi = acos(-1); constexpr double EPS = 1e-8; constexpr long long INF = 1e18; char lis[5] = {'M', 'A', 'R', 'C', 'H'}; void solve() { map<char, long long> mp; long long N; cin >> N; for (long long i = 0; i < N; ++i) { string S; cin >> S; char c = S[0]; mp[c]++; } long long perm[5] = {0, 0, 1, 1, 1}; long long ans = 0; do { long long res = 1; for (long long i = 0; i < 5; ++i) { if (perm[i]) res *= mp[lis[i]]; } ans += res; } while (next_permutation(perm, perm + N)); ; cout << (ans) << '\n'; } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] a = new int[5]; Arrays.fill(a,0); for(int i = 0;i < N;i++){ String s = sc.next(); if(s.charAt(0) = 'M')a[0]++; if(s.charAt(0) = 'A')a[1]++; if(s.charAt(0) = 'R')a[2]++; if(s.charAt(0) = 'C')a[3]++; if(s.charAt(0) = 'H')a[4]++; } System.out.println(a[0]*a[1]*a[2]+a[1]*a[2]*a[3]+a[2]*a[3]*a[4]+a[3]*a[4]*a[0]+a[4]*a[0]*a[1]+a[0]*a[1]*a[3]+a[1]*a[2]*a[4]+a[2]*a[3]*a[0]+a[3]*a[4]*a[1]+a[4]*a[0]*a[2]); }}
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\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.pushbuck(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 = 0; } else if(S[i][0] == 'A'){ a = 0; } else if(S[i][0] == 'R'){ r = 0; } else if(S[i][0] == 'C'){ c = 0; } else if(S[i][0] == 'H'){ h = 0; } } 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
cpp
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; const long long MOD = 1e9 + 7; int main() { int n; cin >> n; int march[5] = {0}; string s = "MARCH"; for (int i = 0; i < (int)(n); i++) { string t; cin >> t; for (int j = 0; j < (int)(5); j++) if (t[0] == s[j]) march[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 += march[i] * march[j] * march[k]; } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var inputList = input.split('\n'); var n = Number(inputList[0]); var capitalWordsList = inputList[1].split(' ').map(i => i.split('')[0]); var mNum = capitalWordsList.filter(s => s === 'M').length; var aNum = capitalWordsList.filter(s => s === 'A').length; var rNum = capitalWordsList.filter(s => s === 'R').length; var cNum = capitalWordsList.filter(s => s === 'C').length; var hNum = capitalWordsList.filter(s => s === 'H').length; var lengthList = [mNum, aNum, rNum, cNum, hNum]; var threeList = []; var chooseThreeFromArr = (arr) => { for (var i=0;i<3;i++) { var list1 = []; list1.push(arr[i]); for (var j=i+1;j<5;j++) { var list2 = list1.slice(); list2.push(arr[j]); for (var k=j+1;k<5;k++) { var list3 = list2.slice(); list3.push(arr[k]); threeList.push(list3); } } } } chooseThreeFromArr(lengthList); const result = threeList.map((i) => i.reduce((a,b)=>a*b)).reduce((a,b)=>a+b); console.log(result);
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
N = int(input()) M = [] A = [] R = [] C = [] H = [] for i in range(N): temp = input() init_temp = list(temp) if 'M' == init_temp[0]: M.append(temp) elif 'A' == init_temp[0]: A.append(temp) elif 'R' == init_temp[0]: R.append(temp) elif 'C' == init_temp[0]: C.append(temp) elif 'H' == init_temp[0]: H.append(temp) else: pass M = len(list(set(M))) A = len(list(set(A))) R = len(list(set(R))) C = len(list(set(C))) H = len(list(set(H))) D = [M, A, R, C, H] #10通り書き出す A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2] B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3] C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4] ans = 0.0 for i in range(10): ans += D[A[i]] * D[B[i]] * D[C[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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string t = "MARCH"; vector<int> c(5); for (int i = 0; i < (n); i++) { string s; cin >> s; for (int j = 0; j < 5; j++) { if (s[0] == t[j]) { c[j]++; } } } long long ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5 - 1; j++) { for (int k = j + 1; k < 5 - 2; 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 factorial(int x) { int tmp = x; for (int i = x - 1; i > 0; i--) tmp *= i; return tmp; } int main() { unsigned long int N; cin >> N; char name[N][15]; char c[5] = {'M', 'A', 'R', 'C', 'H'}; for (int i = 0; i < N; i++) cin >> name[i]; int count = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = j + 1; k < N; k++) { int flag[3] = {0, 0, 0}; for (int m = 0; m < 5; m++) { if (name[i][0] == c[m]) flag[0] = 1; if (name[j][0] == c[m]) flag[1] = 1; if (name[k][0] == c[m]) flag[2] = 1; } if (flag[0] + flag[1] + flag[2] == 3) { if (name[i][0] != name[j][0] && name[i][0] != name[k][0] && name[k][0] != name[j][0]) count++; } } } } cout << count << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, cnt = 1; char s[1001]; cin >> n; for (int i = 0; i < n; i++) { cout << s[i]; } if (n == 5) cout << 2; else cout << 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; string ms = "MARCH"; map<char, int> marches{{'M', 0}, {'A', 0}, {'R', 0}, {'C', 0}, {'H', 0}}; for (int i = 0; i < N; i++) { cin >> S; auto it = marches.find(S[0]); if (it != marches.end()) ++marches[S[0]]; } long long ans = 0; for (auto i = ms.begin(); i != ms.end(); i++) { for (auto j = i + 1; j != ms.end(); j++) { for (auto k = j + 1; k != ms.end(); k++) { ans += marches[*i] * marches[*j] * marches[*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 math import factorial def main(): N = int(input()) S = tuple(input() for _ in [0] * N) name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0} for s in S: if s[0] in 'MARCH': name[s[0]] += 1 lst = [i for i in name.values() if i] n = len(lst) if n < 3: print(0) return comb = factorial(n) // (factorial(3) * factorial(n - 3)) k = 0 for l in lst: comb *= l if l > 1 and n > 3: k += n - 3 print(comb - k) 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() { long long s = 0; int n, i, a = 0, b = 0, c = 0, d = 0, e = 0; char arr; scanf("%d", &n); getchar(); for (i = 0; i < n; i++) { char tmp[15]; scanf("%s", tmp); getchar(); arr = tmp[0]; if (arr == 'M') a++; if (arr == 'A') b++; if (arr == 'R') c++; if (arr == 'C') d++; if (arr == 'H') e++; } s += a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e + b * c * d + b * c * e + b * d * e + c * d * e; printf("%d", s); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long march[5]; for (int i = 0; i < 5; i++) { march[i] = 0; } string name; for (int i = 0; i < 5; i++) { cin >> name; if ('M' == name[0]) { march[0]++; } if ('A' == name[0]) { march[1]++; } if ('R' == name[0]) { march[2]++; } if ('C' == name[0]) { march[3]++; } if ('H' == name[0]) { march[4]++; } } long long sum = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { sum = sum + march[i] * march[j] * march[k]; } } } cout << sum; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import itertools N = int(input()) S = [0] * N ans = 0 for i in range(N): s = input() if s[0] in ['M', 'A', 'R', 'C', 'H']: S[i] = s S = list(set(S)) S.remove(0) march = [0] * 5 for i in S: if i[0] == 'M': march[0] += 1 elif i[0] == 'A': march[1] += 1 elif i[0] == 'R': march[2] += 1 elif i[0] == 'C': march[3] += 1 else: march[4] += 1 for i, j, k in list(itertools.combinations([0, 1, 2, 3, 4], 3)): ans += march[i] * march[j] * march[k] print(ans)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
from intertools import combinations from collections import Counter N=int(input()) S=Counter() for i in range(N): S[input()[0]]+=1 print(sum([S[a]*S[b]*S[c] for a,b,c 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
UNKNOWN
#[allow(unused_macros, dead_code)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } #[allow(unused_macros, dead_code)] macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } #[allow(unused_macros, dead_code)] macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } #[allow(dead_code)] struct UnionFind { parent: Vec<usize>, rank: Vec<usize>, size: Vec<usize>, } #[allow(dead_code)] impl UnionFind { fn new(n: usize) -> UnionFind { let mut p = vec![0; n]; for i in 0..n { p[i] = i; } return UnionFind { parent: p, rank: vec![0; n], size: vec![1; n], }; } fn find(&mut self, x: usize) -> usize { if x == self.parent[x] { x } else { let p = self.parent[x]; let pr = self.find(p); self.parent[x] = pr; pr } } fn same(&mut self, a: usize, b: usize) -> bool { self.find(a) == self.find(b) } fn unite(&mut self, a: usize, b: usize) { let a_root = self.find(a); let b_root = self.find(b); if a_root == b_root { return; } if self.rank[a_root] > self.rank[b_root] { self.parent[b_root] = a_root; self.size[a_root] += self.size[b_root]; } else { self.parent[a_root] = b_root; self.size[b_root] += self.size[a_root]; if self.rank[a_root] == self.rank[b_root] { self.rank[b_root] += 1; } } } fn get_size(&mut self, x: usize) -> usize { let root = self.find(x); self.size[root] } } const MOD_P: usize = 1000000007; #[allow(dead_code)] // fact(n) = n! mod p fn fact(n: usize) -> usize { let mut acc = 1; for i in 1..n + 1 { acc = acc * i % MOD_P; } acc } #[allow(dead_code)] fn mod_pow(b: usize, mut e: usize) -> usize { let mut base = b; let mut acc = 1; while e > 1 { if e % 2 == 1 { acc = acc * base % MOD_P; } e /= 2; base = base * base % MOD_P; } if e == 1 { acc = acc * base % MOD_P; } acc } #[allow(dead_code)] fn comb(n: usize, r: usize) -> usize { // nCr = n! / (r! (n-r)!) = n! (r!)^(p-2) ((n-r)!)^(p-2) let x = ((n - r + 1)..(n + 1)).fold(1, |p, x| p * x % MOD_P); let y = mod_pow(fact(r), MOD_P - 2); x * y % MOD_P } #[derive(Clone, Copy, Debug)] struct GF(usize); impl std::ops::Add for GF { type Output = GF; fn add(self, rhs: GF) -> Self::Output { let mut d = self.0 + rhs.0; if d >= MOD_P { d -= MOD_P; } GF(d) } } impl std::ops::AddAssign for GF { fn add_assign(&mut self, rhs: GF) { *self = *self + rhs; } } impl std::ops::Sub for GF { type Output = GF; fn sub(self, rhs: GF) -> Self::Output { let mut d = self.0 + MOD_P - rhs.0; if d >= MOD_P { d -= MOD_P; } GF(d) } } impl std::ops::SubAssign for GF { fn sub_assign(&mut self, rhs: GF) { *self = *self - rhs; } } impl std::ops::Mul for GF { type Output = GF; fn mul(self, rhs: GF) -> Self::Output { let mut d = self.0 * rhs.0; d %= MOD_P; GF(d) } } impl std::ops::MulAssign for GF { fn mul_assign(&mut self, rhs: GF) { *self = *self * rhs; } } impl std::fmt::Display for GF { fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result { write!(f, "{}", self.0) } } #[allow(dead_code)] impl GF { pub fn new(n: usize) -> GF { GF(n % MOD_P) } pub fn zero() -> GF { GF(0) } pub fn one() -> GF { GF(1) } pub fn pow(self, mut e: usize) -> GF { let mut acc = GF::one(); let mut b = self; while e > 1 { if e % 2 == 1 { acc *= b; } b *= b; e /= 2; } if e == 1 { acc *= b; } acc } pub fn fact(self) -> GF { let mut acc = GF::one(); for i in 1..=self.0 { acc *= GF::new(i); } acc } pub fn inv(self) -> GF { self.pow(MOD_P - 2) } pub fn comb(n: GF, r: GF) -> GF { // nCr = n! / (r! (n-r)!) = n! (r!)^(p-2) ((n-r)!)^(p-2) let x = ((n.0 - r.0 + 1)..=n.0).fold(GF::one(), |p, x| p * GF(x)); let y = r.fact().inv(); x * y } } #[allow(dead_code)] #[derive(Debug)] struct MemComb { inv: Vec<GF>, fact: Vec<GF>, factinv: Vec<GF>, } #[allow(dead_code)] impl MemComb { pub fn new(n: usize) -> MemComb { let mut inv = vec![GF::one(); n + 1]; let mut fact = vec![GF::one(); n + 1]; let mut factinv = vec![GF::one(); n + 1]; for i in 2..=n { fact[i] = fact[i - 1] * GF(i); } factinv[n] = fact[n].inv(); for i in (1..n).rev() { factinv[i] = factinv[i + 1] * GF(i + 1); // 1/n! = 1/(n+1)! * (n+1) inv[i] = factinv[i] * fact[i - 1]; // 1/n = 1/n! * (n-1)! } inv[n] = factinv[n] * fact[n - 1]; MemComb { inv, fact, factinv } } } #[allow(dead_code)] fn gcd(a: usize, b: usize) -> usize { if b > a { gcd(b, a) } else if a % b == 0 { b } else { gcd(b, a % b) } } #[allow(dead_code)] fn getline() -> String { let mut __ret = String::new(); std::io::stdin().read_line(&mut __ret).ok(); return __ret; } #[allow(unused_imports)] use std::cmp::{max, min}; fn main() { input! { n: usize, s: [chars; n], } let mut v = vec![0; 5]; for x in s { match x[0] { 'M' => v[0] += 1, 'A' => v[1] += 1, 'R' => v[2] += 1, 'C' => v[3] += 1, 'H' => v[4] += 1, _ => {} } } // eprintln!("{:?}", v); let mut ans = 0; for i in 0..32 { let c = unsafe { core::arch::x86_64::_popcnt64(i) }; if c == 3 { // eprintln!("{:05b}", i); ans += if i & 1 == 1 { v[0] } else { 1 } * if i & 2 != 0 { v[1] } else { 1 } * if i & 4 != 0 { v[2] } else { 1 } * if i & 8 != 0 { v[3] } else { 1 } * if i & 16 != 0 { v[4] } else { 1 }; } } println!("{}", ans); }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM import qualified Data.ByteString.Char8 as B import Data.List import Control.Monad add vec xs | h == 'M' = VUM.modify vec (+1) 0 | h == 'A' = VUM.modify vec (+1) 1 | h == 'R' = VUM.modify vec (+1) 2 | h == 'C' = VUM.modify vec (+1) 3 | h == 'H' = VUM.modify vec (+1) 4 | otherwise = VUM.modify vec (+1) 5 where h = B.head xs toBit n acc l | n <= 1 = let res = ((n `rem` 2):acc) l' = length res in if l' < l then reverse $ res ++ (replicate (l-l') 0) else reverse res | otherwise = toBit (n `quot` 2) ((n `rem` 2):acc) l solve :: [Int] -> Int -> Int -> [Int] solve xs n l | n < 0 = [] | ones == 3 = (loop xs bs) : solve xs (n-1) l | otherwise = solve xs (n-1) l where ones = length $ filter (==1) bs bs = toBit n [] l loop [] [] = 1 loop (x:xs) (b:bs) | b == 1 = x * loop xs bs | otherwise = loop xs bs main = do n <- readLn :: IO Int tbl <- VUM.replicate 6 0 forM_ [1..n] $ \_ -> do bs <- B.getLine add tbl bs tbl' <- VU.freeze tbl let f = VU.toList $ VU.filter (/=0) (VU.init tbl') let l = length f print $ if l < 3 then 0 else if l == 3 then product f else sum $ solve f (2^l-1) l
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.math; void main() { auto N = readln.chomp.to!int; auto a = ['M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4]; ulong[ulong] b; foreach(i; 0..5) b[i] = 0; foreach(_; 0..N) { auto c = readln.chomp[0]; if(c in a) b[a[c]]++; } auto A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]; auto B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]; auto C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]; int res; foreach(i; 0..10) { res += b[A[i]] * b[B[i]] * b[C[i]]; } res.writeln; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; int initial[5]; long long int Ans = 0; int patern[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}}; for (int i = 0; i < 5; i++) initial[i] = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> S; if (S[0] == 'M') initial[0]++; else if (S[0] == 'A') initial[1]++; else if (S[0] == 'R') initial[2]++; else if (S[0] == 'C') initial[3]++; else if (S[0] == 'H') initial[4]++; } for (int i = 0; i < 10; i++) Ans += initial[patern[i][0]] * initial[patern[i][1]] * initial[patern[i][2]]; 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()) w = "MARCH" count = {key: 0 for key in w} for i in range(N): S = input() c = S[0] if c in w: count[c] += 1 ans = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): ans += count[w[i]] * count[w[j]] * count[w[k]] print(ans)
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long int ans; int main() { int n, f[10], i, g; ans = g = 0; char a[15]; memset(f, 0, sizeof(f)); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", a); if (a[0] == 'A') f[1] += 1; else if (a[0] == 'M') f[2] += 1; else if (a[0] == 'R') f[3] += 1; else if (a[0] == 'H') f[4] += 1; else if (a[0] == 'C') f[5] += 1; } for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += f[i] * f[j] * f[k]; } } } printf("%lld\n", ans); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import math # NO, PAY-PAY #import numpy as np #import statistics #from statistics import mean, median,variance,stdev def main(): N = int(input()) s = [] for i in range(N): tmp = input() s.append(tmp) m = 0 a = 0 r = 0 c = 0 h = 0 for i in s: if s[0] == "M": m += 1 elif s[0] == "A": a += 1 elif s[0] == "R": r += 1 elif s[0] == "C": c += 1 elif s[0] == "H": h += 1e ans = 0 total = (a*b*c) + (a*b*d) + (a*b*e) + (a*c*d) + (a*c*e) + (a*d*e) + (b*c*d) + (b*c*e) + (b*d*e) + (c*d*e) print(total) if __name__ == "__main__": main()
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <stdio.h> long long int minx(long long int v[],int n){ int i,j,k; long long int tmp; tmp=v[0]; for(i=1;i<=n-1;i++){ if(tmp>v[i]) tmp=v[i];} return tmp;} int maxx(int v[],int n){ int i,j,k,tmp; tmp=v[0]; for(i=1;i<=n-1;i++){ if(tmp<v[i]) tmp=v[i];} return tmp;} int max(int n1,int n2,int n3){ int tmp; tmp=n1; if(n2>tmp) tmp=n2; if(n3>tmp) tmp=n3; return tmp;} int max2(int n1,int n2){ int tmp; tmp=n1; if(n2>tmp) tmp=n2; return tmp;} int min3(int n1,int n2,int n3){ int tmp; tmp=n1; if(n2<tmp) tmp=n2; if(n3<tmp) tmp=n3; return tmp;} int min2(int n1,int n2){ int tmp; tmp=n1; if(n2<tmp) tmp=n2; return tmp;} long long int abs(long long int n){ if(n>=0) return n; else return(-1)*n; } int main(void) {int N,A,M,B,j,i,k,H,W,l,nM,nA,nR,nC,nH,flag; long long int sum,min; sum=1; scanf("%d",&N); char S[100000][10]; nM=0; nA=0; nR=0; nC=0; nH=0; for(i=0;i<=N-1;i++){ scanf("%s",&S[i]);} for(j=0;j<=N-1;j++){ if(S[j][0]=='M'){ nM+=1;} else if(S[j][0]=='A'){ nA+=1;} else if(S[j][0]=='R'){ nR+=1;} else if(S[j][0]=='C'){ nC+=1;} else if(S[j][0]=='H'){ nH+=1;} } int A[5]={nM,nA,nR,nC,nH}; long long int B[5]; k=0; for(i=0;i<=4;i++){ if(A[i]!=0){ B[k]=A[i]; k+=1;}} if(k<3) printf("0"); else if(k==3){ sum=B[0]*B[1]*B[2]; printf("%lld",sum);} else if(k==4){ sum=B[0]*B[1]*B[2]+B[0]*B[1]*B[3]+B[0]*B[2]*B[3]+B[1]*B[2]*B[3]; printf("%lld",sum);} else if(k==5){ sum=B[0]*B[1]*B[2]+B[0]*B[1]*B[3]+B[0]*B[2]*B[3]+B[1]*B[2]*B[3]+B[0]*B[1]*B[4]+B[0]*B[2]*B[4]+B[0]*B[3]*B[4]+B[1]*B[2]*B[4]+B[1]*B[3]*B[4]+B[2]*B[3]*B[4]; 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
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int march[] = new int[5]; // int m = 0; // int a = 0; // int r = 0; // int c = 0; // int h = 0; for (int i = 0; i < n; i++) { String str = sc.next(); char ch = str.charAt(0); switch(ch) { case 'M' : // m++; march[0]++; break; case 'A' : // a++; march[1]++; break; case 'R' : // r++; march[2]++; break; case 'C' : // c++; march[3]++; break; case 'H' : // h++; march[4]++; break; } } // for (int i = 0; i < 5; i++) { // System.out.println(march[i]); // } // // System.out.println("---------------------------------"); 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++) { ans += count(march[i], march[j], march[k]); // System.out.println(i + "/"+ j + "/" + k + ":" + count(march[i], march[j], march[k])); } } } System.out.println(ans); sc.close(); } static int count(int a, int b, int c) { return a * b * c; } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[5]; for (int i = 0; i < n; i++) { String s = sc.next(); if (s.charAt(0) == 'M') { a[0]++; } else if (s.charAt(0) == 'A') { a[1]++; } else if (s.charAt(0) == 'R') { a[2]++; } else if (s.charAt(0) == 'C') { a[3]++; } else if (s.charAt(0) == 'H') { a[4]++; } } long ans = a[0]*a[1]*a[2] + a[0]*a[1]*a[3] + a[0]*a[1]*a[4] + a[0]*a[2]*a[3] + a[0]*a[2]*a[4] + a[0]*a[3]*a[4] + a[1]*a[2]*a[3] + a[1]*a[2]*a[4] + a[1]*a[3]*a[4] + a[2]*a[3]*a[4]; System.out.println(ans); } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int a = 0, m = 0, r = 0, c = 0, h = 0, i, num; int answer; scanf("%d", &num); char array[10]; for (i = 1; i <= num; i++) { scanf("%s", array); if (array[0] == 'M') m++; if (array[0] == 'A') a++; if (array[0] == 'R') r++; if (array[0] == 'C') c++; if (array[0] == 'H') h++; } answer = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * c * h + r * c * h + a * r * h; printf("%d", answer); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
let solve m a r c h = let m = Big_int.big_int_of_int m in let a = Big_int.big_int_of_int a in let r = Big_int.big_int_of_int r in let c = Big_int.big_int_of_int c in let h = Big_int.big_int_of_int h in let ( * ) x y = Big_int.mult_big_int x y in let ( + ) x y = Big_int.add_big_int x y in m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * c * h + r * c * h let rec get_input_aux n solve m a r c h = if n = 0 then solve m a r c h else match (read_line ()).[0] with | 'M' -> get_input_aux (n - 1) solve (m + 1) a r c h | 'A' -> get_input_aux (n - 1) solve m (a + 1) r c h | 'R' -> get_input_aux (n - 1) solve m a (r + 1) c h | 'C' -> get_input_aux (n - 1) solve m a r (c + 1) h | 'H' -> get_input_aux (n - 1) solve m a r c (h + 1) | _ -> get_input_aux (n - 1) solve m a r c h let get_input n solve = get_input_aux n solve 0 0 0 0 0 let () = let n = read_int () in get_input n solve |> Big_int.string_of_big_int |> print_endline
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int m = 0; int y; int k1(string a) { if (a == "M") { m++; return 1; } else if (a == "A") { m++; return 2; } else if (a == "R") { m++; return 3; } else if (a == "C") { m++; return 4; } else if (a == "H") { m++; return 5; } else { return 0; } } int main() { long int n; cin >> n; vector<string> s(n); for (int i = 0; i < (n); i++) { cin >> s[i]; } vector<int> x(n); for (int i = 0; i < (n); i++) { string a = s[i]; a = a[0]; x[i] = k1(a); } if (m < 3) { cout << 0 << endl; return 0; } sort(x.begin(), x.end()); int ans = 0; for (int i = 0; i < (n); i++) { if (x[i] == 0) { continue; } for (int j = (i) + 1; j < (n); j++) { if (x[j] == 0 || x[j] == x[i]) { continue; } for (int k = (j) + 1; k < (n); k++) { if (x[k] == 0) { continue; } else if (x[k] == x[i] || x[k] == x[j]) { continue; } ans++; } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
use scanner::Scanner; fn main() { let mut sc = Scanner::new(); let n: usize = sc.read(); let mut count = [0; 5]; for _ in 0..n { match sc.read::<String>().chars().collect::<Vec<char>>()[0] { 'M' => count[0] += 1, 'A' => count[1] += 1, 'R' => count[2] += 1, 'C' => count[3] += 1, 'H' => count[4] += 1, _ => (), } } let mut ans = 0; for i in 0..count.len() { for j in i+1..count.len() { for k in j +1..count.len() { ans += count[i] * count[j] * count[k]; } } } println!("{}", ans); } mod scanner { pub struct Scanner<'a> { s: String, words: ::std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new() -> Scanner<'a> { let s = String::new(); let words = unsafe { ::std::mem::transmute(s.split_whitespace()) }; Scanner { s: s, words: words } } pub fn read<T: ::std::str::FromStr>(&mut self) -> T { match self.words.next() { Some(x) => x.parse().ok().unwrap(), None => { self.load(); self.read() } } } fn load(&mut self) { self.s.clear(); ::std::io::stdin().read_line(&mut self.s).unwrap(); self.words = unsafe { ::std::mem::transmute(self.s.split_whitespace()) }; } } }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int m = 0; int a = 0; int r = 0; int c = 0; int h = 0; for (int i = 0; i < n; i++) { char s[20] = {}; scanf("%s", s); if (s[0] == 'M') m++; if (s[0] == 'A') a++; if (s[0] == 'R') r++; if (s[0] == 'C') c++; if (s[0] == 'H') h++; } printf("%d\n", m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { int n; cin >> n; array<int, 5> c = {0, 0, 0, 0, 0}; string s = "MARCH"; for (int i = 0; i < n; ++i) { string temp; cin >> temp; for (int j = 0; j < 5; ++j) { if (temp.at(0) == s.at(j)) { ++c.at(j); break; } } } ll ans = c.at(0) * c.at(1) * c.at(2) + c.at(0) * c.at(1) * c.at(3) + c.at(0) * c.at(1) * c.at(4) + c.at(0) * c.at(2) * c.at(3) + c.at(0) * c.at(2) * c.at(4) + c.at(0) * c.at(3) * c.at(4) + c.at(1) * c.at(2) * c.at(3) + c.at(1) * c.at(2) * c.at(4) + c.at(1) * c.at(3) * c.at(4) + c.at(2) * c.at(3) * c.at(4); cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.util.*; public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); int N = fs.nextInt(); int[] arr = new int[26]; List<Integer> li = new ArrayList<>(); for (int i = 0; i < N; ++i) { String s = fs.next(); if (s.charAt(0) == 'M' || s.charAt(0) == 'A' || s.charAt(0) == 'C' || s.charAt(0) == 'R' || s.charAt(0) == 'H') { ++arr[s.charAt(0)-65]; } } for (int i = 0; i < 25; ++i) { if (arr[i] != 0) { li.add(arr[i]); } } long ans = 0; for (int i = 0; i <= li.size()-3; ++i) { for (int j = i+1; j < li.size()-1; ++j) { for (int k = j+1; k < li.size(); ++k) { ans += li.get(i) * li.get(j) * li.get(k); } } } System.out.println(ans); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> c(5, 0); for (int i = 0; i < n; i++) { string s; cin >> s; if (s.at(0) == 'M') c.at(0)++; else if (s.at(0) == 'A') c.at(1)++; else if (s.at(0) == 'R') c.at(2)++; else if (s.at(0) == 'C') c.at(3)++; else if (s.at(0) == 'H') c.at(4)++; } long long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += c.at(i) * c.at(j) * c.at(k); } } } cout << ans << endl; return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long m = 0, a = 0, r = 0, c = 0, h = 0; int main() { long long n, flag = 0; char b[20]; scanf("%I64d", &n); for (long long i = 0; i < n; i++) { scanf(" %s", b); if (b[0] == 'M') m++; if (b[0] == 'A') a++; if (b[0] == 'R') r++; if (b[0] == 'C') c++; if (b[0] == 'H') h++; } long long x = 1, y = 0; if (m != 0) flag++; if (a != 0) flag++; if (r != 0) flag++; if (c != 0) flag++; if (h != 0) flag++; if (m != 0) x = x * m; if (a != 0) x = x * a; if (r != 0) x = x * r; if (c != 0) x = x * c; if (h != 0) x = x * h; if (flag <= 2) { printf("0\n"); return 0; } if (flag == 3) { printf("%I64d\n", x); return 0; } if (flag == 4) { if (m != 0) y += x / m; if (a != 0) y += x / a; if (r != 0) y += x / r; if (c != 0) y += x / c; if (h != 0) y += x / h; printf("%I64d\n", y); return 0; } y = x / m / a + x / m / r + x / m / c + x / m / h + x / a / r + x / a / c + x / a / h + x / r / c + x / r / h + x / c / h; printf("%I64d\n", y); return 0; }
p03425 AtCoder Beginner Contest 089 - March
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ" ], "output": [ "2", "7", "0" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
N = gets.chomp.to_i S = [] march = 'MARCH' cnt = Array.new(5,0) N.times do line = gets.chomp if march.include?(line[0]) cnt[march.index(line[0])]+=1 end end sum = 0 param = [0,0,1,3,7] 3.times do |i| if cnt[i] >= 1 tmp = cnt[i] par = 0 for j in (i+1)..4 do if cnt[j] > 0 tmp*=cnt[j] cnt[j] = 1 par += 1 end end sum+=tmp*param[par] end end print "#{sum}\n"