Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, m = 0, a = 0, r = 0, c = 0, h = 0;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M') {
m++;
}
if (S[i][0] == 'A') {
a++;
}
if (S[i][0] == 'R') {
r++;
}
if (S[i][0] == 'C') {
c++;
}
if (S[i][0] == 'H') {
h++;
}
}
cout << (m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + a * c * h + r * c * h);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
const vector<char> V = {'M', 'A', 'R', 'C', 'H'};
int N;
cin >> N;
vector<int> cnt(5, 0);
for (int i = 0; i < N; ++i) {
string S;
cin >> S;
char &c = S.front();
for (int j = 0; j < 5; ++j) {
if (c == V.at(j)) {
cnt.at(j)++;
}
}
}
ll ans = 0;
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += cnt.at(i) * cnt.at(j) * cnt.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 | python3 | n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(n):
p = input()
if p[0] == "M":
m += 1
if p[0] == "A":
a += 1
if p[0] == "R":
r += 1
if p[0] == "C":
c += 1
if p[0] == "H":
h += 1
if m > 0:
cnt += 1
if a > 0:
cnt += 1
if r > 0:
cnt += 1
if c > 0:
cnt += 1
if h > 0:
cnt += 1
if cnt < 3:
print(0)
else:
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*h + a*c*h + r*c*h)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | //
// main.cpp
// CompetitiveProgramming
//
// Created by Yuma Kikuchi on 2018/03/02.
// Copyright © 2018年 yumarimo. All rights reserved.
//
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
llong pow(int x, int n) {
llong ans = x;
if (n == 0) return 1;
for(int i = 0; i < n - 1; i++) {
ans *= x;
}
return ans;
}
void swap(int *X, int *Y){
int t = *X; *X = *Y; *Y = t;
}
string toUpper(string s) {
string t = s;
REP(i, s.size()) {
t[i] = toupper(s[i]);
}
return t;
}
string toLower(string s) {
string t = s;
REP(i, s.size()) {
t[i] = tolower(s[i]);
}
return t;
}
const static int Max = 100001;
llong dp[Max][Max];
llong nCr(llong n, llong r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n;
if(dp[n][r]) return dp[n][r];
return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}
int main() {
int n; cin >> n;
int N[5] = {0};
string name;
bool check[5] = {false};
int cnt = 0;
REP(i, n) {
cin >> name;
if (name[0] == 'M') {
N[0]++;
check[0] = true;
cnt++;
} else if (name[0] == 'A') {
N[1]++;
check[1] = true;
cnt++;
} else if (name[0] == 'R') {
N[2]++;
check[2] = true;
cnt++;
} else if (name[0] == 'C') {
N[3]++;
check[3] = true;
cnt++;
} else if (name[0] == 'H') {
N[4]++;
check[4] = true;
cnt++;
} else {
continue;
}
}
int T = 0;
REP(i, 5) {
if (check[i]) T++;
}
if (cnt >= 3 && T >= 3) {
int tmp = 0;
REP(i, 5) {
if (N[i] >= 2) tmp += nCr(N[i], 2) * (cnt - N[i]);
}
cout << nCr(cnt, 3) - tmp << endl;
} else {
cout << 0 << endl;
}
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
ll lcm(ll a, ll b)
{
return a * b / __gcd(a, b);
}
int main()
{
int N;
cin >> N;
vector<string> S(N);
string A;
vector<int> march(5);
int P[10] = {0,0,0,0,0,0,1,1,2,1};
int Q[10] = {1,1,1,2,2,3,2,2,3,3};
int R[10] = {2,3,4,3,4,4,3,4,4,4};
for (int i = 0; i < N; i++)
{
cin >> A;
S[i] = A[0];
if("M" == S[i]){
march[0]++;
}
else if("A" == S[i]){
march[1]++;
}
else if("R" == S[i]){
march[2]++;
}
else if("C" == S[i]){
march[3]++;
}
else if(S[i] == "H"){
march[4]++;
}
}
ll ans = 0;
for (int d = 0; d < 10;d++)
{
ans += march[P[d]] * march[Q[d]] * march[R[d]];
}
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> member(5, 0);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') member[0]++;
if (s[0] == 'A') member[1]++;
if (s[0] == 'R') member[2]++;
if (s[0] == 'C') member[3]++;
if (s[0] == 'H') member[4]++;
}
vector<int> v1 = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
vector<int> v2 = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
vector<int> v3 = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
long long ans = 0;
for (int i = 0; i < 10; i++) {
ans += member[v1[i]] * member[v2[i]] * member[v3[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 | use std::io::Read;
use std::collections::HashMap;
fn main() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let answer = solve(&buf);
println!("{}", answer);
}
fn solve(input: &str) -> String {
let mut iterator = input.split_whitespace();
let march: Vec<char> = "MARCH".chars().collect();
let n: usize = iterator.next().unwrap().parse().unwrap();
let mut counts: HashMap<char, usize> = HashMap::new();
for _ in 0..n {
let first_char = iterator.next().unwrap().chars().next().unwrap();
if march.contains(&first_char) {
*counts.entry(first_char).or_insert(0) += 1;
}
}
const ZERO: usize = 0;
let mut ans = 0;
for i in 0..3 {
for j in (i + 1)..4 {
for k in (j + 1)..5 {
let ci = counts.get(&march[i]).unwrap_or(&ZERO);
let cj = counts.get(&march[j]).unwrap_or(&ZERO);
let ck = counts.get(&march[k]).unwrap_or(&ZERO);
ans += *ci * *cj * *ck;
}
}
}
return ans.to_string();
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i);
using namespace std;
int main(){
string s="MARCH";
int c[5]={};
int n;
cin >> n;
rep(i,n){
string t;
cin >> t;
rep (j,5){
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>
struct Combination {
int a;
int b;
int c;
};
using namespace std;
vector<Combination> v_c;
void recursive_comb(vector<int>& indexes, int s, int rest,
std::function<void(vector<int>&)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
return;
}
void foreach_comb(int n, int k, std::function<void(vector<int>&)> f) {
vector<int> indexes(k);
recursive_comb(indexes, n - 1, k, f);
return;
}
int main() {
int n;
cin >> n;
vector<int> v_num(5, 0);
for (int i = 0; i < n; ++i) {
string str;
cin >> str;
if (str[0] == 'M') v_num[0]++;
if (str[0] == 'A') v_num[1]++;
if (str[0] == 'R') v_num[2]++;
if (str[0] == 'C') v_num[3]++;
if (str[0] == 'H') v_num[4]++;
}
v_c.reserve(10);
foreach_comb(5, 3, [](vector<int>& indexes) {
Combination c{indexes[0], indexes[1], indexes[2]};
v_c.push_back(c);
});
int score = 0;
for (int i = 0; i < v_c.size(); i++) {
score += v_num[v_c[i].a] * v_num[v_c[i].b] * v_num[v_c[i].c];
}
cout << score << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
string b;
vector<int> c(5);
long long ans = 0;
for (int i = 0; i < a; i++) {
cin >> b;
if (b[0] == 'M') {
c[0]++;
}
if (b[0] == 'A') {
c[1]++;
}
if (b[0] == 'R') {
c[2]++;
}
if (b[0] == 'C') {
c[4]++;
}
if (b[0] == 'H') {
c[3]++;
}
}
for (int i = 0; i < 5; i++) {
for (int u = i + 1; u < 5; u++) {
for (int j = u + 1; j < 5; j++) {
ans += c[i] * c[j] * c[u];
}
}
}
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 | import java.io.BufferedReader
import java.io.PrintWriter
var out: PrintWriter = PrintWriter(System.out) // これを使って出力すると早い
fun main(args: Array<String>) {
try {
val charCount =
mutableMapOf(*charArrayOf('M', 'A', 'R', 'C', 'H').map { Pair(it, 0) }.toTypedArray())
val n = MyScanner.readAsInt()
for (i in 1..n) {
val head = MyScanner.readAsString().first()
if (charCount.containsKey(head)) {
charCount[head] = charCount[head]!! + 1
}
}
val target = charCount.filter { it.value > 0 }.map { it.value }
if (target.count() <= 2){
out.println(0)
return
}
var score = 0L
for (i in 0 until target.count()){
for(j in (i+1) until target.count()){
score += i.toLong() * j
}
}
out.println(score)
} finally {
out.flush() // 消さない
}
}
/**
* 読み取り
*/
class MyScanner {
companion object {
private var reader: BufferedReader = System.`in`.bufferedReader()
fun reset() {
reader = System.`in`.bufferedReader()
}
fun readAsInt(): Int {
return Integer.parseInt(reader.readLine())
}
// Int
fun readAsIntArray(delimiters: String = " "): IntArray {
return reader
.readLine()
.split(delimiters)
.map { s -> Integer.parseInt(s) }
.toIntArray()
}
fun readNTimesAsInt(n: Int): IntArray {
return (1..n).map { readAsInt() }.toIntArray()
}
fun readNTimesAsIntArray(n: Int): Array<IntArray> {
return (1..n).map { readAsIntArray() }.toTypedArray()
}
// long
// TODO 別の方法を考える
fun readAsLong(): Long {
return reader.readLine().toLong()
}
fun readAsLongArray(delimiters: String = " "): LongArray {
return reader.readLine()
.split(delimiters)
.map { s -> s.toLong() }
.toLongArray()
}
fun readNTimesAsLong(n: Int): LongArray {
return (1..n).map { readAsLong() }.toLongArray()
}
fun readAsString(): String {
return reader.readLine()
}
fun readAsStringArray(delimiters: String = " "): Array<String> {
return readAsString().split(delimiters).toTypedArray()
}
}
}
/**
* 要素とその個数を出力
*/
fun <T> Array<T>.ofCountMap(): Map<T, Int> {
return this.groupBy { it }.mapValues { it.value.count() }
}
/**
* 文字とその個数を出力
*/
fun String.ofCountMap(): Map<Char, Int> {
return this.toCharArray().ofCountMap()
}
/**
* 文字とその個数を出力
*/
fun CharArray.ofCountMap(): Map<Char, Int> {
return this.groupBy { it }.mapValues { it.value.count() }
}
/**
* Combination, nCk mod p を求める
* https://ja.wikipedia.org/wiki/%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%A9%E9%80%86%E6%95%B0
* http://drken1215.hatenablog.com/entry/2018/06/08/210000
* @param maxN 最大のn
* @param mod 素数p
*/
class ModCombination(private val maxN: Int, private val mod: Int = 1000000007) {
val fac: IntArray = IntArray(maxN)
val finv: IntArray = IntArray(maxN)
init {
val inv: IntArray = IntArray(maxN)
fac[0] = 1
fac[1] = 1
inv[0] = 1
inv[1] = 1
for (i in 2..maxN) {
fac[i] = fac[i - 1] * i % mod // 累積
// mod % i < i
inv[i] = mod - ((inv[mod % i].toLong()) * (mod / i) % mod).toInt()
finv[i] = finv[i - 1] * inv[i] % mod
}
}
/**
* nCk mod p
*/
fun Calc(n: Int, k: Int): Int {
if (n < k || n < 0 || k < 0) {
return 0
}
return ((fac[n].toLong() * finv[k] % mod) * finv[n - k] % mod).toInt()
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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];
int main() {
int n;
scanf("%d", &n);
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
char ch[5000];
scanf("%s", ch);
if (ch[0] == 'M')
a[1]++;
else if (ch[0] == 'A')
a[2]++;
else if (ch[0] == 'R')
a[3]++;
else if (ch[0] == 'C')
a[4]++;
else if (ch[0] == 'H')
a[5]++;
}
long long ans = 0;
for (int i = 1; i <= 3; i++)
for (int j = i + 1; j <= 4; j++)
for (int k = j + 1; k <= 5; k++) ans += a[i] * a[j] * a[k];
printf("%lld", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int count[5];
int combine[10][3] = {{0, 1, 2}, {0, 1, 3}, {0, 1, 4}, {0, 2, 3}, {0, 2, 4},
{0, 3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}};
int main() {
int n;
long long ans;
char str[15];
while (~scanf("%d", &n)) {
ans = 0;
for (int i = 0; i < 5; i++) count[i] = 0;
for (int i = 0; i < n; i++) {
scanf("%s", str);
if (str[0] == 'M')
count[0]++;
else if (str[0] == 'A')
count[1]++;
else if (str[0] == 'R')
count[2]++;
else if (str[0] == 'C')
count[3]++;
else if (str[0] == 'H')
count[4]++;
else
continue;
}
for (int i = 0; i < 9; i++) {
ans += count[combine[i][0]] * count[combine[i][1]] * count[combine[i][2]];
}
printf("%lld\n", ans);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long ans = 0;
cin >> N;
int C[6] = {};
string dict = "MARCH";
for (int i = 0; i < N; i++) {
string S;
cin >> S;
C[dict.find(S[0]) + 1]++;
}
for (int i = 1; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 6; 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 | UNKNOWN | <?php
fscanf(STDIN,"%d",$n);
$chars = array();
$march = array('M','A','R','C','H');
$index = '';
for($i=0;$i<$n;$i++){
$tmp_c = trim(fgets(STDIN));
if(in_array($tmp_c[0],$march)) $chars[$tmp_c[0]]++;
}
//print_r($chars);
$char_count = count($chars);
$patern1 = ($char_count*($char_count-1)*($char_count-2))/6;
//echo $patern1;
foreach($chars as $c){
if($c>=2){
$tmp = ($c-1)*((($n-$c-1)*($n-$c-2))/2);
$patern1 += $tmp;
}
}
echo $patern1;
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
vector<int> v(5, 0);
for (int i = 0; i < n; i++) {
cin >> s;
switch (s[0]) {
case 'M':
v[0]++;
break;
case 'A':
v[1]++;
break;
case 'R':
v[2]++;
break;
case 'C':
v[3]++;
break;
case 'H':
v[4]++;
break;
default:
break;
}
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += v[i] * v[j] * v[k];
}
}
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import collections
N = int(input())
S = [input()[0] for _ in range(N)]
A = []
ans = 0
for i in S:
if i == 'M' or i == 'A' or i == 'R' or i == 'C' or i == 'H':
A.append(i)
C = collections.Counter(A).most_common()
v,c =zip(*C)
s = c[0]
for i in range(1,len(c)):
s *= c[i]
ans += s
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 j, i, s = 0;
cin >> j;
string a;
for (i = 0; i < j; i++) {
cin >> a;
if (a[0] == 'M' || a[0] == 'A' || a[0] == 'R' || a[0] == 'C' || a[0] == 'H')
s++;
}
cout << s * (s - 1) * (s - 2) / 6 << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) {
return gcd(b, a);
} else if (a % b) {
return gcd(b, a % b);
} else {
return b;
}
}
int main() {
long long N;
cin >> N;
string S[100];
long long m = 0;
long long a = 0;
long long r = 0;
long long c = 0;
long long h = 0;
for (int i = 0; i < N; ++i) {
cin >> S[i];
if (S[i].at(0) == 'M') {
m++;
} else if (S[i].at(0) == 'A') {
a++;
} else if (S[i].at(0) == 'R') {
r++;
} else if (S[i].at(0) == 'C') {
c++;
} else if (S[i].at(0) == 'H') {
h++;
}
}
long long ans = 0;
if (m > 0 && a > 0 && r > 0) {
ans += m * a * r;
}
if (m > 0 && a > 0 && h > 0) {
ans += m * a * h;
}
if (m > 0 && a > 0 && c > 0) {
ans += m * a * c;
}
if (m > 0 && c > 0 && r > 0) {
ans += m * c * r;
}
if (m > 0 && h > 0 && r > 0) {
ans += m * h * r;
}
if (m > 0 && h > 0 && c > 0) {
ans += m * h * c;
}
if (a > 0 && r > 0 && c > 0) {
ans += c * a * r;
}
if (a > 0 && r > 0 && h > 0) {
ans += h * a * r;
}
if (a > 0 && c > 0 && h > 0) {
ans += h * a * c;
}
if (r > 0 && c > 0 && h > 0) {
ans += h * c * r;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
map<char, int> name;
string str = "MARCH";
for (int i = 0; i < str.length(); i++) name[str[i]] = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M')
name['M']++;
else if (S[i][0] == 'A')
name['A']++;
else if (S[i][0] == 'R')
name['R']++;
else if (S[i][0] == 'C')
name['C']++;
else if (S[i][0] == 'H')
name['H']++;
}
vector<int> A;
int sum = 0;
for (int i = 0; i < str.length(); i++) {
if (name[str[i]] > 0) A.push_back(name[str[i]]);
sum += name[str[i]];
}
int SIZE = A.size();
long long ans = 0;
for (int i = 0; i < SIZE - 2; i++) {
for (int j = i + 1; j < SIZE - 1; j++) {
for (int k = j + 1; k < SIZE; k++) {
ans += A[i] * A[j] * A[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
map<char, long long> mp;
for (int i = 0; i < N; i++) {
cin >> S;
mp[S[0]]++;
}
string march = "MARCH";
int res = 0;
for (int i = 0; i < 3; i++) {
for (int k = i + 1; k < 4; k++) {
for (int l = k + 1; l < 5; l++) {
res += mp[march[i]] * mp[march[k]] * mp[march[l]];
}
}
}
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;
template <typename T>
void printmatrix(vector<vector<T> > ar) {
for (int i = 0; i < (int)ar.size(); i++) {
for (int j = 0; j < (int)ar.size(); j++) {
cout << ar[i][j];
}
cout << endl;
}
}
template <typename T>
void printvector(vector<T> vec) {
for (int i = 0; i < (int)vec.size(); i++) {
cout << vec[i] << endl;
}
}
template <typename T>
void unique(vector<T>& vec) {
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
vector<T> cumsum(vector<T> vec) {
vector<T> newvec((T)vec.size());
int tmp = 0;
for (int i = 0; i < (int)vec.size(); i++) {
tmp += vec[i];
newvec[i] = tmp;
}
return newvec;
}
int main(int argc, char const* argv[]) {
int n;
cin >> n;
vector<int> v(5, 0);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') v[0]++;
if (s[0] == 'A') v[1]++;
if (s[0] == 'R') v[2]++;
if (s[0] == 'C') v[3]++;
if (s[0] == 'H') v[4]++;
}
int c = 0;
for (int i = 0; i < 5; i++)
if (v[i] > 0) c++;
if (c < 3) {
cout << 0 << endl;
} else {
long long total = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
if (v[i] * v[j] * v[k] > 0) {
total += v[i] * v[j] * v[k];
}
}
}
}
cout << total << 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;
while (cin >> n) {
long long int ans = 0;
int ansm = 0, ansa = 0, ansr = 0, ansc = 0, ansh = 0;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
ansm++;
else if (s[0] == 'A')
ansa++;
else if (s[0] == 'R')
ansr++;
else if (s[0] == 'C')
ansc++;
else if (s[0] == 'H')
ansh++;
}
ans += ansm * ansa * ansr;
ans += ansm * ansa * ansc;
ans += ansm * ansa * ansh;
ans += ansm * ansr * ansc;
ans += ansm * ansr * ansh;
ans += ansm * ansc * ansh;
ans += ansa * ansr * ansc;
ans += ansa * ansr * ansh;
ans += ansa * ansc * ansh;
ans += ansr * ansc * ansh;
cout << ans << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> vec(5);
string str;
for (int(i) = (0); (i) < (n); (i)++) {
cin >> str;
if (str[0] == 'M') vec[0]++;
if (str[0] == 'A') vec[1]++;
if (str[0] == 'R') vec[2]++;
if (str[0] == 'C') vec[3]++;
if (str[0] == 'H') vec[4]++;
}
ll ans = 0;
for (int(i) = (0); (i) < (5); (i)++) {
for (int(j) = (i + 1); (j) < (5); (j)++) {
for (int(k) = (j + 1); (k) < (5); (k)++) {
ans += (vec[i] * vec[j] * vec[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;
map<char, set<string>> name_set = {
{'M', {}}, {'A', {}}, {'R', {}}, {'C', {}}, {'H', {}}};
for (int i = 0; i < N; i++) {
string tmp;
cin >> tmp;
if (name_set.find(tmp[0]) != name_set.end()) name_set[tmp[0]].insert(tmp);
}
int sum = 0;
string s = "MARCH";
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += name_set[s[i]].size() * name_set[s[j]].size() *
name_set[s[k]].size();
}
}
}
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 | python3 | d = {}
for _ in range(int(input())):
s = input()[0]
d[s] = d.get(s, 0) + 1
b, ans = False, 1
for m in "MARCH":
if m in d:
b = True
ans *= d[m]
else:
print(ans if b else 0) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int64_t INF = 1LL << 60;
int main() {
int N;
cin >> N;
int c[5] = {0};
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
c[0]++;
}
if (s[0] == 'A') {
c[1]++;
}
if (s[0] == 'R') {
c[2]++;
}
if (s[0] == 'C') {
c[3]++;
}
if (s[0] == 'H') {
c[4]++;
}
}
int64_t 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;
void SolveA() {
int n, cnt = 0;
scanf("%d", &n);
while (n >= 3) {
n = n - 3;
cnt++;
}
printf("%d\n", cnt);
}
void SolveB() {
int n;
scanf("%d", &n);
string s = "";
for (int i = 0; i < n; i++) {
string str;
cin >> str;
s.append(str);
}
bool isPink = false;
if (s.find('Y') != string::npos) {
isPink = true;
}
if (isPink) {
printf("Four\n");
} else {
printf("Three\n");
}
}
void SolveC() {
long long int n;
cin >> n;
vector<string> strs;
for (long long int i = 0; i < n; i++) {
string str;
cin >> str;
strs.push_back(str);
}
}
void SolveD() {
int H, W, D;
scanf("%d %d %d", &H, &W, &D);
int posx[90001], posy[90001];
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
int A;
scanf("%d", &A);
posx[A] = w + 1;
posy[A] = h + 1;
}
}
vector<int> d;
d.resize(90001, 0);
for (int i = D + 1; i <= H * W; i++) {
d[i] = d[i - D] + abs(posx[i] - posx[i - D]) + abs(posy[i] - posy[i - D]);
}
int Q;
scanf("%d", &Q);
while (Q--) {
int L, R;
scanf("%d %d", &L, &R);
printf("%d\n", d[R] - d[L]);
}
}
void EditSolveC() {
string str = "MARCH";
int c[5] = {};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == str[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 << "\n";
}
int main() { EditSolveC(); }
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
int N;
cin >> N;
map<char, ll> m;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
char c = S.at(0);
if (m.count(c) == 0) {
m[c] = 1;
} else {
m[c]++;
}
}
ll a = m['M'], b = m['A'], c = m['R'], d = m['C'], e = m['H'];
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
ll ans = 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;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vc(5, 0);
string s;
string march = "MARCH";
for (int i = 0; i < (n); i++) {
cin >> s;
for (int i = 0; i < (5); i++) {
if (s[0] == march[i]) {
vc[i]++;
break;
}
}
}
unsigned long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
if (vc[i] * vc[j] * vc[k]) {
ans += vc[i] * vc[j] * vc[k];
}
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string t;
map<char, int> mp;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
for (int i = 0; i < n; i++) {
cin >> t;
if (mp.find(t[0]) == mp.end())
mp[t[0]] = 1;
else
mp[t[0]]++;
}
long m = mp['M'], a = mp['A'], r = mp['R'], c = mp['C'], h = mp['H'], sum = 0;
sum += m * a * r;
sum += m * a * c;
sum += m * a * h;
sum += m * r * c;
sum += m * r * h;
sum += a * r * c;
sum += a * r * h;
sum += a * c * h;
sum += r * c * h;
cout << sum;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
int mp[5] = {0};
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') mp[0]++;
if (s[0] == 'A') mp[1]++;
if (s[0] == 'R') mp[2]++;
if (s[0] == 'C') mp[3]++;
if (s[0] == 'H') mp[4]++;
}
long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += mp[i] * mp[j] * mp[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
ss = []
N.times do
s = gets.chomp[0]
if ['M', 'A', 'R', 'C', 'H'].include?(s)
ss << s
end
end
puts ss.combination(3).to_a.select { |aaaa| aaaa.uniq.count == 3 }.count |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < (n); ++i) {
cin >> str;
if (str[0] == 'M') {
m++;
}
if (str[0] == 'A') {
a++;
}
if (str[0] == 'R') {
r++;
}
if (str[0] == 'C') {
c++;
}
if (str[0] == 'H') {
h++;
}
}
long long ans = 0;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << (ans) << endl;
;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import sys
input = sys.stdin.readline
n=int(input())
S=[input().strip() for _ in range(n)]
a=[]
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
from collections import Counter
for s in S:
if s[0] in ["M","A","R","C","H"]:
a.append(s[0])
if len(a)==0:
print(0)
exit()
a=Counter(a)
#print(a)
asum=sum(a.values())
b=0
c=0
for i in a.values():
if i ==1:
continue
if i==2:
b+=asum-i
if i>=3:
b+=cmb(i,2)*(asum-i)
c+=cmb(i,3)
print(cmb(asum,3)-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 | python3 | import itertools
N = int(input())
SK = {"M":0,"A":1,"R":2,"C":3,"H":4}
SD = [0]*5
del_list = []
A = ["M","A","R","C","H"]
for x in range(N):
tmp = str(input())
if tmp[0] in A:
SD[SK[tmp[0]]] +=1
C = 0
for x in range(5)
if SD[x] == 0 :
del_list.append(x)
C +=1
del_list.reverse()
for x in del_list:
SD.pop(x)
if C >2:
print(0)
else:
Z = 5-C
k = itertools.combinations(range(Z), 3)
ans = 0
for x in k:
ans += SD[x[0]]*SD[x[1]]*SD[x[2]]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
long long int fact[1000005], inverse[1000005];
long long int Bigmod(int a, int b) {
if (b == 0) return 1 % MOD;
long long int x = Bigmod(a, b / 2);
x = (x * x) % MOD;
if (b % 2 == 1) x = (x * a) % MOD;
return x;
}
long long int nCr(int x, int y) {
if (x < 0 || y < 0 || x < y) return 0;
return fact[x] * (inverse[y] * inverse[x - y] % MOD) % MOD;
}
void pre_cal() {
fact[0] = 1;
for (int i = 1; i <= 1000000; i++) fact[i] = fact[i - 1] * 1LL * i % MOD;
inverse[1000000] = Bigmod(fact[1000000], MOD - 2);
for (int i = 1000000; i > 0; i--) {
inverse[i - 1] = i * 1LL * inverse[i] % MOD;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
pre_cal();
long long int tot = 0, m = 0, a = 0, c = 0, h = 0, r = 0, n;
cin >> n;
while (n--) {
string s;
cin >> s;
if (s[0] == 'M')
m++;
else if (s[0] == 'R')
r++;
else if (s[0] == 'A')
a++;
else if (s[0] == 'C')
c++;
else if (s[0] == 'H')
h++;
}
if (m) tot++;
if (a) tot++;
if (r) tot++;
if (c) tot++;
if (h) tot++;
long long int ans = nCr(tot, 3);
long long int ori = (ans / 2) + 1;
if (m) ans += (ori) * (m - 1);
if (a) ans += (ori) * (a - 1);
if (r) ans += (ori) * (r - 1);
if (c) ans += (ori) * (c - 1);
if (h) ans += (ori) * (h - 1);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt_march[5] = {0}, ans = 0;
cin >> n;
string s[n];
for (int i = (0); i < (5); i++) {
cnt_march[i] = 0;
}
for (int i = (0); i < (n); i++) {
cin >> s[i];
switch (s[i][0]) {
case 'M':
cnt_march[0]++;
break;
case 'A':
cnt_march[1]++;
break;
case 'R':
cnt_march[2]++;
break;
case 'C':
cnt_march[3]++;
break;
case 'H':
cnt_march[4]++;
break;
}
}
for (int i = (0); i < (5); i++) {
for (int j = (i + 1); j < (5); j++) {
for (int k = (j + 1); k < (5); k++) {
ans += cnt_march[i] * cnt_march[j] * cnt_march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, A[5] = {0};
string S;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
if (S[0] == 'M') {
A[0]++;
} else if (S[0] == 'A') {
A[1]++;
} else if (S[0] == 'R') {
A[2]++;
} else if (S[0] == 'C') {
A[3]++;
} else if (S[0] == 'H') {
A[4]++;
}
}
long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += A[i] * A[j] * A[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
string str;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M') {
m++;
}
if (str[0] == 'A') {
a++;
}
if (str[0] == 'R') {
r++;
}
if (str[0] == 'C') {
c++;
}
if (str[0] == 'H') {
h++;
}
}
unsigned long long sum = 0;
sum += m * a * r;
sum += m * a * c;
sum += m * a * h;
sum += m * r * c;
sum += m * r * h;
sum += m * c * h;
sum += a * r * c;
sum += a * r * h;
sum += a * c * h;
sum += r * c * h;
printf("%lld\n", sum);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
vector<char> s(N);
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
cin >> S.at(i);
s.at(i) = S.at(i).at(0);
if (s.at(i) == 'M')
m++;
else if (s.at(i) == 'A')
a++;
else if (s.at(i) == 'R')
r++;
else if (s.at(i) == 'C')
c++;
else if (s.at(i) == 'H')
h++;
}
long ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < (n); ++i) cin >> s[i];
vector<ll> a(5, 0);
for (int i = 0; i < (n); ++i) {
if (s[i][0] == 'M')
++a[0];
else if (s[i][0] == 'A')
++a[1];
else if (s[i][0] == 'R')
++a[2];
else if (s[i][0] == 'C')
++a[3];
else if (s[i][0] == 'H')
++a[4];
}
ll ans = 0;
for (int i = 0; i < 3; ++i) {
if (a[i] == 0) continue;
for (int j = i + 1; j < 4; ++j) {
if (a[j] == 0) continue;
for (int k = j + 1; k < 5; ++k) {
if (a[k] == 0) continue;
ans += (a[i] * a[j] * a[k]);
}
}
}
cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4]
<< "\n";
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
using namespace std;
int n, m;
int a[10];
int prime(int x) {
if (x == 1) return 0;
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return 0;
return 1;
}
int check(int x, int y) {
if (x > n || x < 1 || y >= m || y < 0) return 0;
return 1;
}
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
if (s[0] == 'M') a[1]++;
if (s[0] == 'A') a[2]++;
if (s[0] == 'R') a[3]++;
if (s[0] == 'C') a[4]++;
if (s[0] == 'H') a[5]++;
}
long long ans = 0;
ans = 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;
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())
nm = 0
na = 0
nr = 0
nc = 0
nh = 0
for i in range(n):
a = input()
for j in a:
b = j
break
if b == "M":
nm += 1
elif b == "A":
na += 1
elif b == "R":
nr += 1
elif b == "C":
nc += 1
elif b == "H":
nh += 1
count = 0
if nm == 0:
count += 1
if na == 0:
count += 1
if nr == 0:
count += 1
if nc == 0:
count += 1
if nh == 0:
count += 1
count = 5-count
num = 0
if count <= 2 :
print(0)
elif count == 3:
num = 1
if nm != 0:
num = num * nm
if na != 0:
num = num * na
if nr != 0:
num = num * nr
if nc != 0:
num = num * nc
if nh != 0:
num = num * nh
print(num)
elif count == 4:
num = 4
if nm != 0:
num = num * nm
if na != 0:
num = num * na
if nr != 0:
num = num * nr
if nc != 0:
num = num * nc
if nh != 0:
num = num * nh
print(num)
elif count == 5:
num = 10
if nm != 0:
num = num * nm
if na != 0:
num = num * na
if nr != 0:
num = num * nr
if nc != 0:
num = num * nc
if nh != 0:
num = num * nh
print(num)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #{{{ header
{.hints:off warnings:off.}
import algorithm, sequtils, tables, macros, math, sets, strutils
when defined(MYDEBUG):
import header
proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc getchar(): char {.header: "<stdio.h>", varargs.}
proc nextInt(): int = scanf("%lld",addr result)
proc nextFloat(): float = scanf("%lf",addr result)
proc nextString(): string =
var get = false
result = ""
while true:
let c = getchar()
if int(c) > int(' '):
get = true
result.add(c)
else:
if get: break
get = false
type SomeSignedInt = int|int8|int16|int32|int64|BiggestInt
type SomeUnsignedInt = uint|uint8|uint16|uint32|uint64
type SomeInteger = SomeSignedInt|SomeUnsignedInt
type SomeFloat = float|float32|float64|BiggestFloat
template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)
template inf(T): untyped =
when T is SomeFloat: T(Inf)
elif T is SomeInteger: ((T(1) shl T(sizeof(T)*8-2)) - (T(1) shl T(sizeof(T)*4-1)))
else: assert(false)
proc sort[T](v: var seq[T]) = v.sort(cmp[T])
proc discardableId[T](x: T): T {.discardable.} =
return x
macro `:=`(x, y: untyped): untyped =
if (x.kind == nnkIdent):
return quote do:
when declaredInScope(`x`):
`x` = `y`
else:
var `x` = `y`
discardableId(`x`)
else:
return quote do:
`x` = `y`
discardableId(`x`)
macro dump*(x: typed): untyped =
let s = x.toStrLit
let r = quote do:
debugEcho `s`, " = ", `x`
return r
#}}}
proc solve(N:int, S:seq[string]) =
v := newSeq[int](5)
for i in 0..<N:
if S[i][0] == 'M': v[0] += 1
elif S[i][0] == 'A': v[1] += 1
elif S[i][0] == 'R': v[2] += 1
elif S[i][0] == 'C': v[3] += 1
elif S[i][0] == 'H': v[4] += 1
ans := 0
for i in 0..<N:
for j in i+1..<N:
for k in j+1..<N:
ans += v[i]*v[j]*v[k]
echo ans
return
#{{{ main function
proc main() =
var N = 0
N = nextInt()
var S = newSeqWith(N, "")
for i in 0..<N:
S[i] = nextString()
solve(N, S);
return
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;
void solve() {
int n;
cin >> n;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int a[5] = {0, 0, 0, 0, 0};
for (int _ = 0; _ < n; _++) {
string s;
cin >> s;
for (int i = 0; i < 5; i++) {
if (s[0] == c[i]) a[i]++;
}
}
long long res = 0;
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
for (int k = 0; k < 5; k++)
if (i != j && i != k && j != k) {
res += 1ll * a[i] * a[j] * a[k];
}
cout << res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
cout << 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 cmp = "MARCH";
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S[i];
map<char, long long> dic;
for (int i = 0; i < 5; i++) {
dic[cmp[i]] = i;
}
vector<int> cnt(5, 0);
for (int i = 0; i < N; i++) {
if (dic.count(S[i][0])) cnt[dic[S[i][0]]]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k < j; 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 i, m = 0, a = 0, r = 0, c = 0, h = 0, n;
cin >> n;
char s[100000];
for (i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
m++;
else if (s[0] == 'A')
a++;
else if (s[0] == 'R')
r++;
else if (s[0] == 'C')
c++;
else if (s[0] == 'H')
h++;
}
cout << m * a * r * +m * a * c + m * a * h + m * r * c +
m * r * h * +m * c * h + a * r * c + a * r * h + a * c * h +
r * c * h
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string a;
int b[5] = {0};
cin >> N;
while (N--) {
cin >> a;
if (a[0] == 'M')
b[0]++;
else if (a[0] == 'A')
b[1]++;
else if (a[0] == 'R')
b[2]++;
else if (a[0] == 'C')
b[3]++;
else if (a[0] == 'H')
b[4]++;
}
int flag = 0;
long s;
for (int i = 0; i < 5; i++)
if (b[i]) flag++;
if (flag < 3)
printf("0\n");
else if (flag == 3) {
s = 1;
for (int i = 0; i < 5; i++)
if (b[i]) s *= b[i];
cout << s << endl;
} else if (flag >= 4) {
s = 0;
int x, y, z;
for (x = 0; x < 3; x++)
for (y = x + 1; y < 4; y++)
for (z = y + 1; z < 5; z++)
if (b[x] && b[y] && b[z]) s += b[x] * b[y] * b[z];
cout << s << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
int n;
cin >> n;
unordered_map<char, int> map;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
map[s.at(0)]++;
}
ll ans;
ans += map['M'] * map['A'] * map['R'];
ans += map['M'] * map['A'] * map['C'];
ans += map['M'] * map['A'] * map['H'];
ans += map['M'] * map['R'] * map['C'];
ans += map['M'] * map['R'] * map['H'];
ans += map['M'] * map['C'] * map['H'];
ans += map['A'] * map['R'] * map['C'];
ans += map['A'] * map['R'] * map['H'];
ans += map['A'] * map['C'] * map['H'];
ans += map['R'] * map['C'] * map['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 | python3 | n = int(input())
s = []
for i in range(n):
s.append(input()[0])
def qwe(y):
m = 0
a = 0
r = 0
c = 0
h = 0
for i in y:
if i == 'M':
m += 1
elif i == 'A':
a += 1
elif i == 'R':
r += 1
elif i == 'C':
c += 1
elif i == 'H':
h += 1
else:
pass
q = [m,a,r,c,h]
return q
def qwer(arr):
count = 0
coun = 0
for j in range(len(arr)):
if arr[j] == 0:
count += 1
arr.pop(j)
else:
coun += 1
if count == 5:
return 0
if coun == 4:
asd_1 = arr[0]*arr[1]*arr[2]
asd_2 = arr[0]*arr[1]*arr[3]
asd_3 = arr[0]*arr[2]*arr[3]
asd_4 = arr[1]*arr[2]*arr[3]
return (asd_1 + asd_2 + asd_3 + asd_4)
if coun == 5:
asf_1 = arr[0]*arr[1]*arr[2]
asf_2 = arr[0]*arr[1]*arr[3]
asf_3 = arr[0]*arr[1]*arr[4]
asf_4 = arr[0]*arr[2]*arr[3]
asf_5 = arr[0]*arr[2]*arr[4]
asf_6 = arr[0]*arr[3]*arr[4]
asf_7 = arr[1]*arr[2]*arr[3]
asf_8 = arr[1]*arr[2]*arr[4]
asf_9 = arr[1]*arr[3]*arr[4]
asf_10 = arr[2]*arr[3]*arr[4]
return (asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10)
v = qwe(s)
print(qwer(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;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return abs(a * b) / gcd(a, b); }
ll n, ans = 0;
int a[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2},
b[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3},
c[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
std::vector<int> d(5, 0);
int main() {
cin >> n;
for (size_t i = 0; i < n; i++) {
string temp;
cin >> temp;
if (temp[0] == 'M') d[0]++;
if (temp[0] == 'A') d[1]++;
if (temp[0] == 'R') d[2]++;
if (temp[0] == 'C') d[3]++;
if (temp[0] == 'H') d[4]++;
}
for (size_t i = 0; i < 10; i++) {
ans += d[a[i]] * d[b[i]] * d[c[i]];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
int main(){
int n;
cin>>n;
string S[n];
map<char,ll>m;
rep(i,n){
cin>>S[i];
m[S[i][0]]++;
}
char a[5]={'M','A','R','C','H'};
ll count=0;
for(int i=0;i<3;i++){
for(int j=i+1;j<4;j++){
for(int k=j+1;k<5;k++){
count+=ll(m[a[i]]*m[a[j]]*m[a[k]]);
}
}
}
cout<<count<<endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d", &N);
int name[5] = {0};
char c[6] = "MARCH";
for (int i = 0; i < N; i++) {
char S[11];
scanf("%s", S);
for (int j = 0; j < 5; j++) {
if (S[0] == c[j]) name[j]++;
}
}
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 += name[i] * name[j] * name[k];
}
}
printf("%ld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;
class Program
{
static void Main(string[] args)
{
label:
var nums = new long[5];
int count = Parse(ReadLine());
for (int i = 0; i < count; ++i)
{
switch (ReadLine()[0])
{
case 'M': ++nums[0]; break;
case 'A': ++nums[1]; break;
case 'R': ++nums[2]; break;
case 'C': ++nums[3]; break;
case 'H': ++nums[4]; break;
}
}
long result = nums[0] * nums[1] * nums[2];
result += nums[0] * nums[1] * nums[3];
result += nums[0] * nums[1] * nums[4];
result += nums[0] * nums[2] * nums[3];
result += nums[0] * nums[2] * nums[4];
result += nums[0] * nums[3] * nums[4];
result += nums[1] * nums[2] * nums[3];
result += nums[1] * nums[2] * nums[4];
result += nums[1] * nums[3] * nums[4];
result += nums[2] * nums[3] * nums[4];
WriteLine(result);
goto label;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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) {
string buf;
int m, a, r, c, h;
int N;
long long p;
cin >> N;
m = a = r = c = h = 0;
for (int i = 0; i < N; i++) {
cin >> buf;
switch (buf[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
default:
break;
}
}
p = 0;
p = 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 << p << 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, cou[5] = {0};
long long ans = 0;
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
string s;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') {
cou[0]++;
} else if (s[0] == 'A') {
cou[1]++;
} else if (s[0] == 'R') {
cou[2]++;
} else if (s[0] == 'C') {
cou[3]++;
} else if (s[0] == 'H') {
cou[4]++;
}
}
for (int j = 0; j < 10; j++) {
ans += cou[P[j]] * cou[Q[j]] * cou[R[j]];
}
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
long long to;
long long cost;
};
int main() {
int N;
cin >> N;
long long cnt = 0;
unordered_map<char, int> mp{};
for (int i = 0; i < (int)(N); i++) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
continue;
}
mp[s[0]]++;
}
long long ans = 0;
for (auto s : mp) {
for (auto t : mp) {
for (auto u : mp) {
if (s.first == t.first || t.first == u.first || u.first == s.first)
continue;
if (s.second == 0 || t.second == 0 || u.second == 0) continue;
ans += s.second * t.second * u.second;
}
}
}
cout << ans / 6 << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
int main() {
long long n;
cin >> n;
vstr s(n);
vll a(5);
for (long long i = 0; i < (n); i++) cin >> s[i];
for (long long i = 0; i < (n); i++) {
if (s[i][0] == 'M') {
a[0]++;
} else if (s[i][0] == 'A') {
a[1]++;
} else if (s[i][0] == 'C') {
a[2]++;
} else if (s[i][0] == 'H') {
a[3]++;
} else if (s[i][0] == 'R') {
a[4]++;
}
}
long long ans = 1;
long long cu = 0;
for (long long i = 0; i < (5); i++) {
if (a[i] != 0) cu++;
}
if (cu < 3)
cout << (0) << endl;
else {
if (cu == 5) {
ans *= 5;
ans *= 3;
ans *= 4;
} else if (cu == 4) {
ans *= 4;
ans *= 3;
ans *= 2;
} else if (cu == 3) {
ans *= 3;
ans *= 2;
}
ans /= 3;
ans /= 2;
for (long long i = 0; i < (5); i++) {
if (a[i] != 0) {
ans *= a[i];
}
}
}
cout << (ans) << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, i, j = 0;
char S[100000][10];
cin >> N;
for (i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' || S[i][0] == 'C' ||
S[i][0] == 'H')
j++;
}
cout << j * (j - 1) * (j - 2) / 6 << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<string, int> names;
string init = "MARCH";
for (size_t i = 0; i < 5; i++) {
names[init.substr(i, 1)] = 0;
}
for (size_t i = 0; i < N; i++) {
string s;
cin >> s;
if (init.find(s.substr(0, 1)) != string::npos) {
names[s.substr(0, 1)]++;
}
}
long long ret = 0;
ret += names["M"] * names["A"] * names["R"];
ret += names["M"] * names["A"] * names["C"];
ret += names["M"] * names["A"] * names["H"];
ret += names["M"] * names["R"] * names["C"];
ret += names["M"] * names["R"] * names["H"];
ret += names["M"] * names["C"] * names["H"];
ret += names["A"] * names["R"] * names["C"];
ret += names["A"] * names["R"] * names["H"];
ret += names["A"] * names["C"] * names["H"];
ret += names["R"] * names["C"] * names["H"];
cout << ret << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import scala.io.StdIn
object Main extends App {
val n = StdIn.readLine().toInt
val linse = (0 until n).map(_ => StdIn.readLine())
val combis = "MARCH".split("").combinations(3).map(p => p.toList)
val members = linse.filter{p =>
p.charAt(0) == 'M' || p.charAt(0) == 'A' || p.charAt(0) == 'R' || p.charAt(0) == 'C' || p.charAt(0) == 'H'
}.groupBy(name => name.charAt(0))
//val combi = members.keys.toList.combinations(3)
//println(combi.mkString(" "))
val result = combis.foldLeft(0L){ (acc, l) =>
val List(a1, a2, a3) = l.map(p => p.charAt(0))
acc + members.getOrElse(a1, List()).size * members.getOrElse(a2, List()).size * members.getOrElse(a3,List()).size
}
println(result)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
unsigned long long res = 0;
vector<int> v = {0, 0, 0, 0, 0};
string tmp;
for (int(i) = 0; (i) < (n); (i)++) {
cin >> tmp;
char f = tmp.at(0);
if (f == 'M')
v[0]++;
else if (f == 'A')
v[1]++;
else if (f == 'R')
v[2]++;
else if (f == 'C')
v[3]++;
else if (f == 'H')
v[4]++;
}
for (int(i) = 0; (i) < (5); (i)++) {
for (int(j) = 0; (j) < (5); (j)++) {
if (i >= j) continue;
for (int(k) = 0; (k) < (5); (k)++) {
if (j >= k) continue;
res += v[i] * v[j] * v[k];
}
}
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vc(5);
string s;
string march = "MARCH";
for (int i = 0; i < (n); i++) {
cin >> s;
for (int j = 0; j < (march.size()); j++) {
if (s[0] == march[j]) {
vc[j]++;
break;
}
}
}
long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += vc[i] * vc[j] * vc[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
int N;
scanf("%d",&N);
char s[N][11];
int i,j,k
long long c[5]={0,0,0,0,0};
for(i=0;i<N;i++){
scanf("%s",s[i]);
if(s[i][0]=='M'){
c[0]++;
}else if(s[i][0]=='A'){
c[1]++;
}else if(s[i][0]=='R'){
c[2]++;
}else if(s[i][0]=='C'){
c[3]++;
}else if(s[i][0]=='H'){
c[4]++;
}
}
long long ans = 0;
for(i=0;i<3;i++){
for(j=i+1;j<4;j++){
for(k=j+1;k<5;k++){
ans += c[i]*c[j]*c[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 | UNKNOWN | import scala.io.{StdIn => in}
object Main extends App {
val n = in.readInt
val tar ="MARCH".toCharArray
val table = Array.ofDim[Int](tar.size)
Iterator.continually(in.readLine)
.take(n)
.foreach(s => {
val idx = tar.indexWhere(_ == s.head)
if(idx != -1) table(idx) += 1
})
// debug(table.mkString(" "))
val ans = {
var res = 0L
for {
i <- tar.indices
j <- i+1 until tar.size
k <- j+1 until tar.size
} res += table(i) * table(j) * table(k)
res
}
println(ans)
def debug(any:Any*):Unit = {
if(this.getClass.toString == "class Main$") return
println(any.mkString(" "))
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, b[10] = {0}, t = 0, t0;
char a[1000];
cin >> n;
while (n--) {
cin >> a;
if (a[0] == 'M') b[0]++;
if (a[0] == 'A') b[1]++;
if (a[0] == 'R') b[2]++;
if (a[0] == 'C') b[3]++;
if (a[0] == 'H') b[4]++;
}
t = b[0] * b[1] * b[2] + b[0] * b[2] * b[3] + b[0] * b[3] * b[4] +
b[0] * b[1] * b[3] + b[0] * b[1] * b[4] + b[0] * b[2] * b[4] +
b[1] * b[2] * b[3] + b[1] * b[2] * b[4] + b[1] * b[1] * b[3] * b[4] +
b[2] * b[3] * b[4];
cout << t << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0) g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll mod = MOD) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll mod = MOD) {
return (a - b + mod) % mod;
}
ll MUL(const ll &a, const ll &b, const ll mod = MOD) {
return (1LL * a * b) % mod;
}
ll DIV(const ll &a, const ll &b, const ll mod = MOD) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
map<char, int> h;
for (int i = (int)(0); i < (int)(n); ++i) {
string in;
cin >> in;
h[in[0]]++;
}
string T = "MARCH";
int m = T.size();
int res = 0;
for (int i = (int)(0); i < (int)(m); ++i) {
char e1 = T[i];
for (int j = (int)(i + 1); j < (int)(m); ++j) {
char e2 = T[j];
for (int k = (int)(j + 1); k < (int)(m); ++k) {
char e3 = T[k];
res += h[e1] * h[e2] * h[e3];
}
}
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int name[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
name[0]++;
} else if (s[0] == 'A') {
name[1]++;
} else if (s[0] == 'R') {
name[2]++;
} else if (s[0] == 'C') {
name[3]++;
} else if (s[0] == 'H') {
name[4]++;
}
}
long long 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 = ans + name[i] * name[j] * name[k];
}
}
}
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, count1 = 0, ans = 1;
string s;
cin >> n;
map<char, int> mp;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
for (int i = 0; i < n; i++) {
cin >> s;
mp[s.at(0)]++;
}
cout << mp['M'] * mp['C'] * mp['H'] + mp['A'] * mp['C'] * mp['H'] +
mp['M'] * mp['R'] * mp['H'] + mp['M'] * mp['R'] * mp['C'] +
mp['M'] * mp['A'] * mp['R'] + mp['M'] * mp['A'] * mp['C'] +
mp['M'] * mp['A'] * mp['H'] + mp['A'] * mp['R'] * mp['C'] +
mp['A'] * mp['R'] * mp['H'] + mp['R'] * mp['C'] * mp['H']
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <stdio.h>
using namespace std;
char s[1000];
int main()
{
int m,a,r,c,h,i,n,sum=0;
scanf("%d",&n);
for(i=1; i<=n; 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++;
}
sum=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+r*c*h+a*r*h;
printf("%d",sum);
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
void chmin(int &a, int b) {
if (a > b) a = b;
}
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S[i];
map<char, long long> ma;
char list[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) ma[list[i]] = 0;
for (int i = 0; i < N; i++) ma[S[i].front()]++;
long long res = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
res += ma[list[i]] + ma[list[j]] + ma[list[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() {
string s = "MARCH";
int c[5] = {0, 0, 0, 0, 0};
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < s.size(); j++) {
if (t[0] == s[j]) {
c[j]++;
}
}
}
long ans = 0L;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
while (n--) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
unsigned long long answer = 0;
answer += m * a * r;
answer += m * a * c;
answer += m * a * h;
answer += m * r * c;
answer += m * r * h;
answer += m * c * h;
answer += a * r * c;
answer += a * r * h;
answer += r * c * h;
cout << 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 | java | import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public Main () {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
LinkedList<Character> list = new LinkedList<Character>();
int m, a, r, c, h;
long ans = 0;
m = 0; a = 0; r = 0; c = 0; h = 0;
for (int i = 0; i < n; i++) {
list.add(i, sc.next().charAt(0));
}
for (int i = 0; i < n; i++) {
if (!march(list.get(i))) {
list.remove(i);
n--;
}
}
for (int i = 0; i < n; i++) {
char s = list.get(i);
switch (s) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
}
}
ans += m*a*r;
ans += m*a*c;
ans += m*a*h;
ans += m*r*c;
ans += m*r*h;
ans += m*c*h;
ans += a*r*c;
ans += a*r*h;
ans += a*c*h;
ans += r*c*h;
System.out.println(ans);
}
boolean march(char s) {
return s == 'M' || s == 'A'|| s == 'R' || s == 'C' || s == 'H';
}
public static void main (String[] args) {
new 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;
void cinv(vector<long long> &V) {
long long t;
cin >> t;
V.push_back(t);
}
int main() {
long long N, M = 0, A = 0, R = 0, C = 0, H = 0, ANS = 0;
vector<long long> S;
cin >> N;
for (long long i = 0; i < N; i++) {
string s;
cin >> s;
cout << s[0] << endl;
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++;
}
if (M != 0) S.push_back(M);
if (A != 0) S.push_back(A);
if (R != 0) S.push_back(R);
if (C != 0) S.push_back(C);
if (H != 0) S.push_back(H);
if (S.size() <= 2) {
cout << "0" << endl;
} else {
if (S.size() == 3) {
cout << S[0] * S[1] * S[2] << endl;
} else if (S.size() == 4) {
ANS = ANS + S[0] * S[1] * S[2];
ANS = ANS + S[0] * S[1] * S[3];
ANS = ANS + S[0] * S[2] * S[3];
ANS = ANS + S[1] * S[2] * S[3];
cout << ANS << endl;
} else {
ANS = ANS + S[0] * S[1] * S[2];
ANS = ANS + S[0] * S[1] * S[3];
ANS = ANS + S[0] * S[1] * S[4];
ANS = ANS + S[0] * S[2] * S[3];
ANS = ANS + S[0] * S[2] * S[4];
ANS = ANS + S[0] * S[3] * S[4];
ANS = ANS + S[1] * S[2] * S[3];
ANS = ANS + S[1] * S[2] * S[4];
ANS = ANS + S[1] * S[3] * S[4];
ANS = ANS + S[2] * S[3] * S[4];
cout << ANS << endl;
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, c[5], ans = 0;
cin >> n;
string s[100000];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') 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]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main() {
int n;
char name[11];
int avoid = scanf("%d", &n);
int i;
int count[5] = {};
int sum = 0;
for (i = 0; i < n; i++) {
avoid = scanf("%s", name);
switch (name[0]) {
case 'M':
count[0]++;
if (count[0] == 1) sum++;
break;
case 'A':
count[1]++;
if (count[1] == 1) sum++;
break;
case 'R':
count[2]++;
if (count[2] == 1) sum++;
break;
case 'C':
count[3]++;
if (count[3] == 1) sum++;
break;
case 'H':
count[4]++;
if (count[4] == 1) sum++;
}
}
int ans;
ans = count[0] * count[1] * count[2] + count[0] * count[1] * count[3] +
count[0] * count[1] * count[4] + count[0] * count[2] * count[3] +
count[0] * count[2] * count[4] + count[0] * count[3] * count[4] +
count[1] * count[2] * count[3] + count[1] * count[2] * count[4] +
count[1] * count[3] * count[4] + count[2] * count[3] * count[4];
printf("%d", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #icnlude <bits/stdc++.h>
using namespace std;
int main() {
int m,a,r,c,h,n;
cin >> n;
m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
vector<string> name(n);
for(int i=0;i<n;i++){
cin >> name.at(i);
if(nema.at(i).at(0) == 'M'){
m++;
}
else if(name.at(i).at(0) == 'A'){
a++;
}
else if(name.at(i).at(0) == 'R'){
r++;
}
else if(name.at(i).at(0) == 'C'){
c++;
}
else if(name.at(i).at(0) == 'H'){
h++;
}
}
long x;
x = 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 << x << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) {
return gcd(b, a);
} else if (a % b) {
return gcd(b, a % b);
} else {
return b;
}
}
int main() {
long long N;
cin >> N;
vector<string> S(N);
long long m = 0;
long long a = 0;
long long r = 0;
long long c = 0;
long long h = 0;
for (int i = 0; i < N; ++i) {
cin >> S[i];
if (S[i].at(0) == 'M') {
m++;
}
if (S[i].at(0) == 'A') {
a++;
}
if (S[i].at(0) == 'R') {
r++;
}
if (S[i].at(0) == 'C') {
c++;
}
if (S[i].at(0) == 'H') {
h++;
}
}
int ans = 0;
if (m > 0 && a > 0 && r > 0) {
ans += m * a * r;
}
if (m > 0 && a > 0 && h > 0) {
ans += m * a * h;
}
if (m > 0 && a > 0 && c > 0) {
ans += m * a * c;
}
if (m > 0 && c > 0 && r > 0) {
ans += m * c * r;
}
if (m > 0 && h > 0 && r > 0) {
ans += m * h * r;
}
if (m > 0 && h > 0 && c > 0) {
ans += m * h * c;
}
if (a > 0 && r > 0 && c > 0) {
ans += c * a * r;
}
if (a > 0 && r > 0 && h > 0) {
ans += h * a * r;
}
if (a > 0 && c > 0 && h > 0) {
ans += h * a * c;
}
if (r > 0 && c > 0 && h > 0) {
ans += h * c * r;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long ans = 0;
vector<int> memo(5), p = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2},
q = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3},
r = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M')
memo[0]++;
else if (s[i][0] == 'A')
memo[1]++;
else if (s[i][0] == 'R')
memo[2]++;
else if (s[i][0] == 'C')
memo[3]++;
else if (s[i][0] == 'H')
memo[4]++;
}
for (int i = 0; i < 10; i++) ans += memo[p[i]] * memo[q[i]] * memo[r[i]];
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
s=input()
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+=1
x=[m,a,r,c,h]
cnt=x.count(0)
for i in range(cnt):
x.remove(0)
l=len(x)
if l<3:
print(0)
elif l==3:
print(x[0]*x[1]*x[2])
elif l==4:
a,b,c,d=x[0],x[1],x[2],x[3]
print(a*b*c+a*b*d+a*c*d+b*c*d)
else:
a,b,c,d,e=x[0],x[1],x[2],x[3],x[4]
print(5)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
long long N;
cin >> N;
string S;
map<char, long long> mp;
for (long long i = 0; i < N; i++) {
cin >> S;
mp[S[0]]++;
}
string march[5] = {"M", "A", "R", "C", "H"};
string tmp;
vector<string> v;
set<string> st;
do {
for (long long i = 0; i < 3; i++) {
tmp += march[i];
}
sort(tmp.begin(), tmp.end());
st.insert(tmp);
tmp = "";
} while (next_permutation(march, march + 5));
for (auto it = st.begin(); it != st.end(); it++) {
v.push_back(*it);
}
unsigned long long ans = 0;
for (long long i = 0; i < v.size(); i++) {
ans += (mp[v[i][0]] * mp[v[i][1]] * mp[v[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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
int mp[5] = {0};
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') mp[0]++;
if (s[0] == 'A') mp[1]++;
if (s[0] == 'R') mp[2]++;
if (s[0] == 'C') mp[3]++;
if (s[0] == 'H') mp[4]++;
}
long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += mp[i] * mp[j] * mp[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 | using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
public static void Main() {
// 終了後回答
int N = int.Parse(Console.ReadLine());
string[] names = new string[N];
for (int i = 0; i < N; i++) {
names[i] = Console.ReadLine();
}
int[] MARCH = new[]{ 'M', 'A', 'R', 'C', 'H' }.Select(c => names.Count(s => s[0] == c)).ToArray();
long res = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i==j) continue;
for (int k = 0; k < 5; k++) {
if (i == k || i == j) continue;
res += MARCH[i]*MARCH[j]*MARCH[k];
}
}
}
Console.WriteLine(res);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
using namespace std;
typedef long long ll;
string s;
int N;
ll m,a,r,c,h;
ll D[5];
int P[10]={0,0,0,0,0,0,1,1,1,2};
int Q[10]={1,1,1,2,2,3,2,2,3,3};
int R[10]={2,3,4,3,4,4,3,4,4,4};
int main () {
cin >> N;
for(int i=0;i<N;i++) {
cin>>s;
if(s[0]==’M’)m++;
if(s[0]==’A’)a++;
if(s[0]==’R’)r++;
if(s[0]==’C’)c++;
if(s[0]==’H’)h++;
}
D[0]=m, D[1]=a, D[2]=r,D[3]=c,D[4]=h;
ll res =0;
for(int d=0;d<10;d++) res+=D[P[d]]*D[Q[d]]*D[R[d]];
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001000;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
int main() {
int N;
cin >> N;
char comb[5] = {'M', 'A', 'R', 'C', 'H'};
vector<int> name(30, 0);
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
name[s[0] - 'A']++;
}
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 += name[comb[i] - 'A'] * name[comb[j] - 'A'] * name[comb[k] - 'A'];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
string s[n];
int march[20];
for (int i = 0; i < 20; i++) {
march[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M')
march[0]++;
else if (s[i][0] == 'A')
march[1]++;
else if (s[i][0] == 'R')
march[2]++;
else if (s[i][0] == 'C')
march[3]++;
else if (s[i][0] == 'H')
march[4]++;
}
ll ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[10] = {};
char str[5] = {'M', 'A', 'R', 'C', 'H'};
while (n--) {
string s;
cin >> s;
for (int i = 0; i < 5; i++) {
if (s[0] == str[i]) a[i]++;
}
}
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++) {
if (a[i] * a[j] * a[k] > 0) ans += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | num = gets.to_i
initial = {"M": 0,"A": 0,"R": 0,"C": 0,"H": 0}
while num > 0 do
num -= 1
n = gets.to_s[0]
if n == "M"||"A"||"R"||"C"||"H"
initial[n.to_sym] += 1
end
end
count = 0
"MARCH".split("").combination(3).map do |a,b,c|
puts "#{a},#{b},#{c}"
count = count + (initial[a.to_sym] * initial[b.to_sym] * initial[c.to_sym])
puts count
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;
int main() {
int N;
cin >> N;
string S;
string march = "MARCH";
int count = 0;
vector<int> data(5, 0);
for (int i = 0; i < N; i++) {
count = 0;
cin >> S;
for (char a : march) {
if (S.at(0) == a) data.at(0 + count)++;
count++;
}
}
long ans = data.at(2) * data.at(3) * data.at(4) +
data.at(1) * data.at(3) * data.at(4) +
data.at(1) * data.at(2) * data.at(4) +
data.at(1) * data.at(2) * data.at(3) +
data.at(0) * data.at(3) * data.at(4) +
data.at(0) * data.at(2) * data.at(4) +
data.at(0) * data.at(2) * data.at(3) +
data.at(0) * data.at(1) * data.at(4) +
data.at(0) * data.at(1) * data.at(3) +
data.at(0) * data.at(1) * data.at(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 | UNKNOWN | #include <bits/stdc++.h>
int main() {
int N;
int i;
scanf("%d", &N);
char name[N + 1][100];
for (i = 1; i <= N; i++) scanf("%s", &name[i][0]);
int countM = 0, countA = 0, countR = 0, countC = 0, countH = 0;
for (i = 1; i <= N; i++) {
if (name[i][0] == 'M') countM += 1;
if (name[i][0] == 'A') countA += 1;
if (name[i][0] == 'R') countR += 1;
if (name[i][0] == 'C') countC += 1;
if (name[i][0] == 'H') countH += 1;
}
long result;
result += (long)(countM * countA * (countR + countC + countH));
result += (long)(countM * countR * (countC + countH));
result += (long)(countM * countC * countH);
result += (long)(countA * countR * (countC + countH));
result += (long)(countA * countC * countH);
result += (long)(countR * countC * countH);
printf("%ld", result);
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 (
"bufio"
"fmt"
"os"
"strconv"
)
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)
n := nextInt()
m := map[string]int{}
for i := 0; i < n; i++ {
m[string(nextLine()[0])]++
}
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[string(march[i])] * m[string(march[j])] * m[string(march[k])]
}
}
}
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> s(N);
for (int i = 0; i < N; i++) cin >> s.at(i);
vector<char> x;
x = {'M', 'A', 'R', 'C', 'H'};
vector<int> t;
t = {0, 0, 0, 0, 0};
for (int i = 0; i < 5; i++) {
for (int j = 0; j < N; j++) {
if (s.at(j).at(0) == x.at(i)) t.at(i)++;
}
}
long ans = 0;
for (int j = 1; j < 4; j++) {
for (int i = 0; i < j; i++) {
for (int k = j + 1; k < 5; k++) {
ans += t.at(i) * t.at(j) * t.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;
using ll = long long;
int main() {
int n;
cin >> n;
int march[20];
for (int i = 0; i < 20; i++) {
march[i] = 0;
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
march[0]++;
else if (s[0] == 'A')
march[1]++;
else if (s[0] == 'R')
march[2]++;
else if (s[0] == 'C')
march[3]++;
else if (s[0] == 'H')
march[4]++;
}
ll ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
long long int m, a, r, c, h;
for (int i = 0; i < n; i++) {
if (s[i].at(0) == 'M') {
m++;
} else if (s[i].at(0) == 'A') {
a++;
} else if (s[i].at(0) == 'R') {
r++;
} else if (s[i].at(0) == 'C') {
c++;
} else if (s[i].at(0) == 'H') {
h++;
}
}
long long int ans;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char init[n];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
init[i] = s[0];
}
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (int i = 0; i < n; i++) {
if (init[i] == 'M') {
m++;
} else if (init[i] == 'A') {
a++;
} else if (init[i] == 'R') {
r++;
} else if (init[i] == 'C') {
c++;
} else if (init[i] == 'H') {
h++;
}
}
long long int ans = 0;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
multiset<char> S;
for (int i = 0; i < (int)(N); i++) {
string tmp;
cin >> tmp;
S.insert(tmp[0]);
}
size_t m_count = S.count('M');
size_t a_count = S.count('A');
size_t r_count = S.count('R');
size_t c_count = S.count('C');
size_t h_count = S.count('H');
vector<long long> tmp;
if (m_count != 0) tmp.push_back(m_count);
if (a_count != 0) tmp.push_back(a_count);
if (r_count != 0) tmp.push_back(r_count);
if (c_count != 0) tmp.push_back(c_count);
if (h_count != 0) tmp.push_back(h_count);
if (tmp.size() < 3)
cout << 0 << endl;
else if (tmp.size() == 3) {
long long ans = 1;
for (int i = 0; i < (int)(tmp.size()); i++) ans *= tmp[i];
cout << ans << endl;
} else if (tmp.size() == 4) {
long long ans = 0;
ans += tmp[0] * (tmp[1] * tmp[2] + tmp[1] * tmp[3] + tmp[2] * tmp[3]);
ans += tmp[1] * tmp[2] * tmp[3];
cout << ans << endl;
} else {
long long ans = 0;
ans +=
tmp[0] * tmp[1] * (tmp[2] * tmp[3] + tmp[2] * tmp[4] + tmp[3] * tmp[4]);
ans +=
tmp[0] * tmp[2] * (tmp[1] * tmp[3] + tmp[1] * tmp[4] + tmp[3] * tmp[4]);
ans +=
tmp[0] * tmp[3] * (tmp[2] * tmp[1] + tmp[2] * tmp[4] + tmp[1] * tmp[4]);
ans +=
tmp[0] * tmp[4] * (tmp[2] * tmp[3] + tmp[2] * tmp[1] + tmp[3] * tmp[1]);
ans += tmp[1] * (tmp[2] * tmp[3] + tmp[2] * tmp[4] + tmp[3] * tmp[4]);
ans += tmp[2] * tmp[3] * tmp[4];
cout << ans << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string s = "MARCH";
int c[5] = {};
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < 5; j++) {
if (s[j] == t[0]) c[j]++;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += 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>
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
map<char, int> dic;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
dic[s[0]]++;
}
string march = "MARCH";
ll ans = 0;
for (int i = 0; i < (n); i++) {
for (int j = (i + 1); j < (n); j++) {
for (int k = (j + 1); k < (n); k++) {
ans += dic[march[i]] * dic[march[j]] * dic[march[k]];
}
}
}
cout << ans << endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.