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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArCorder
{
class Program
{
class inner : IEquatable<inner>
{
string m_First;
string m_Second;
string m_Therd;
public inner (string first, string second, string therd)
{
m_First = first;
m_Second = second;
m_Therd = therd;
}
public Boolean IsTarget()
{
if (m_First.First() != m_Second.First() && m_First.First() != m_Therd.First() && m_Second.First() != m_Therd.First())
{
return true;
}
else
{
return false;
}
}
public bool Equals(inner obj)
{
return obj.GetHashCode() == this.GetHashCode();
}
public override int GetHashCode()
{
return this.m_First.GetHashCode() ^ this.m_Second.GetHashCode() ^ this.m_Therd.GetHashCode();
}
}
static void Main()
{
int max = int.Parse(Console.ReadLine());
List<string> names = new List<string>();
for (int i = 0; i < max; i++)
{
names.Add(Console.ReadLine());
}
IEnumerable<string> targetNames = names.Where(x => x.StartsWith("M") ||
x.StartsWith("A") ||
x.StartsWith("R") ||
x.StartsWith("C") ||
x.StartsWith("H"));
List<inner> allPatern = new List<inner>();
foreach (string first in targetNames){
foreach(string second in targetNames)
{
foreach (string therd in targetNames)
{
allPatern.Add(new inner(first, second, therd));
}
}
}
Console.WriteLine(allPatern.Where(x => x.IsTarget()).Distinct().LongCount());
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp93 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var S = new string[N];
var num_array = new int[5];
for (int i = 0; i < N; i++) {
S[i] = Console.ReadLine();
}
num_array[0] = S.Where(x => x[0] == 'M').Count();
num_array[1] = S.Where(x => x[0] == 'A').Count();
num_array[2] = S.Where(x => x[0] == 'R').Count();
num_array[3] = S.Where(x => x[0] == 'C').Count();
num_array[4] = S.Where(x => x[0] == 'H').Count();
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 += num_array[i] * num_array[j] * num_array[k];
}
}
}
Console.WriteLine(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, a[10];
long long total = 0;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') a[0]++;
if (s[0] == 'A') a[1]++;
if (s[0] == 'R') a[2]++;
if (s[0] == 'C') a[3]++;
if (s[0] == 'H') a[4]++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
total += a[i] * a[j] * a[k];
}
}
}
cout << total << 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 S[5];
for (int i = 0; i < N; i++) cin >> S[N];
int count[5];
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M') {
count[0] += 1;
} else if (S[i][0] == 'A') {
count[1] += 1;
} else if (S[i][0] == 'R') {
count[2] += 1;
} else if (S[i][0] == 'C') {
count[3] += 1;
} else if (S[i][0] == 'H') {
count[4] += 1;
}
}
long long sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += count[i] * count[j] * count[k];
}
}
}
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;
int main() {
int n;
cin >> n;
int c[26];
for (int i = 0; i < 26; i++) c[i] = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
c[s[0] - 'A']++;
}
string s[10] = {"MAR", "MAC", "MAH", "MRC", "MRH",
"MCH", "ARC", "ACH", "ARH", "RCH"};
int ans = 0;
for (int i = 0; i < 10; i++) {
int tmp = 1;
for (int j = 0; j < 3; j++) tmp *= c[s[i][j] - 'A'];
ans += tmp;
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> str(N);
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int64_t i = 0; i < N; i++) {
cin >> str.at(i);
}
for (int64_t i = 0; i < N; i++) {
if (str.at(i).at(0) == 'M') {
M++;
} else if (str.at(i).at(0) == 'A') {
A++;
} else if (str.at(i).at(0) == 'R') {
R++;
} else if (str.at(i).at(0) == 'C') {
C++;
} else if (str.at(i).at(0) == 'H') {
H++;
}
}
cout << M * A * R + M * A * C + M * A * H + M * R * C + M * R * H +
M * C * H + A * R * C + A * R * H + A * C * H + R * C * H
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
map<char, long long int> mp;
for (int i = 0; i < n; i++) {
string tmp;
cin >> tmp;
if (tmp[0] != 'M' && tmp[0] != 'A' && tmp[0] != 'R' && tmp[0] != 'C' &&
tmp[0] != 'H') {
} else {
mp[tmp[0] - 'A']++;
}
}
vector<long long int> arr;
for (auto itr : mp) {
arr.push_back(itr.second);
}
long long int ans = 0;
if (arr.size() < 3) {
ans = 0;
} else {
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += arr[i] * arr[j] * arr[k];
}
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int Num=sc.nextInt();
int mem[]=new int[5];
int ans=0;
for(int i=0;i<Num;i++){
String str=sc.next();
char s=str.charAt(0);
if(s=='M') mem[0]++;
else if(s=='A') mem[1]++;
else if(s=='R') mem[2]++;
else if(s=='C') mem[3]++;
else if(s=='H') mem[4]++;
}
for(int i=0;i<=2;i++){
for(int j=1;j<=3;j++){
for(int k=2;k<=4;k++){
if(i!=j && j!=k) ans+=mem[i]*mem[j]*mem[k];
}
}
}
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long N = 0;
unsigned long long M, A, R, C, H;
cin >> N;
string s;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') {
M += 1;
} else if (s[0] == 'A') {
A += 1;
} else if (s[0] == 'R') {
R += 1;
} else if (s[0] == 'C') {
C += 1;
} else if (s[0] == 'H') {
H += 1;
}
}
int 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("%d\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n, sum = 0, cnt = 1;
string s;
cin >> n;
vector<long long> v(5);
for (long long i = 0; i < n; i++) {
cin >> s;
if (s.substr(0, 1) == "M") v.at(0)++;
if (s.substr(0, 1) == "A") v.at(1)++;
if (s.substr(0, 1) == "R") v.at(2)++;
if (s.substr(0, 1) == "C") v.at(3)++;
if (s.substr(0, 1) == "H") v.at(4)++;
}
for (int i = 0; i < v.size(); i++) {
if (v.at(i) == 0) cnt++;
}
sort(v.begin(), v.end());
do {
sum += v.at(0) * v.at(1) * v.at(2);
} while (next_permutation(v.begin(), v.end()));
if (cnt == 0) {
cout << sum << endl;
} else {
cout << sum / cnt << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
long long int sum = 0;
long long int num[5], i, n, j, k, x;
char name[11];
for (i = 0; i < 5; i++) num[i] = 0;
scanf("%d", &n);
while (n > 0) {
scanf("%s", name);
if (name[0] == 'M')
num[0]++;
else if (name[0] == 'A')
num[1]++;
else if (name[0] == 'R')
num[2]++;
else if (name[0] == 'C')
num[3]++;
else if (name[0] == 'H')
num[4]++;
n--;
}
for (i = 0; i < 5; i++) {
x = 0;
if (num[i] == 0) continue;
for (j = i + 1; j < 5; j++)
for (k = j + 1; k < 5; k++) x += num[j] * num[k];
sum += x * num[i];
}
printf("%lld", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
std::cin >> n;
std::vector<string> s(n);
for (int i = 0; i < (int)(n); i++) std::cin >> s[i];
std::map<char, int> map;
for (int i = 0; i < (int)(n); i++) {
map[s[i][0]]++;
}
string march = "MARCH";
int64_t sum = 0;
for (int a = 0; a < 5; ++a) {
for (int b = a + 1; b < 5; ++b) {
for (int c = b + 1; c < 5; ++c) {
sum += map[march[a]] * map[march[b]] * map[march[c]];
}
}
}
std::cout << sum << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
int a[100010];
int main() {
int n;
cin >> n;
vector<string> s(n);
vector<long long int> name(5, 0);
for (int i = 0; i < (n); ++i) {
cin >> s[i];
if (s[i][0] == 'M') name[0]++;
if (s[i][0] == 'A') name[1]++;
if (s[i][0] == 'R') name[2]++;
if (s[i][0] == 'C') name[3]++;
if (s[i][0] == 'H') name[4]++;
}
long long int res = 0, ans;
for (int bit = 0; bit < (1 << 5); bit++) {
if (__builtin_popcount(bit) != 3) continue;
cout << "bit" << bit;
ans = 1;
for (int i = 0; i < 5; i++) {
if (bit & (1 << i)) {
ans = ans * name[i];
}
}
cout << ans << endl;
res += ans;
}
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>
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;
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
map<char, ll> mci;
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
continue;
}
mci[s[0]]++;
}
if (mci.size() < 3) {
cout << 0 << endl;
return 0;
} else if (mci.size() == 3) {
ll res = 1;
for (auto v : mci) {
res *= v.second;
}
cout << res << endl;
return 0;
}
vector<char> skip;
ll ans = 0;
for (auto v : mci) skip.push_back(v.first);
for (auto sk : skip) {
ll tmp = 1;
for (auto v : mci) {
if (v.first == sk) continue;
tmp *= v.second;
}
ans += tmp;
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d", &N);
int i, j, k;
int c[5] = {0};
for (i = 0; i < N; i++) {
char S[20];
scanf("%s", S);
if (S[0] == 'M') {
c[0]++;
} else if (S[0] == 'A') {
c[1]++;
} else if (S[0] == 'R') {
c[2]++;
} else if (S[0] == 'C') {
c[3]++;
} else if (S[0] == 'H') {
c[4]++;
}
}
long count = 0;
for (i = 0; i < 5; i++) {
for (j = i; j < 5; j++) {
for (k = j; k < 5; k++) {
if (i != j && j != k && k != i) {
count += c[i] * c[j] * c[k];
}
}
}
}
printf("%ld", 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, cnt = 0;
long long M = 0, A = 0, R = 0, C = 0, H = 0;
string tmp;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> tmp;
if (tmp[0] == 'M')
M++;
else if (tmp[0] == 'A')
A++;
else if (tmp[0] == 'R')
R++;
else if (tmp[0] == 'C')
C++;
else if (tmp[0] == 'H')
H++;
}
cnt += M * A * R;
cnt += M * A * C;
cnt += M * A * H;
cnt += M * R * C;
cnt += M * R * H;
cnt += M * C * H;
cnt += A * R * C;
cnt += A * R * H;
cnt += A * C * H;
cnt += R * C * H;
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
map<char, int> head;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
head['m'] += 1;
else if (s[0] == 'A')
head['a'] += 1;
else if (s[0] == 'R')
head['r'] += 1;
else if (s[0] == 'C')
head['c'] += 1;
else if (s[0] == 'H')
head['h'] += 1;
}
char idx[5] = {'m', 'a', 'r', 'c', 'h'};
int sele1[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2};
int sele2[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3, 3};
int sele3[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 5, 4};
int sum = 0;
for (int i = 0; i < 11; i++) {
sum += head[idx[sele1[i]]] * head[idx[sele2[i]]] * head[idx[sele3[i]]];
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long A[5] = {0, 0, 0, 0, 0};
cin >> N;
vector<string> S(N);
for (size_t i = 0; i < N; i++) {
cin >> S.at(i);
if (S.at(i).at(0) == 'M') {
A[0]++;
} else if (S.at(i).at(0) == 'A') {
A[1]++;
} else if (S.at(i).at(0) == 'R') {
A[2]++;
} else if (S.at(i).at(0) == 'C') {
A[3]++;
} else if (S.at(i).at(0) == 'H') {
A[4]++;
}
long long ans = A[0] * A[1] * A[2] * A[3] * A[4];
cout << ans;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, ans, a, r, c, h, m;
a = r = c = h = m = 0;
string b;
vector<string> vec;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b;
if (b[0] == 'A')
a++;
else if (b[0] == 'R')
r++;
else if (b[0] == 'C')
c++;
else if (b[0] == 'M')
m++;
else if (b[0] == 'H')
h++;
}
cout << a * r * c + a * r * m + a * r * h + a * c * m + a * c * h +
a * m * h + r * c * m + r * c * h + r * m * h + c * m * h
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S[i];
int B[5] = {0};
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M') {
B[0]++;
} else if (S.at(i).at(0) == 'A') {
B[1]++;
} else if (S.at(i).at(0) == 'R') {
B[2]++;
} else if (S.at(i).at(0) == 'C') {
B[3]++;
} else if (S.at(i).at(0) == 'H') {
B[4]++;
}
}
long long x = B[0] * B[1] * B[2] + B[0] * B[1] * B[3] + B[0] * B[1] * B[4] +
B[0] * B[2] * B[3] + B[0] * B[2] * B[4] + B[0] * B[3] * B[4] +
B[1] * B[2] * B[3] + B[1] * B[2] * B[4] + B[1] * B[3] * B[4] +
B[2] * B[3] * B[4];
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;
int main() {
int N;
cin >> N;
vector<string> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int j = 0; j < N; j++) {
string S = vec.at(j);
if (S.at(0) == 'M') {
M++;
}
if (S.at(0) == 'A') {
A++;
}
if (S.at(0) == 'R') {
R++;
}
if (S.at(0) == 'C') {
C++;
}
if (S.at(0) == 'H') {
H++;
}
}
vector<int> MARCH(5);
MARCH.at(0) = M;
MARCH.at(1) = A;
MARCH.at(2) = R;
MARCH.at(3) = C;
MARCH.at(4) = H;
sort(MARCH.begin(), MARCH.end());
int64_t ans = 0;
if (MARCH.at(1) == 0 && MARCH.at(2) != 0) {
ans = MARCH.at(2) * MARCH.at(3) * MARCH.at(4);
} else if (MARCH.at(0) == 0) {
ans += MARCH.at(2) * MARCH.at(3) * MARCH.at(4);
ans += MARCH.at(1) * MARCH.at(3) * MARCH.at(4);
ans += MARCH.at(1) * MARCH.at(2) * MARCH.at(4);
ans += MARCH.at(2) * MARCH.at(3) * MARCH.at(1);
} else {
ans += MARCH.at(2) * MARCH.at(3) * MARCH.at(4);
ans += MARCH.at(1) * MARCH.at(3) * MARCH.at(4);
ans += MARCH.at(1) * MARCH.at(2) * MARCH.at(4);
ans += MARCH.at(2) * MARCH.at(3) * MARCH.at(1);
ans += MARCH.at(0) * MARCH.at(1) * MARCH.at(2);
ans += MARCH.at(0) * MARCH.at(3) * MARCH.at(1);
ans += MARCH.at(0) * MARCH.at(1) * MARCH.at(4);
ans += MARCH.at(0) * MARCH.at(3) * MARCH.at(2);
ans += MARCH.at(0) * MARCH.at(2) * MARCH.at(4);
ans += MARCH.at(0) * MARCH.at(3) * MARCH.at(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 | UNKNOWN | n = 0
s = []
N = gets.to_i
N.times do
si = gets.chomp
s << si[0] if si[0] =~ /M|A|R|C|H/
end
c = s.combination(3).to_a.map(&:uniq)
c.each do |x|
if x.length == 3
n += 1
end
end
p n
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s[N];
for (int i = 0; i < N; i++) {
cin >> s[i];
}
vector<int> nums(26);
fill(nums.begin(), nums.end(), 0);
for (int i = 0; i < N; i++) {
nums[s[i][0] - 'A']++;
}
vector<int> fi(5);
fi[0] = nums[0];
fi[1] = nums[2];
fi[2] = nums[7];
fi[3] = nums[12];
fi[4] = nums[17];
sort(fi.begin(), fi.end());
long long ans = fi[0] * fi[1] * fi[2] + fi[0] * fi[1] * fi[3] +
fi[0] * fi[1] * fi[4] + fi[0] * fi[2] * fi[3] +
fi[0] * fi[2] * fi[4] + fi[0] * fi[3] * fi[4] +
fi[1] * fi[2] * fi[3] + fi[1] * fi[2] * fi[4] +
fi[1] * fi[3] * fi[4] + fi[2] * fi[3] * fi[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author palayutm
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
String target = "MARCH";
int[] a = new int[5];
int n = in.nextInt();
for (int i = 0; i < n; i++) {
String s = in.next();
char c = s.charAt(0);
if (target.indexOf(c) >= 0) {
a[target.indexOf(c)]++;
}
}
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];
}
}
}
out.println(ans);
}
}
static class OutputWriter extends PrintWriter {
public OutputWriter(OutputStream out) {
super(out);
}
public OutputWriter(Writer out) {
super(out);
}
public void close() {
super.close();
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S;
for (int i = 0; i < N; i++) {
string tmps;
cin >> tmps;
if (tmps[0] == 'M' || tmps[0] == 'A' || tmps[0] == 'R' || tmps[0] == 'C' ||
tmps[0] == 'H') {
S.push_back(tmps);
}
}
if (S.size() == 0) {
cout << 0 << endl;
return 0;
}
sort(S.begin(), S.end());
vector<string> distincted;
int cnt1 = 1;
int cnt2 = 1;
for (int i = 1; i < S.size(); i++) {
if (S[i - 1] != S[i]) {
cnt1++;
}
if (S[i - 1][0] != S[i][0]) {
cnt2++;
}
}
if (cnt2 < 3) {
cout << 0 << endl;
return 0;
}
int a = 1;
for (int i = 0; i < 3; i++) {
a *= cnt2 - i;
}
int x = a / (cnt2 - 3);
x = x / 6;
int y = cnt1 - cnt2;
long long ans = x + y * 3;
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() {
long long n;
cin >> n;
long long m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
long long ans = 0;
int d[5];
d[0] = m;
d[1] = a;
d[2] = r;
d[3] = c;
d[4] = h;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += d[i] * d[j] * d[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, c, d, e, f = 0, ans = 0, n, m;
int b;
int M = 0, A = 0, R = 0, C = 0, H = 0;
int num[100000];
unsigned long long x, y;
string s;
cin >> n;
b = 0;
for (a = 0; a < n; a++) {
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++;
}
}
a = 0;
a += M * A * R;
a += M * A * C;
a += M * A * H;
a += M * R * C;
a += M * R * H;
a += M * C * H;
a += A * R * C;
a += A * R * H;
a += A * C * H;
a += R * C * H;
cout << a << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M[5] = {0};
cin >> N;
string S[N];
for (int i = 0; i < N; i++) {
cin >> S[i];
char s = S[i][0];
if (s == 'M')
M[0]++;
else if (s == 'A')
M[1]++;
else if (s == 'R')
M[2]++;
else if (s == 'C')
M[3]++;
else if (s == 'H')
M[4]++;
}
long ans = 0;
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) ans += M[i] * M[j] * M[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 s;
int a[5] = {};
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]++;
}
}
int Answer = 0;
Answer += a[0] * a[1] * a[2];
Answer += a[1] * a[2] * a[3];
Answer += a[2] * a[3] * a[4];
Answer += a[3] * a[4] * a[0];
Answer += a[4] * a[0] * a[1];
Answer += a[0] * a[2] * a[4];
Answer += a[0] * a[2] * a[3];
Answer += a[0] * a[1] * a[3];
Answer += a[1] * a[3] * a[4];
Answer += a[1] * a[2] * a[4];
cout << Answer << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
int n;
string s[maxx];
long long ans;
int dd[7];
void cnt(string t) {
if (t[0] == 'M')
dd[1]++;
else if (t[0] == 'A')
dd[2]++;
else if (t[0] == 'R')
dd[3]++;
else if (t[0] == 'C')
dd[4]++;
else if (t[0] == 'H')
dd[5]++;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
cnt(s[i]);
}
int m = 0;
for (int i = 1; i <= n; i++) m += dd[i];
if (m < 3)
ans = 0;
else if (m == 3) {
bool flg = 1;
for (int i = 1; i <= 5; i++) {
if (dd[i] > 1) {
flg = 0;
break;
}
}
if (flg)
ans = 1;
else
ans = 0;
} else {
for (int i = 1; i <= 5; i++)
for (int j = i + 1; j <= 5; j++)
for (int k = j + 1; k <= 5; k++)
ans += (long long)dd[i] * (long long)dd[j] * (long long)dd[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 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 * +a * r * c + r * c * h + c * h * m + h * m * r << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
int n;
int c[5] = {0, 0, 0, 0, 0};
long long ans = 0;
int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
cin >> n;
string s;
for (int i = 0; i < n; i++) {
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]++;
}
for (int i = 0; i < 10; i++) ans += c[x[i]] * c[y[i]] * c[z[i]];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int ans = 0;
int main() {
int n, f[10], i, g;
char a[15];
memset(f, 0, sizeof(f));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", a);
if (a[0] == 'A') f[1] += 1;
if (a[0] == 'M') f[2] += 1;
if (a[0] == 'R') f[3] += 1;
if (a[0] == 'H') f[4] += 1;
if (a[0] == 'C') f[0] += 1;
}
for (i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += f[i] * f[j] * f[k];
}
}
}
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char a[100000 + 5][15], v[100000 + 5][15];
int n, k, num;
int main() {
int i, j, l;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i][0] == 'M' || a[i][0] == 'A' || a[i][0] == 'R' || a[i][0] == 'C' ||
a[i][0] == 'H') {
strcpy(v[k], a[i]);
k++;
}
}
for (i = 0; i < k; i++)
for (j = i + 1; j < k; j++)
for (l = j + 1; l < k; l++)
if (v[i][0] != v[j][0] && v[j][0] != v[l][0] && v[l][0] != v[i][0])
num++;
cout << num;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | #include <bits/stdc++.h>
using namespace std;
double euclid_distance(double a, double b) { return sqrt(a * a + b * b); }
int gcd(long long int a, long long int b) {
long long int r;
if (a < b) {
int tmp;
tmp = a;
a = b;
b = tmp;
}
while (r != 0) {
r = a % b;
a = b;
b = r;
}
return r;
}
void Integer_factorization(long long factor[], long long n) {
long long a = 2;
bool flag = false;
for (int p = 2; p * p <= n; p++) {
while (n % p == 0) {
n /= p;
factor[p]++;
}
}
if (n != 1) factor[n]++;
}
void ys() { cout << "Yes" << endl; }
void yb() { cout << "YES" << endl; }
void ns() { cout << "No" << endl; }
void nb() { cout << "NO" << endl; }
void solve(void) {
long long n;
cin >> n;
long long d[5] = {0};
int a[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int b[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int c[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int(i) = (0); (i) < (n); (i)++) {
string s;
cin >> s;
if (s[0] == 'M') d[0]++;
if (s[0] == 'A') d[1]++;
if (s[0] == 'R') d[2]++;
if (s[0] == 'C') d[3]++;
if (s[0] == 'H') d[4]++;
}
long long ans = 0;
for (int(i) = (0); (i) < (10); (i)++) {
ans += d[a[i]] * d[b[i]] * d[c[i]];
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
int main(){
int N;
scanf("%d", &N);
//std::vector<std::string > vec(N);
std::map<std::string, int > mp;
std::string S;
for (int i=0; i<N; i++){
std::cin >> S;
mp[S]++;
}
std::vector<int > count(5, 0);
// 0:M, 1:A, 2:R, 3:C, 4:H
char moji[5] = {'M', 'A', 'R', 'C', 'H'};
for (auto &entry : mp){
//printf("%c\n", entry.first[0]);
for (int j=0; j<5; j++){
if (entry.first[0]==moji[j]){
count[j] += entry.second;
}
}
}
/*for (int i=0; i<5; i++){
printf("count[%d]=%d\n",i,count[i]);
}*/
long long ans = 0;
for (int i=0; i<5; i++){
for (int j=i+1; j<5; j++){
for (i |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
let mut next = || { iter.next().unwrap() };
input_inner!{next, $($r)*}
};
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes
.by_ref()
.map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr, ) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, ( $($t:tt),* )) => {
( $(read_value!($next, $t)),* )
};
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, usize1) => {
read_value!($next, usize) - 1
};
($next:expr, $t:ty) => {
$next().parse::<$t>().expect("Parse error")
};
}
use std::cmp::max;
use std::collections::HashMap;
fn main(){
input!{
n:usize,
sn:[chars;n],
}
let master = vec!['M','A','R','C','H'];
let mut map = HashMap::new();
for s in sn {
*map.entry(s[0]).or_insert(0) += 1;
}
let mut ans = 0;
for bit in 0usize..(1<<5) {
if bit.count_ones() != 3 {
continue;
}
let mut sub = 1;
for j in 0..5 {
if bit&(1<<j) != 0 {
sub *= map.get(&master[j]).cloned().unwrap_or(0);
}
}
ans += sub;
}
println!("{}",ans);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
n=int(input())
list1=[]
for j in range(n):
s=input()
if s[0]=='M' or s[0]=='A' or s[0]=='R' or s[0]=='C' or s[0]=='H':
list1.append(s[0])
list1.sort()
list2=list(itertools.combinations(list1, 3))
cnt=0
#for j in range(len(list2)):
# if len(list2[j])==len(set(list2[j])):
# cnt+=1
print(cnt)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string march("MARCH");
int main() {
int N;
cin >> N;
vector<string> S(N);
copy_n(istream_iterator<string>(cin), N, S.begin());
unordered_map<char, int> m;
for (auto& item : S) {
if (string::npos != march.find_first_of(item[0], 0)) {
if (m.count(item[0]))
++(m[item[0]]);
else
m[item[0]] = 1;
}
}
int64_t result = 0;
for (char c1 = 'A'; c1 <= 'X'; ++c1) {
for (char c2 = c1 + 1; c2 <= 'Y'; ++c2) {
for (char c3 = c2 + 1; c3 <= 'Z'; ++c3) {
result += m[c1] * m[c2] * m[c3];
}
}
}
cout << result << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int n, i, j;
int count[5] = {0, 0, 0, 0, 0};
int ans = 0, hal1 = 0, hal2 = 0;
scanf("%d", &n);
char s[11];
for (i = 0; i < n; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
count[0]++;
break;
case 'A':
count[1]++;
break;
case 'R':
count[2]++;
break;
case 'C':
count[3]++;
break;
case 'H':
count[4]++;
break;
}
}
hal1 = count[0] * count[1];
hal2 = count[2] * count[3];
ans = hal1 * count[2] + hal1 * count[3] + hal1 * count[4] + count[1] * hal2 +
count[1] * count[2] * count[4] + hal2 * count[4] + hal2 * count[0] +
count[3] * count[4] * count[0] + count[3] * count[4] * count[1] +
count[0] * count[2] * count[4];
printf("%d\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, cou[7] = {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]++;
cou[5]++;
} else if (s[0] == 'A') {
cou[1]++;
cou[6]++;
} 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;
int main(void) {
int N;
cin >> N;
unsigned int names[5] = {0};
string march = "MARCH";
for (int i = 0; i < (int)(N); i++) {
string str;
cin >> str;
for (int j = 0; j < (int)(5); j++) {
if (str[0] == march[j]) names[j]++;
}
}
unsigned long long comb = 0;
for (int i = 0; i < (int)(5); i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
comb += names[i] * names[j] * names[k];
}
}
}
cout << comb << 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;
int MARCH[5] = {0};
string tmp;
for (int i = 0; i < n; ++i) {
cin >> tmp;
if (tmp[0] == 'M') {
++MARCH[0];
} else if (tmp[0] == 'A') {
++MARCH[1];
} else if (tmp[0] == 'R') {
++MARCH[2];
} else if (tmp[0] == 'C') {
++MARCH[3];
} else if (tmp[0] == 'H') {
++MARCH[4];
}
}
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) {
total += MARCH[i] * MARCH[j] * MARCH[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, m = 0, a = 0, r = 0, c = 0, h = 0;
string s[100010];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
if (s[i][0] == 'M')
m++;
else if (s[i][0] == 'A')
a++;
else if (s[i][0] == 'R')
r++;
else if (s[i][0] == 'C')
c++;
else if (s[i][0] == 'H')
h++;
}
long long d = 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 << d;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long int cmp(pair<long long int, string> a,
pair<long long int, string> b) {
if (a.first != b.first)
return a.first < b.first;
else
return a.second < b.second;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % 1000000007;
inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
finv[i] = finv[i - 1] * inv[i] % 1000000007;
}
}
long long COM(long long int n, long long int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
map<char, int> cnt;
int dp[100005];
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
cnt[s[i][0]]++;
if (s[i][0] == 'M')
m++;
else if (s[i][0] == 'A')
a++;
else if (s[i][0] == 'R')
r++;
else if (s[i][0] == 'C')
c++;
else if (s[i][0] == 'H')
h++;
}
int cnn = 0;
if (m) cnn++;
if (a) cnn++;
if (r) cnn++;
if (c) cnn++;
if (h) cnn++;
int cac = 0;
if (m == 1) cac++;
if (a == 1) cac++;
if (r == 1) cac++;
if (c == 1) cac++;
if (h == 1) cac++;
COMinit();
cout << (long long int)(COM(cnn, 3)) * (1 > COM(m, 1) ? 1 : COM(m, 1)) *
(1 > COM(a, 1) ? 1 : COM(a, 1)) *
(1 > COM(r, 1) ? 1 : COM(r, 1)) *
(1 > COM(c, 1) ? 1 : COM(c, 1)) *
(1 > COM(h, 1) ? 1 : COM(h, 1)) -
COM(cac, 3) * (1 > COM(m, 1) - 1 ? 1 : COM(m, 1) - 1) *
(1 > COM(a, 1) - 1 ? 1 : COM(a, 1) - 1) *
(1 > COM(r, 1) - 1 ? 1 : COM(r, 1) - 1) *
(1 > COM(c, 1) - 1 ? 1 : COM(c, 1) - 1) *
(1 > COM(h, 1) - 1 ? 1 : COM(h, 1) - 1)
<< 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 | ips = []
ips.append(input())
while True:
try:
ips.append(input())
except (EOFError):
break
def mar(ips):
march = ["M","A","R","C","H"]
cnt = [0,0,0,0,0]
num = int(ips[0])
names = [s for s in ips[1:] if s[0] in march]
if len(names) ==0:
return 0
for n in names:
if n[0]=="M": cnt[0]+=1
elif n[0]=="A": cnt[1]+=1
elif n[0]=="R": cnt[2]+=1
elif n[0]=="C": cnt[3]+=1
elif n[0]=="H": cnt[4]+=1
m = cnt[0]*(cnt[1]*(sum(cnt[2:]))+cnt[2]*(sum(cnt[3:]))+cnt[3]*cnt[4])
a = cnt[1]*(cnt[2]*(sum(cnt[3:]))+cnt[3]*cnt[4])
r = cnt[2]*(cnt[3]*(cnt[4]))
c = cnt[3]*cnt[4]
return m+a+r+c
print(mar(ips)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 | [<EntryPoint>]
let main argv =
let N = stdin.ReadLine() |> int
let counter =
[| for _ in 1..N ->
stdin.ReadLine().[0]
|]
|> Array.countBy id
|> Array.filter (fun (c, _) -> "MARCH".Contains(c.ToString()))
let n = counter |> Array.length
if n < 3 then 0
else
let counts a b c =
List.fold (fun total i -> total * (snd counter.[i])) 1 [a; b; c]
let rec dfs a b c count =
if a >= n-2 then count
elif b = n-2 then dfs (a+1) (a+2) (a+3) (count + (counts a b c))
elif c = n-1 then dfs a (b+1) (b+2) (count + (counts a b c))
else dfs a b (c+1) (count + (counts a b c))
dfs 0 1 2 0
|> stdout.WriteLine
0 // return an integer exit code
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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);
static char S[11];
int name[5] = {0};
for (int i = 0; i < N; i++) {
scanf("%s", S[i]);
switch (S[0]) {
case 'M':
name[0]++;
break;
case 'A':
name[1]++;
break;
case 'R':
name[2]++;
break;
case 'C':
name[3]++;
break;
case 'H':
name[4]++;
break;
}
}
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};
long long int ans = 0;
for (int i = 0; i < 10; i++) {
ans += name[P[i]] * name[Q[i]] * name[R[i]];
}
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.ArrayList;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long N = scan.nextInt();
ArrayList<String> namebox = new ArrayList<String>();
int[] judge = new int[5];
for(int i= 0;i < N;i++){
String x = scan.next();
namebox.add(x);
if(x.charAt(0) == 'M'){
judge[0]++;
}else if(x.charAt(0) == 'A'){
judge[1]++;
}else if(x.charAt(0) == 'R'){
judge[2]++;
}else if(x.charAt(0) == 'C'){
judge[3]++;
}else if(x.charAt(0) == 'H'){
judge[4]++;
}
}
long ans = (judge[0]*judge[1]*judge[2]) + (judge[0]*judge[1]*judge[3]) + (judge[0]*judge[1]*judge[4]) + (judge[0]*judge[2]*judge[3])
+ (judge[0]*judge[2]*judge[4]) + (judge[0]*judge[3]*judge[4]) + (judge[1]*judge[2]*judge[3]) + (judge[1]*judge[2]*judge[4])
+ (judge[1]*judge[3]*judge[4]) + (judge[2]*judge[3]*judge[4]) ;
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline
def log(*args):
print(*args, file=sys.stderr)
def main():
n = int(input().rstrip())
s = [input()[0] for _ in range(n)]
s = [v for v in range(n)]
c = Counter(s)
ans = 0
for x, y, z in combinations('MARCH', 3):
ans += c[x] * c[y] * c[z]
print(ans)
if __name__ == '__main__':
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
dic = {}
for c in "MARCH":
dic[c] = 0
myset = set(list("MARCH"))
for _ in range(N):
c = input()[0]
if c in myset:
dic[c] += 1
res = 0
for i in range(N-2):
for j in range(i+1, N-1):
for k in range(j+1, N):
res += dic["MARCH"[i]] * dic["MARCH"[j]] * dic["MARCH"[k]]
print(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 | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (int i = 0; i < N; i++) {
String s = sc.next();
if (s.charAt(0) == 'M') m++;
if (s.charAt(0) == 'A') a++;
if (s.charAt(0) == 'R') r++;
if (s.charAt(0) == 'C') c++;
if (s.charAt(0) == 'H') h++;
}
long ans = 0;
if (m > 0) {
ans += (m * a * r) + (m * a * c) + (m * a * h) + (m * r * c) + (m * r * h) + (m * c * h);
}
if (a > 0) {
ans += (a * r * c) + (a * r * h) + (a * c * h);
}
if (r > 0) {
ans += (r * c * h);
}
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
# input
N = int(input())
S = [input()[0] for i in range(N)]
# check
cnt = 0
MARCH = ["M", "A", "R", "C", "H"]
tops = [s for s in S if s in MARCH]
for c in combinations(tops, 3):
if len(tops) == 3 and len(tops) == len(set(tops)):
cnt += 1
print(cnt)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
s = input()[0]
if s in march:
S[s] += 1
for i in range(5**2):
tmp = []
for j in range(5):
if (i >> j) & 1:
tmp.append(S[march[j]])
if len(tmp) == 3:
cnt += tmp[0] * tmp[1] * tmp[2]
print(cnt) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] S = new int[5];
for (int i = 0; i < N; i++) {
String name = sc.next();
if (name.charAt(0) == 'M') S[0]++;
if (name.charAt(0) == 'A') S[1]++;
if (name.charAt(0) == 'R') S[2]++;
if (name.charAt(0) == 'C') S[3]++;
if (name.charAt(0) == 'H') S[4]++;
}
long res = 0;
for (int i = 0; i < 5; i++) {
for (int j = i+1; j < 5; j++) {
for (int k = j+1; k < 5; k++) {
res += S[i] * S[j] * S[k];
}
}
}
System.out.println(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 | python3 | n = int(input())
s = [input()[0] for i in range(n)]
work = [0, 0, 0, 0, 0]
for el in s:
if el == "M":
work[0] += 1
elif el == "A":
work[1] += 1
elif el == "R":
work[2] += 1
elif el == "C":
work[3] += 1
elif el == "H":
work[4] += 1
temp = sum(work)
result = temp*(temp-1)*(temp-2)//6
for el in work:
result -= el*(el-1)*(temp-2)//2
print(result) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s[n];
for (int i = (0); i < (n); i++) cin >> s[i];
long long ct[5];
for (int i = (0); i < (5); i++) ct[i] = 0;
for (int i = (0); i < (n); i++) {
if (s[i][0] == 'M') {
ct[0]++;
} else if (s[i][0] == 'A') {
ct[1]++;
} else if (s[i][0] == 'R') {
ct[2]++;
} else if (s[i][0] == 'C') {
ct[3]++;
} else if (s[i][0] == 'H') {
ct[4]++;
}
}
long long ans;
for (int i = (0); i < (5); i++)
for (int j = (i + 1); j < (5); j++)
for (int h = (j + 1); h < (5); h++) ans += ct[i] * ct[j] * ct[h];
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
map<char, int> m;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
m[s[0]]++;
}
vector<int> v(5);
v[0] = m['M'];
v[1] = m['A'];
v[2] = m['R'];
v[3] = m['C'];
v[4] = m['H'];
long long ans = 0;
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++)
for (int z = j + 1; z < 5; z++) {
ans += long long(v[i] * v[j] * v[z]);
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> march(5, 0);
string s = "MARCH";
for (int i = 0; i < (int)(n); i++) {
string t;
cin >> t;
for (int i = 0; i < (int)(5); i++)
if (t[0] == s[i]) march[i]++;
}
long long ans = 0;
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += march[i] * march[j] * march[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
input! {
n: usize,
s: [Chars; n]
}
let (mut m, mut a, mut r, mut c, mut h) = (0, 0, 0, 0, 0);
for i in 0..n {
if s[i][0] == 'M' {
m += 1
}
if s[i][0] == 'A' {
a += 1
}
if s[i][0] == 'R' {
r += 1;
}
if s[i][0] == 'C' {
c += 1;
}
if s[i][0] == 'H' {
h += 1;
}
}
let d = vec![m, a, r, c, h];
let p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
let q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
let t = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
let mut ans = 0;
for i in 0..10 {
ans += d[p[i]] * d[q[i]] * d[t[i]];
}
println!("{}", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import java.util.Scanner
object Main {
def main(args: Array[String]): Unit = {
val sc = new Scanner(System.in)
val n = sc.nextInt()
val a = Array(0, 0, 0, 0, 0) // m a r c h
for(i <- 0 until n) {
val s = sc.next()
if (s.charAt(0) == 'M') {
a(0) += 1
} else if (s.charAt(0) == 'A') {
a(1) += 1
} else if (s.charAt(0) == 'R') {
a(2) += 1
} else if (s.charAt(0) == 'C') {
a(3) += 1
} else if (s.charAt(0) == 'H') {
a(4) += 1
}
}
var ans = 0
for(i <- 0 until a.length) {
for(j <- (i+1) until a.length) {
for(k <- (j+1) until a.length) {
ans += a(i)*a(j)*a(k)
}
}
}
println(ans)
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
s = []
for i in range(n):
s.append(str(input()))
for i,j in enumerate(s):
if j[0] != 'M' and j[0] != 'A' and j[0] != 'R' and j[0] != 'C' and j[0] != 'H':
s.pop(i)
import itertools
count = 0
for i in itertools.combinations(s, 3):
check = []
for j in i:
check.append(j[0])
if len(list(set(check))) == 3:
count += 1
print(count) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d", &N);
char s[10];
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int i = 0; i < N; i++) {
scanf("%s", &s[10]);
if (s[0] == 'M') {
M++;
break;
}
if (s[0] == 'A') {
A++;
break;
}
if (s[0] == 'R') {
R++;
break;
}
if (s[0] == 'C') {
C++;
break;
}
if (s[0] == 'H') {
H++;
break;
}
}
long long int num = 0;
num = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
printf("%lld", num);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char s[20];
long long num[200];
long long sum = 0;
long long jiecheng(long long x) { return x * (x - 1) * (x - 2) / 6; }
int main() {
int n;
long long k;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
getchar();
scanf("%s", s);
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
sum++;
}
num[s[0] - 'A']++;
}
if (sum < 3)
printf("0\n");
else {
k = jiecheng(sum);
for (int i = 0; i < 26; i++) {
if (num[i] > 1) {
k = k - (sum - num[i]) * ((num[i] * num[i] - 1) / 2);
}
}
if (k < 0)
printf("0\n");
else
printf("%lld\n", k);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = (0); i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
cout << (long long)(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;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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 num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
for (int i = 0; i < n; i++) {
string tmp;
cin >> tmp;
if (tmp[0] == 'M') {
num1 += 1;
} else if (tmp[0] == 'A') {
num2 += 1;
} else if (tmp[0] == 'R') {
num3 += 1;
} else if (tmp[0] == 'C') {
num4 += 1;
} else if (tmp[0] == 'H') {
num5 += 1;
}
}
vector<long long int> ans(10);
ans[0] = num1 * num2 * num3;
ans[1] = num1 * num2 * num4;
ans[2] = num1 * num2 * num5;
ans[3] = num1 * num3 * num4;
ans[4] = num1 * num3 * num5;
ans[5] = num1 * num4 * num5;
ans[6] = num2 * num3 * num4;
ans[7] = num2 * num3 * num5;
ans[8] = num2 * num4 * num5;
ans[9] = num3 * num4 * num5;
long long int sum = accumulate(ans.begin(), ans.end(), 0LL);
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
long long i, c0, c1, c2, N, m[5] = {0};
long long s;
char name[14];
const char sign[7] = "MARCH";
scanf("%lld", &N);
for (i = 0; i < N; i++) {
scanf("%s", name);
for (int j = 0; j < 5; j++)
if (name[0] == sign[j]) m[j]++;
}
s = 0;
for (c0 = 0; c0 < 5; c0++)
for (c1 = c0 + 1; c1 < 5; c1++)
for (c2 = c1 + 1; c2 < 5; c2++) s += m[c0] * m[c1] * m[c2];
printf("%d\n", s);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
char march[] = {'M', 'A', 'R', 'C', 'H'};
int array[5];
memset(array, 0, sizeof(int) * 5);
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char s[11];
scanf("%s", s);
for (int j = 0; j < 5; j++) {
if (s[0] == march[j]) {
array[j]++;
}
}
}
long long int ans = 0L;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += array[i] * array[j] * array[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 | 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;
long long TMP = 0;
for (int i = 0; i < (int)(tmp.size()); i++) {
ans *= tmp[i];
TMP += tmp[i];
}
if (ans > TMP)
cout << TMP << endl;
else
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 | python3 | import itertools
N = int(input())
S = [input() for _ in range(N)]
cnt = [0 for _ in range(5)]
for s in S:
if s[0] == "M":
cnt[0] += 1
elif s[1] == "A":
cnt[1] += 1
elif s[2] == "R":
cnt[2] += 1
elif s[3] == "C":
cnt[3] += 1
elif s[4] == "H":
cnt[4] += 1
ans = 0
for i, j, k in itertools.permutations(cnt, r=3):
ans += i * j * k
print(ans)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
int cnt[5] = {};
int sum = 0;
void recursive_comb(int *indexes, int s, int rest, function<void(int *)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
void foreach_comb(int n, int k, function<void(int *)> f) {
int indexes[k];
recursive_comb(indexes, n - 1, k, f);
}
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') {
cnt[0]++;
} else if (s[i][0] == 'A') {
cnt[1]++;
} else if (s[i][0] == 'R') {
cnt[2]++;
} else if (s[i][0] == 'C') {
cnt[3]++;
} else if (s[i][0] == 'H') {
cnt[4]++;
}
}
foreach_comb(5, 3, [](int *indexes) {
sum += cnt[indexes[0]] * cnt[indexes[1]] * cnt[indexes[2]];
});
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 | # -*- coding: utf-8 -*-
N = int(input())
lines = []
for i in range(N):
tmp = input()[0]
if tmp in ["M","A","R","C","H"]:lines.append(tmp)
def recl(persons, tmp, count):
if len(tmp) == 3 and len(list(set(tmp))) == 3:
count[0] += 1
return
for idx, person in enumerate(persons):
if len(persons) < 1:break
recl( persons[idx+1:len(persons)] , tmp + [person], count)
count = [0]
recl(lines ,[] , count)
print(count[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;
static const int INFTY = (1 << 30);
int N, M;
void func() {
cin >> N;
string tmpstr;
int array[5] = {};
for (int i = (int)(0); i < (int)(N); ++i) {
cin >> tmpstr;
if (tmpstr[0] == 'M')
++array[0];
else if (tmpstr[0] == 'A')
++array[1];
else if (tmpstr[0] == 'R')
++array[2];
else if (tmpstr[0] == 'C')
++array[3];
else if (tmpstr[0] == 'H')
++array[4];
}
ll ans = 0;
for (int i = (int)(0); i < (int)(5); ++i) {
for (int j = (int)(i + 1); j < (int)(5); ++j) {
for (int k = (int)(j + 1); k < (int)(5); ++k) {
ans += array[i] * array[j] * array[k];
}
}
}
cout << ans << endl;
}
int main() { func(); }
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, set;
char head;
int node[5] = {0, 0, 0, 0, 0};
string S;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
head = S[0];
if (head == 'M') node[0] += 1;
if (head == 'A') node[1] += 1;
if (head == 'R') node[2] += 1;
if (head == 'C') node[3] += 1;
if (head == 'H') node[4] += 1;
}
set = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
set += node[i] * node[j] * node[k];
}
}
}
cout << set << 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>
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;
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
map<char, int> mci;
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
continue;
}
mci[s[0]]++;
}
vector<ll> fac(100);
fac[0] = 1;
for (int i = 0; i < 100; i++) {
fac[i + 1] = fac[i] * (i + 1);
}
ll ans;
ll countable = mci.size();
if (countable > 3) {
ans = fac[countable] / (fac[countable - 3] * fac[3]);
} else {
cout << 0 << endl;
return 0;
}
for (auto v : mci) {
if (v.second >= 2) {
ans *= v.second;
if (countable > 3) {
ans -= fac[countable - 1] / (fac[countable - 4] * fac[3]);
}
}
}
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;
for(int i=0;i<N;i++){
string p;
cin>>p;
string name=p;
char cap=name.at(0);
if(cap=="M"){m++;}
else if(cap=="A"){a++;}
else if(cap=="R"){r++;}
else if(cap=="C"){c++;}
else if(cap=="H"){h++;}
else{continue;}
}
int sum=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<<sum<<endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int arr[6];
for (int i = 0; i < 5; i++) arr[i] = 0;
int n;
cin >> n;
string d;
map<string, bool> v;
v.clear();
while (n--) {
cin >> d;
if (v.count(d) == 0) {
v[d] = 0;
switch (d[0]) {
case 'A':
arr[0]++;
break;
case 'C':
arr[1]++;
break;
case 'H':
arr[2]++;
break;
case 'M':
arr[3]++;
break;
case 'R':
arr[4]++;
break;
}
}
}
int e = 0;
for (int i = 0; i < 5 - 2; i++)
for (int j = i + 1; j < 5 - 1; j++)
for (int k = j + 1; k < 5; k++) e += (arr[i] * arr[j] * arr[k]);
cout << e;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ans = 0;
cin >> n;
int cnt[26] = {};
char s[21];
for (int i = 0; i < n; ++i) {
cin >> s;
++cnt[s[0] - 65];
}
for (int i = 0; i < 24; ++i)
for (int j = i + 1; j < 25; ++j)
for (int k = j + 1; k < 26; ++k) ans += cnt[i] * cnt[j] * cnt[k];
cout << ans << '\n';
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int N;
scanf("%d", &N);
char si1mojime[N];
char dammy;
scanf("%c", &dammy);
int i;
char buff[100];
for (i = 0; i < N; i++) {
gets(buff);
si1mojime[i] = buff[0];
}
int m, a, r, c, h;
m = a = r = c = h = 0;
for (i = 0; i < N; i++) {
if (si1mojime[i] == 'M') {
m += 1;
} else if (si1mojime[i] == 'A') {
a += 1;
} else if (si1mojime[i] == 'R') {
r += 1;
} else if (si1mojime[i] == 'C') {
c += 1;
} else if (si1mojime[i] == 'H') {
h += 1;
}
}
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;
printf("%d", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, a[100], ans;
string s[10000];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= n; i++) {
if (s[i][0] == 'M') ++a[1];
if (s[i][0] == 'A') ++a[2];
if (s[i][0] == 'R') ++a[3];
if (s[i][0] == 'C') ++a[4];
if (s[i][0] == 'H') ++a[5];
}
ans += a[1] * a[2] * a[3];
ans += a[1] * a[2] * a[4];
ans += a[1] * a[2] * a[5];
ans += a[1] * a[3] * a[4];
ans += a[1] * a[3] * a[5];
ans += a[1] * a[4] * a[5];
ans += a[2] * a[3] * a[4];
ans += a[2] * a[3] * a[5];
ans += a[3] * a[4] * a[5];
printf("%d\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char name[11];
int march[5] = {0};
for (int i = 0; i < n; i++) {
cin >> name;
if (name[0] == 'M')
march[0]++;
else if (name[0] == 'A')
march[1]++;
else if (name[0] == 'R')
march[2]++;
else if (name[0] == 'C')
march[3]++;
else if (name[0] == 'H')
march[4]++;
}
long long combination = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
combination += march[i] * march[j] * march[k];
}
}
}
cout << combination << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<cstdio>
int main(){
string s="MARCH";
int c[5] = {0};
int N;
cin>>N;
for(int i=0; i<N; i++){
string t;
cin>>t;
for(int i=0; i<5; i++){
if(t[0] == s[i])
c[i]++;
}
}
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; j++){
ans += c[i]*c[k]*c[j];
}
}
}
cout << ans << endl;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
import collections
N = int(input())
A = []
for i in range(N):
A.append(input()[0])
c = collections.Counter(A)
if len(set(A)) >= 3:
ans = 1
for i in c.values():
ans *= i
else:
ans = 0
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <sstream>
using namespace std;
int m,a,r,c,h;
int 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 ()
{
string s ;
int n;
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;
int res=0;
for (int i=0;i<10;i++)
res+=d[p[i]]*d[q[i]]*d[r[i]];
cout<<res;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main() {
char s[10001][11];
int n;
char march[] = {'M', 'A', 'R', 'C', 'H'};
long long int d[5] = {0, 0, 0, 0, 0};
int p[5] = {0, 1, 2, 3, 4};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
for (int j = 0; j < 5; j++)
if (s[i][0] == march[j]) d[j]++;
}
long long int sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += d[i] * d[j] * d[k];
}
}
}
printf("%d\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.*;
import java.util.*;
/**
* @author baito
*/
public class Main
{
static StringBuilder sb = new StringBuilder();
static FastScanner sc = new FastScanner(System.in);
static int INF = 10000;
static long MOD = 1000000007;
static long[] f;//factorial
static int[] y4 = {0, 1, 0, -1};
static int[] x4 = {1, 0, -1, 0};
static int[] y8 = {0, 1, 0, -1, -1, 1, 1, -1};
static int[] x8 = {1, 0, -1, 0, 1, -1, 1, -1};
static int N;
static int m, a, r, c, h;
public static void main(String[] args)
{
m = a = r = c = h = 0;
N = sc.nextInt();
//longを忘れるなオーバーフローするぞ
for (int i = 0; i < N; i++)
{
char t = sc.next().toCharArray()[0];
switch (t)
{
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
long ans = 0;
ans += m * a * r;
ans += m * a * c;
ans += m * a * h;
ans += m * r * c;
ans += m * r * h;
ans += m * c * h;
ans += a * r * c;
ans += a * r * h;
ans += a * c * h;
ans += r * c * h;
System.out.println(ans);
}
//次の順列に書き換える、最大値ならfalseを返す
public static boolean nextPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] < A[pos + 1]) break;
}
if (pos == -1) return false;
//posより大きい最小の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] > A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//次の順列に書き換える、最小値ならfalseを返す
public static boolean prevPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] > A[pos + 1]) break;
}
if (pos == -1) return false;
//posより小さい最大の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] < A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//↓nCrをmod計算するために必要。 ***factorial(N)を呼ぶ必要がある***
static long ncr(int n, int r)
{
long result = f[n];
result = result * modInv(f[n - r]) % MOD;
result = result * modInv(f[r]) % MOD;
return result;
}
static long modInv(long n)
{
return modPow(n, MOD - 2);
}
static void factorial(int n)
{
f = new long[n + 1];
f[0] = f[1] = 1;
for (int i = 2; i <= n; i++)
{
f[i] = (f[i - 1] * i) % MOD;
}
}
static long modPow(long x, long n)
{
long res = 1L;
while (n > 0)
{
if ((n & 1) == 1)
{
res = res * x % MOD;
}
x = x * x % MOD;
n >>= 1;
}
return res;
}
//↑nCrをmod計算するために必要
static int gcd(int n, int r)
{
return r == 0 ? n : gcd(r, n % r);
}
static long gcd(long n, long r)
{
return r == 0 ? n : gcd(r, n % r);
}
static <T> void swap(T[] x, int i, int j)
{
T t = x[i];
x[i] = x[j];
x[j] = t;
}
static void swap(int[] x, int i, int j)
{
int t = x[i];
x[i] = x[j];
x[j] = t;
}
public static void reverse(int[] x)
{
int l = 0;
int r = x.length - 1;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
public static void reverse(int[] x, int s, int e)
{
int l = s;
int r = e;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
static int length(int a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int length(long a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int countC2(char[][] a, char c)
{
int co = 0;
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
if (a[i][j] == c) co++;
return co;
}
static void fill(int[][] a, int v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
a[i][j] = v;
}
static int max(int a, int b, int c)
{
return Math.max(a, Math.max(b, c));
}
static int abs(int a)
{
return Math.abs(a);
}
static class FastScanner
{
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in)
{
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
/*public String nextChar(){
return (char)next()[0];
}*/
public String nextLine()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
return reader.readLine();
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong()
{
return Long.parseLong(next());
}
public int nextInt()
{
return Integer.parseInt(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int[] nextIntArray(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public int[][] nextIntArray2(int h, int w)
{
int[][] a = new int[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextInt();
}
}
return a;
}
public int[] nextIntArray21(int n, int scalar)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt() * scalar + nextInt();
return a;
}
public Integer[] nextIntegerArray(int n)
{
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public char[] nextCharArray(int n)
{
char[] a = next().toCharArray();
return a;
}
public char[][] nextCharArray2(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = next().toCharArray();
}
return a;
}
//スペースが入っている場合
public char[][] nextCharArray2s(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = nextLine().replace(" ", "").toCharArray();
}
return a;
}
public char[][] nextWrapCharArray2(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + next() + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
//スペースが入ってる時用
public char[][] nextWrapCharArray2s(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + nextLine().replace(" ", "") + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
public long[] nextLongArray(int n)
{
long[] a = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public long[][] nextLongArray2(int h, int w)
{
long[][] a = new long[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < h; wi++)
{
a[h][w] = nextLong();
}
}
return a;
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
using namespace std;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int solve() {
int n;
cin >> n;
vector<long long> cnt(5);
long long ans = 0;
for (int i = 0; i < (n); ++i) {
string tmp;
cin >> tmp;
char c = tmp[0];
if (c == 'M') cnt[0]++;
if (c == 'A') cnt[1]++;
if (c == 'R') cnt[2]++;
if (c == 'C') cnt[3]++;
if (c == 'H') cnt[4]++;
}
for (int i = 0; i < (5); ++i)
for (int j = i + 1; j < (5); ++j)
for (int k = j + 1; k < (5); ++k) {
ans += (cnt[i] * cnt[j] * cnt[k]) % INF;
ans %= INF;
}
cout << ans << endl;
return 0;
}
int main() {
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <typename LenType = int>
LenType readln(char* buf, LenType max) {
LenType len = 0;
while ((max-- > 0) && ((buf[len] = fgetc(stdin)) != '\n') &&
(buf[len] != EOF))
++len;
buf[len] = 0;
return len;
}
template <typename T>
int orderDesc(const void* p1, const void* p2) {
const T& a = *static_cast<const T*>(p1);
const T& b = *static_cast<const T*>(p2);
return (a < b);
}
template <typename T>
int orderAsc(const void* p1, const void* p2) {
const T& a = *static_cast<const T*>(p1);
const T& b = *static_cast<const T*>(p2);
return (a > b);
}
int N;
char S[10000][11];
int hashfunc(char c) {
switch (c) {
case 'M':
return 0;
case 'A':
return 1;
case 'R':
return 2;
case 'C':
return 3;
case 'H':
return 4;
}
return -1;
}
void solve() {
int counts[5] = {};
int hashcode;
for (int i = 1; i <= N; ++i) {
hashcode = hashfunc(S[i][0]);
if (hashcode != -1) ++counts[hashcode];
}
qsort(counts, 5, sizeof(int), orderDesc<int>);
long long res = 0;
for (int i = 0; i <= 3; ++i) {
for (int j = i + 1; j <= 4; ++j) {
for (int x = j + 1; x <= 5; ++x) {
res += counts[i] * counts[j] * counts[x];
}
}
}
cout << res << endl;
}
int main() {
scanf("%d\n", &N);
for (int i = 1; i <= N && !feof(stdin); ++i) {
readln(S[i], 11);
}
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long N, ans;
int m[256];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
while (N--) {
string s;
cin >> s;
m[s[0]]++;
}
ans += m['M'] * m['A'] * m['R'];
ans += m['M'] * m['A'] * m['C'];
ans += m['M'] * m['A'] * m['H'];
ans += m['M'] * m['R'] * m['C'];
ans += m['M'] * m['R'] * m['H'];
ans += m['M'] * m['C'] * m['H'];
ans += m['A'] * m['R'] * m['C'];
ans += m['A'] * m['R'] * m['H'];
ans += m['A'] * m['C'] * m['H'];
ans += m['R'] * m['C'] * m['H'];
cout << ans << '\n';
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int march[5];
for (int i = 0; i < 5; 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]++;
}
long long ans = 0;
for (int i = 0; i < (1 << 5); i++) {
int num = 0;
int tmp = 1;
for (int j = 0; j < 5; j++) {
if ((i & (1 << j)) != 0) {
num++;
tmp *= march[j];
}
}
if (num == 3) {
ans += tmp;
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, x, y;
string s[100005], a[100005];
char d, f, g;
int main() {
cin >> n;
for (int 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') {
a[x] = s[i];
x++;
}
}
for (int i = 0; i < x; i++) {
d = a[i][0];
for (int j = i + 1; j < x; j++) {
f = a[j][0];
if (d != f) {
for (int q = j + 1; q < x; q++) {
g = a[q][0];
if (f != g && g != d) y++;
}
}
}
}
cout << y;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//入力
int N = sc.nextInt();
List<String> SList = new ArrayList<String>();
for (int i = 0; i < N; i++) {
String S = sc.next();
SList.add(S);
}
int flagM=0;
int countM=0;
int flagA=0;
int countA=0;
int flagR=0;
int countR=0;
int flagC=0;
int countC=0;
int flagH=0;
int countH=0;
Long answer = (long)0;
for (int i = 0; i < N; i++) {
if (SList.get(i).substring(0,1).equals("M")) {
flagM = 1;
countM++;
}
else if (SList.get(i).substring(0,1).equals("A")) {
flagA = 1;
countA++;
}
else if (SList.get(i).substring(0,1).equals("R")) {
flagR = 1;
countR++;
}
else if (SList.get(i).substring(0,1).equals("C")) {
flagC = 1;
countC++;
}
else if (SList.get(i).substring(0,1).equals("H")) {
flagH = 1;
countH++;
}
else {
}
}
if (flagM + flagA + flagR + flagC + flagH >2) {
answer = answer
+ (long)((long)countM * (long)countA * (long)countR)
+ (long)((long)countM * (long)countA * (long)countC)
+ (long)((long)countM * (long)countA * (long)countH)
+ (long)((long)countM * (long)countR * (long)countC)
+ (long)((long)countM * (long)countR * (long)countH)
+ (long)((long)countM * (long)countC * (long)countH)
+ (long)((long)countA * (long)countR * (long)countC)
+ (long)((long)countA * (long)countR * (long)countH)
+ (long)((long)countR * (long)countC * (long)countH);
}
System.out.println(answer);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String [] args){
Scanner sc =new Scanner(System.in);
int N =sc.nextInt();
String s[] = new String[N];
int m=0;
int a=0;
int r=0;
int c=0;
int h=0;
for (int i=0;i<N;i++) {
s[i] = sc.nextLine();
if(s[i].startsWith("M")) {
m++;
}
if(s[i].startsWith("A")) {
a++;
}
if(s[i].startsWith("R")) {
r++;
}
if(s[i].startsWith("C")) {
c++;
}
if(s[i].startsWith("H")) {
h++;
}
}
long ans =m*a*r + m*a*c + m*a*h + a*r*c + a*r*h + r*c*h +m*r*c + m*c*h +a*c*h +m*r*h;
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
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];
map<char, int> mp;
vector<int> p(5);
for (int i = 0; i < (n); i++) {
if (s[i].at(0) == 'M') p[0]++;
if (s[i].at(0) == 'A') p[1]++;
if (s[i].at(0) == 'R') p[2]++;
if (s[i].at(0) == 'C') p[3]++;
if (s[i].at(0) == 'H') p[4]++;
}
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 += p[i] * p[j] * p[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S =[]
for n in range(N):
s = input()
S.append(s[0])
NAME = ["M","A","R","C","H"]
from itertools import permutations
pattern = list(permutations(NAME,3))
LEN = len(S)
cnt=0
for s1 in range(LEN-2):
for s2 in range(s1+1,LEN-1):
for s3 in range(s2+1,LEN):
if (S[s1],S[s2],S[s3]) in pattern:
cnt+=1
print(cnt) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> V(5);
for (int i = 0; i < (int)(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]++;
}
long long ans = 0;
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
ans += V[i] * V[j] * V[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
string s;
VI march(5, 0);
for (int i = 0; i < (int)(n); i++) {
cin >> s;
switch (s[0]) {
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
default:
break;
}
}
ll ans = 0;
for (int a = 0; a < (int)(3); a++)
for (int b = (a + 1); b < (int)(4); b++)
for (int c = (b + 1); c < (int)(5); c++) {
ans += (ll)(march[a] * march[b] * march[c]);
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
map<int,int> name;
map<string,int> name_to_int;
name_to_int["M"]=0;
name_to_int["A"]=1;
name_to_int["R"]=2;
name_to_int["C"]=3;
name_to_int["H"]=4;
int n;
cin>>n;
for(int i=0;i<n;i++){
string s;
name[name_to_int[s[0]]]+=1;
}
int 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+=name[i]*name[j]*name[k];
}
}
}
cout<<ans<<endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int n, m = 0, i, j;
long long int ans;
scanf("%d", &n);
char s[n + 1];
for (i = 0; i < n; i++) {
scanf("%s", &s[i]);
}
long long int a[5];
for (i = 0; i < 5; i++) {
a[i] = 0;
}
for (i = 0; s[i] != '\0'; i++) {
if (s[i] == 'M')
a[0]++;
else if (s[i] == 'A')
a[1]++;
else if (s[i] == 'R')
a[2]++;
else if (s[i] == 'C')
a[3]++;
else if (s[i] == 'H')
a[4]++;
}
ans = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[1] * a[4] +
a[0] * a[2] * a[3] + a[0] * a[2] * a[4] + a[0] * a[3] * a[4] +
a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[3] * a[4] +
a[2] * a[3] * a[4];
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>
int main(void) {
int n;
int head[5] = {};
std::cin >> n;
std::string s[n];
for (int i = 0; i < n; i++) {
std::cin >> s[i];
switch (s[i][0]) {
case 'M':
head[0]++;
break;
case 'A':
head[1]++;
break;
case 'R':
head[2]++;
break;
case 'C':
head[3]++;
break;
case 'H':
head[4]++;
break;
}
}
long long int total = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
total += head[i] * head[j] * head[k];
}
}
}
std::cout << total << std::endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.