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 | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();scan.nextLine();
String[] S = new String[n];
for (int i = 0; i < n; i++) {
S[i] = scan.nextLine();
}
int[] s = new int[5];
for (int i = 0; i < n; i++) {
if (S[i].charAt(0) == 'M') s[0]++;
else if (S[i].charAt(0) == 'A') s[1]++;
else if (S[i].charAt(0) == 'R') s[2]++;
else if (S[i].charAt(0) == 'C') s[3]++;
else if (S[i].charAt(0) == 'H') s[4]++;
}
long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += (long)(s[i]*s[j]*s[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() {
string s = "MARCH";
int c[5] = {0};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string t;
cin >> t;
for (int j = 0; j < 5; j++) {
if (t[0] == s[j]) c[j]++;
}
}
int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; 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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderBS
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string[] nameList = new string[n];
string checkFirst = "MARCH";
int[] count = new int[5];
int pair = 0;
for (int i = 0; i < n; i++)
{
string check = null;
check = Console.ReadLine();
if (checkFirst.IndexOf(check[0]) != -1)
{
count[checkFirst.IndexOf(check[0])]++;
}
}
for (int j = 0; j < 5; j++)
{
for (int k = j + 1; k < 5; k++)
{
for (int l = k + 1; l < 5; l++)
{
pair += count[j] * count[k] * count[l];
}
}
}
Console.Write(pair);
Console.Read();
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N;
cin>>N;
int64_t m=0;
int64_t a=0;
int64_t r=0;
int64_t c=0;
int64_t h=0;
for(int i=0;i<N;i++){
string s;
cin>>s
char x=s.at(0);
if(x=='M') m++;
if(x=='A') a++;
if(x=='R') r++;
if(x=='C') c++;
if(x=='H') h++;
}int64_t ans=m*a*r*c*h;
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
}
}
long int ans = 0;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
printf("%ld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const unsigned long long int mod = 1000000007;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
unsigned long long int n;
cin >> n;
map<char, unsigned long long int> m;
for (unsigned long long 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') {
m[s[0]]++;
}
}
unsigned long long int ans = 0, i = 1;
vector<unsigned long long int> v;
if (m.size() == 0) {
cout << 0 << endl;
return 0;
}
for (auto it = m.begin(); it != m.end(); it++) {
v.push_back(it->second);
}
for (unsigned long long int i = 0; i < v.size() - 2; i++) {
for (unsigned long long int j = i + 1; j < v.size() - 1; j++) {
for (unsigned long long int k = j + 1; k < v.size(); k++) {
ans = ans + v[i] * v[j] * v[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArCorder
{
class Program
{
class inner : IEquatable<inner>
{
string m_First;
string m_Second;
string m_Therd;
public inner (string first, string second, string therd)
{
m_First = first;
m_Second = second;
m_Therd = therd;
}
public Boolean IsTarget()
{
if (m_First.First().Equals(m_Second.First()) || m_First.First().Equals(m_Therd.First()) || m_Second.First().Equals(m_Therd.First()))
{
return false;
}
else
{
return true;
}
}
public bool Equals(inner obj)
{
return obj.GetHashCode() == this.GetHashCode();
}
public override int GetHashCode()
{
return this.m_First.GetHashCode() ^ this.m_Second.GetHashCode() ^ this.m_Therd.GetHashCode();
}
}
static void Main()
{
int max = int.Parse(Console.ReadLine());
List<string> names = new List<string>();
for (int i = 0; i < max; i++)
{
names.Add(Console.ReadLine());
}
List<string> targetNames = names.Where(x => x.StartsWith("M") ||
x.StartsWith("A") ||
x.StartsWith("R") ||
x.StartsWith("C") ||
x.StartsWith("H")).ToList();
List<inner> allPatern = new List<inner>();
foreach (string first in targetNames){
foreach(string second in targetNames.Where(x => !x.StartsWith(first.First().ToString())))
{
foreach (string therd in targetNames.Where(x => !x.StartsWith(first.First().ToString()) && !x.StartsWith(second.First().ToString())))
{
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> m;
m.clear();
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
m[0]++;
else if (s[0] == 'A')
m[1]++;
else if (s[0] == 'R')
m[2]++;
else if (s[0] == 'C')
m[3]++;
else if (s[0] == 'H')
m[4]++;
}
long long res = 1;
long long ans = 0;
int tmp;
for (int bit = 0; bit < (1 << 5); bit++) {
tmp = 0;
for (int i = 0; i < 5; i++) {
if (bit & (1 << i)) {
tmp++;
res *= m[i];
}
}
if (tmp == 3) {
ans += res;
}
}
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())
lis = [input() for _ in range(n)]
lis.sort()
choice = list(itertools.combinations(range(n), 3))
count = 0
for ch in choice:
master = set(['M','A','R','C','H'])
se = set([lis[ch[0]][0],lis[ch[1]][0],lis[ch[2]][0]])
if len(se) <=2:
break
#print(master,se,master - se)
if len(master - se) == 2:
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int n, mark[5];
char s[10005][11];
int select(char ch) {
if (ch == 'M' && mark[1] == 0) {
mark[0] = 1;
return 1;
} else if (ch == 'A' && mark[1] == 0) {
mark[1] = 1;
return 1;
} else if (ch == 'R' && mark[2] == 0) {
mark[2] = 1;
return 1;
} else if (ch == 'C' && mark[3] == 0) {
mark[3] = 1;
return 1;
} else if (ch == 'H' && mark[4] == 0) {
mark[4] = 1;
return 1;
} else
return 0;
}
int main(int argc, char *argv[]) {
while (cin >> n) {
int ans = 0;
memset(s, 0, sizeof(s));
memset(mark, 0, sizeof(mark));
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < n; k++) {
memset(mark, 0, sizeof(mark));
if (select(s[i][0]) == 0 || select(s[j][0]) == 0 ||
select(s[k][0]) == 0)
continue;
ans++;
}
cout << ans << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import*;print(sum(p*q*r for p,q,r in combinations([list(s[0]for s in open(0).readlines()).count(s)for s in"MARCH"],3))) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
var dic = new Dictionary<char, int>();
for (int i = 0; i < n; i++)
{
string s = Console.ReadLine();
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
{
// ๅญๅจใใใ++ใใใชใใใฐๅค1ใง่ฟฝๅ
if (dic.ContainsKey(s[0])) dic[s[0]]++;
else dic[s[0]] = 1;
}
}
int ans = 0;
for (int i = 0; i < 1 << dic.Count; i++)
{
// ใใใๆผ็ฎใง3ใคใฎๆใ็ฎใๅ
จ้จ่จ็ฎ
var bits = new bool[dic.Count];
int m = 0;
for (int j = 0; j < dic.Count; j++)
{
if ((i >> j & 1) == 1)
{
bits[j] = true;
m++;
}
}
if (m == 3)
{
int tmp = 1;
for (int j = 0; j < dic.Count; j++)
{
if (bits[j]) tmp *= dic.ElementAt(j).Value;
}
ans += tmp;
}
}
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 | java | import java.util.ArrayList;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ไบบๆฐใๅๅพ
Integer n = sc.nextInt();
// ๅๅใๅๅพ
ArrayList<String> m = new ArrayList<String>();
ArrayList<String> a = new ArrayList<String>();
ArrayList<String> r = new ArrayList<String>();
ArrayList<String> c = new ArrayList<String>();
ArrayList<String> h = new ArrayList<String>();
for(int i = 0; i < n ; i++){
String name = sc.next();
if("M".equals(name.substring(0,1))){
m.add(name);
}else if("A".equals(name.substring(0,1))){
a.add(name);
}else if("R".equals(name.substring(0,1))){
r.add(name);
}else if("C".equals(name.substring(0,1))){
c.add(name);
}else if("H".equals(name.substring(0,1))){
h.add(name);
}
}
// ใใใใใฎๆๅญใใๅงใพใๅๅใฎๆฐใ้่จ
Long mNum = (long)m.size();
Long aNum = (long)a.size();
Long rNum = (long)r.size();
Long cNum = (long)c.size();
Long hNum = (long)h.size();
ArrayList<Long> valid = new ArrayList<Long>();
if(mNum != 0){
valid.add(mNum);
}
if(aNum != 0){
valid.add(aNum);
}
if(rNum != 0){
valid.add(rNum);
}
if(cNum != 0){
valid.add(cNum);
}
if(hNum != 0){
valid.add(hNum);
}
// ็ตใฟๅใใ็ทๆฐใ่จ็ฎ(valid.size()<3ใฎๅ ดๅใฏ็ตใฟๅใใใ1ใคใๆ็ซใใชใใฎใงๆดๆฐใชใ)
long pair = 0;
if(3 == valid.size()){
long allMulti = 1;
for(int i = 0 ; i < valid.size() ; i++){
allMulti = allMulti * valid.get(i);
}
pair = allMulti;
}else if(4 == valid.size()){
long allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
long tmp = allMulti/valid.get(i);
pair = pair + tmp;
}
}else if(5 == valid.size()){
long allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
long tmp = allMulti/valid.get(i);
for(int j = 0; j < valid.size(); j++){
if(i < j ){
tmp = tmp/valid.get(j);
pair = pair + tmp;
}
}
}
}
System.out.println((long)pair);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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, MOD = 1e9 + 7,
around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const long double PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const long long LINF = 1e18;
int main() {
int n;
cin >> n;
int li[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') li[0]++;
if (s[0] == 'A') li[1]++;
if (s[0] == 'R') li[2]++;
if (s[0] == 'C') li[3]++;
if (s[0] == 'H') li[4]++;
}
int c = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k < j; k++) {
c += li[i] * li[j] * li[k];
}
}
}
cout << c << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S[104];
long long Ans = 0;
int m[5] = {};
int sum = 0;
cin >> N;
for (int i = 0; i < (N); i++) {
cin >> S[i];
if (S[i][0] == 'M') {
m[0]++;
} else if (S[i][0] == 'A') {
m[1]++;
} else if (S[i][0] == 'R') {
m[2]++;
} else if (S[i][0] == 'C') {
m[3]++;
} else if (S[i][0] == 'H') {
m[4]++;
}
}
for (int i = 0; i < (5); i++) {
sum += m[i];
}
Ans += m[0] * m[1] * m[2];
Ans += m[0] * m[1] * m[3];
Ans += m[0] * m[1] * m[4];
Ans += m[0] * m[2] * m[3];
Ans += m[0] * m[2] * m[4];
Ans += m[0] * m[3] * m[4];
Ans += m[1] * m[2] * m[3];
Ans += m[1] * m[2] * m[4];
Ans += m[1] * m[3] * m[4];
Ans += m[1] * m[3] * m[4];
Ans += m[2] * m[3] * m[4];
cout << Ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long N;
cin >> N;
long long i;
string s[100010];
long long cnt[5];
;
for (i = 0; i < N; i++) {
cin >> s[i];
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
long long ans = 0;
ans += cnt[0] * cnt[1] * (cnt[2] + cnt[3] + cnt[4]);
ans += cnt[0] * cnt[2] * (cnt[3] * cnt[4]);
ans += cnt[0] * cnt[3] * cnt[4];
ans += cnt[1] * cnt[2] * (cnt[3] + cnt[4]);
ans += cnt[1] * cnt[3] * cnt[4];
ans += cnt[2] * cnt[3] * cnt[4];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> march(5, 0);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s.at(0) == 'M')
march.at(0)++;
else if (s.at(0) == 'A')
march.at(1)++;
else if (s.at(0) == 'R')
march.at(2)++;
else if (s.at(0) == 'C')
march.at(3)++;
else if (s.at(0) == 'H')
march.at(4)++;
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += march.at(i) * march.at(j) * march.at(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>
int main() {
int n, m, a, r, c, h, i;
m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
scanf("%d", &n);
char name[100];
for (i = 0; i < n; i++) {
scanf("%s", name);
if (name[0] == 'M') {
m++;
} else {
if (name[0] == 'A') {
a++;
} else {
if (name[0] == 'R') {
r++;
} else {
if (name[0] == 'C') {
c++;
} else {
if (name[0] == 'H') {
h++;
}
}
}
}
}
}
long long int ans = 0;
ans += m * a * (r + c + h);
ans += m * r * (c + h);
ans += m * c * h;
ans += a * r * (c + h);
ans += a * c * h;
ans += r * c * h;
printf("%llu\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 | file:///home/noilinux/Desktop/march.cpp
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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
def main():
MARCH = ['M','A','R','C','H']
N = int(input())
S = []
cnt = 0
for _ in range(N):
s = input()
if not s[0] in MARCH:
continue
S.append(s)
for a,b,c in itertools.combinations(S,3):
# print(a,b,c,cnt)
if a[0] == b[0] or b[0] == c[0] or a[0] == c[0]:
continue
cnt += 1
print(cnt)
if __name__ == '__main__':
main() |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<char,int> mp;
for (int i = 0;i < N; i++) {
string s;
cin >> s;
char a = s.at(0);
if ((a == 'M') || (a=='A') || (a=='R') || (a=='C') || (a=='H')) {
mp[a]++;
}
}
long long ans = 0;
ans += mp[M]*mp[A]*mp[R];
ans += mp[M]*mp[A]*mp[C];
ans += mp[M]*mp[A]*mp[H];
ans += mp[M]*mp[R]*mp[C];
ans += mp[M]*mp[R]*mp[H];
ans += mp[M]*mp[C]*mp[H];
ans += mp[A]*mp[R]*mp[C];
ans += mp[A]*mp[R]*mp[H];
ans += mp[A]*mp[C]*mp[H];
ans += mp[R]*mp[C]*mp[H];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | <?php
$n = trim(fgets(STDIN));
$count = [];
$march=["M","A","R","C","H"];
for($i=0; $i<$n; $i++){
$s = trim(fgets(STDIN));
if(in_array($s[0],$march)){
$count[$s[0]]++;
}
}
// print_r($count);
$c = count($count);
$ans = $c;
$c--;
foreach ($count as $d){
if($d > 1){
$ans += ($d-1)*$c;
}
}
echo $ans; |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdIn=new Scanner(System.in);
int N=stdIn.nextInt();
String s="";
int S[]=new int[5];
int z=0,y=0,x=0;
long ans=0;
while(z<N){
s=stdIn.next();
s=s.substring(0,1);
if(s.equals("M"))
S[0]++;
if(s.equals("A"))
S[1]++;
if(s.equals("R"))
S[2]++;
if(s.equals("C"))
S[3]++;
if(s.equals("H"))
S[4]++;
z++;
}z=0;
while(z<3){
y=z+1;
while(y<4){
x=y+1;
while(x<5){
ans+=S[z]*S[y]*S[x];
x++;
}
x=0;y++;
}
y=0;z++;
}
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 | //
// main.cpp
// CompetitiveProgramming
//
// Created by Yuma Kikuchi on 2018/03/02.
// Copyright ยฉ 2018ๅนด yumarimo. All rights reserved.
//
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
llong pow(int x, int n) {
llong ans = x;
if (n == 0) return 1;
for(int i = 0; i < n - 1; i++) {
ans *= x;
}
return ans;
}
void swap(int *X, int *Y){
int t = *X; *X = *Y; *Y = t;
}
string toUpper(string s) {
string t = s;
REP(i, s.size()) {
t[i] = toupper(s[i]);
}
return t;
}
string toLower(string s) {
string t = s;
REP(i, s.size()) {
t[i] = tolower(s[i]);
}
return t;
}
const static int Max = 100001;
long dp[Max][Max];
long nCr(long n, long r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n;
if(dp[n][r]) return dp[n][r];
return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}
int main() {
int n; cin >> n;
int N[5] = {0};
string name;
bool check[5] = {false};
int cnt = 0;
REP(i, n) {
cin >> name;
if (name[0] == 'M') {
N[0]++;
check[0] = true;
cnt++;
} else if (name[0] == 'A') {
N[1]++;
check[1] = true;
cnt++;
} else if (name[0] == 'R') {
N[2]++;
check[2] = true;
cnt++;
} else if (name[0] == 'C') {
N[3]++;
check[3] = true;
cnt++;
} else if (name[0] == 'H') {
N[4]++;
check[4] = true;
cnt++;
} else {
continue;
}
}
int T = 0;
REP(i, 5) {
if (check[i]) T++;
}
if (cnt >= 3 && T >= 3) {
int tmp = 0;
REP(i, 5) {
if (N[i] >= 2) tmp += nCr(N[i], 2) * (cnt - N[i]);
}
cout << nCr(cnt, 3) - tmp << endl;
} else {
cout << 0 << endl;
}
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const long long LINF = 1e18;
long long int n, cnt = 0, ans = 0, a = 0, b, c = 0, cmp, cmpp, data, m = 0,
h = 0, w, x, y, xcmp, ycmp, sum = 0, r = 0;
string s;
vector<int> z;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
cmp = n;
cmpp = n;
for (long long int(i) = 0; (i) < (int)(n); (i)++) {
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
cmp--;
cmpp--;
}
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++;
}
}
if (m != 1 && m != 0) {
cnt = m;
} else if (a != 1 && a != 0) {
cnt += a;
} else if (r != 1 && r != 0) {
cnt += r;
} else if (c != 1 && c != 0) {
cnt += c;
} else if (h != 1 && h != 0) {
cnt += h;
}
cmp = cmp * (cmp - 1) * (cmp - 2);
cmp /= 6;
cout << (cmp - (cmpp - 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 | extern crate itertools;
use itertools::Itertools;
use std::collections::HashSet;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("filed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}
fn main() {
let n:usize = read();
let mut arr:Vec<String> = Vec::new();
for _ in 0..n {
let s:String = read();
match &s[0..1] {
"M" => arr.push(s),
"A" => arr.push(s),
"R" => arr.push(s),
"C" => arr.push(s),
"H" => arr.push(s),
_ => continue
}
}
let mut ans = 0;
let mut set = HashSet::new();
arr.into_iter().combinations(3).sorted().unique().for_each(|x| {
set.clear();
for i in x {
set.insert(i.chars().nth(0).unwrap());
}
if set.len() == 3 {
ans += 1;
}
});
println!("{}", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
map<char, int> mp;
for (int i = 0; i < (N); i++) {
string S;
cin >> S;
mp[S[0]]++;
}
char S[5] = {'M', 'A', 'R', 'C', 'H'};
int64_t Ans = 0;
for (int i = 0; i < 32; i++) {
int cnt = 0;
int C[5];
for (int j = 0; j < 5; j++) {
int k = i & (1 << j);
if (k) {
C[cnt++] = mp[S[j]];
}
}
if (cnt == 3) {
Ans += C[0] * C[1] * C[2];
}
}
cout << Ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N= sc.nextInt();
int a[]= new int[5];
char c[] = {'M','A','R','C','H'};
long sum =0;
for (int i =0;i<N;i++) {
String str = sc.next();
for (int j=0;j<c.length;j++) {
if (str.charAt(0)==c[j]) {
a[j] ++;
break;
}
}
}
sum +=Main.count(a[0], a[1], a[2]);
sum +=Main.count(a[0], a[1], a[3]);
sum +=Main.count(a[0], a[1], a[4]);
sum +=Main.count(a[0], a[2], a[3]);
sum +=Main.count(a[0], a[2], a[4]);
sum +=Main.count(a[0], a[3], a[4]);
sum +=Main.count(a[1], a[2], a[3]);
sum +=Main.count(a[1], a[2], a[4]);
sum +=Main.count(a[1], a[3], a[4]);
sum +=Main.count(a[2], a[3], a[4]);
}
private static long count(int a,int b,int c) {
return a*b*c;
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int num[] = new int[5];
for (int i = 0; i < N; i++) {
String S = sc.next();
switch (S.charAt(0)) {
case 'M':
num[0]++;
break;
case 'A':
num[1]++;
break;
case 'R':
num[2]++;
break;
case 'C':
num[3]++;
break;
case 'H':
num[4]++;
break;
}
}
long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i+1; j < 5; j++) {
for (int k = j+1; k < 5; k++) {
ans += num[i] * num[j] * num[k];
}
}
}
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 n, m, a, r, c, h;
string s;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
cout << m * a * r + m * a * c + m * a * h + a * r * c + a * r * h +
r * c * h + m * r * c + m * r * h + m * c * h + a * c * h;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int initial[5] = {};
void divide(string s) {
if (s[0] == 'M')
initial[0]++;
else if (s[0] == 'A')
initial[1]++;
else if (s[0] == 'R')
initial[2]++;
else if (s[0] == 'C')
initial[3]++;
else if (s[0] == 'H')
initial[4]++;
}
int main() {
int n;
long long ans = 0;
cin >> n;
string name[n];
for (int i = 0; i < n; i++) cin >> name[i];
for (int i = 0; i < n; i++) divide(name[i]);
for (int i = 1; i < 4; i++) {
for (int j = 0; j < i; j++) {
for (int k = (i + 1); k < 5; k++) {
ans += (initial[i] * initial[j] * initial[k]);
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
Map<Character, Long> map = new HashMap<>();
long count = 0;
for (int i = 0; i < N; i++) {
Character S = in.next().charAt(0);
if (S == 'M' || S == 'A' || S == 'R' || S == 'C' || S == 'H') {
if (map.containsKey(S)) {
map.put(S, map.get(S) + 1);
} else {
map.put(S, 1l);
}
count++;
}
}
long ans = 0;
if (count >= 3) {
ans = count * (count - 1) * (count - 2) / 6;
for (Map.Entry<Character, Long> s : map.entrySet()) {
if (s.getValue() >= 2) {
long sNum = s.getValue() * (s.getValue() - 1) / 2;
ans -= sNum * (count - s.getValue());
}
}
}
System.out.println(ans);
in.close();
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
N = int(input())
name=[]
for i in range(N):
si = input()
if si[0] in ['M', 'A', 'R', 'C', 'H']:
name.append(si)
if name==[]:
print(0)
exit()
ans=0
for i, names in enumerate(list(combinations(name, 3))):
x,y,z=names[0][0],names[1][0],names[2][0]
if x==y or y==z or z==x:
continue
else:
ans+=1
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
static Scanner scan=new Scanner(System.in);
static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
static long lcm (int a, int b) {return a*b/gcd(a,b);}
static int max(int a,int b) {return a>b?a:b;}
static int min(int a,int b) {return a<b?a:b;}
static long factorial(int i) {return i==1?1:i*factorial(i-1);}
static int lower_bound(int a[],int key) {
int low=0,high=a.length;
while(low<high) {
int mid=((high-low)/2)+low;
if(a[mid]<=key)low=mid+1;
else high=mid;
}
return high;
}
static int upper_bound(int a[],int key) {
int low=0,high=a.length;
while(low<high) {
int mid=((high-low)/2)+low;
if(a[mid]<key)low=mid+1;
else high=mid;
}
return high;
}
static boolean isPrime (int n) {
if (n==2) return true;
if (n<2 || n%2==0) return false;
double d = Math.sqrt(n);
for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
return true;
}
static int upper_division(int a,int b) {
if(a%b==0) {
return a/b;
}
else {
return a/b+1;
}
}
static long lupper_division(long a,long b) {
if(a%b==0) {
return a/b;
}
else {
return a/b+1;
}
}
static long lmax(long a,long b) {return Math.max(a, b);}
static long lmin(long a,long b) {return Math.min(a, b);}
static int[] setArray(int a) {
int b[]=new int[a];
for(int i=0;i<a;i++) {
b[i]=scan.nextInt();
}
return b;
}
public static void main(String[] args) {
int z=scan.nextInt();
int m=0,a=0,r=0,c=0,h=0;
for(int i=0;i<z;i++) {
String str=scan.next();
char ch=str.charAt(0);
switch(ch) {
case 'M':m++;break;
case 'A':a++;break;
case 'R':r++;break;
case 'C':c++;break;
case 'H':h++;break;
}
}
long ans=0;//mar,mac,mah,mrc,mrh,mch,arc,arh,ach,rch
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);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | fun main(args: Array<String>) {
val n = readLine()!!.toInt()
val l = (1 .. n).map{ readLine()!!.toString()}
var ll = mutableListOf(0, 0, 0, 0, 0)
for(i in 0 until n){
when(l[i][0]){
'M' -> ll[0] += 1
'A' -> ll[1] += 1
'R' -> ll[2] += 1
'C' -> ll[3] += 1
'H' -> ll[4] += 1
}
}
var a = 0
for(i in 0..4) for (j in i+1..4) for (k in j+1..4){
a += ll[i] * ll[j] * ll[k]
}
println(a)
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n;
char s[100000][101];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int cm = 0, ca = 0, cr = 0, cc = 0, ch = 0;
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
cm++;
}
if (s[i][0] == 'A') {
ca++;
}
if (s[i][0] == 'R') {
cr++;
}
if (s[i][0] == 'C') {
cc++;
}
if (s[i][0] == 'H') {
ch++;
}
}
int ans = 0;
ans = cm * ca * cr;
ans += cm * ca * cc;
ans += cm * ca * ch;
ans += cm * cr * cc;
ans += cm * cr * ch;
ans += cm * cc * ch;
ans += ca * cr * cc;
ans += ca * cr * ch;
ans += ca * cc * ch;
ans += cr * cc * ch;
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 | java | import java.util.*;
public class Main {
static int Examine(int countM,int countA,int countR,int countC,int countH) {
int count = 0;
count += countR * countC * countH;
count += countA * countC * countH;
count += countA * countR * countH;
count += countA * countR * countC;
count += countM * countC * countH;
count += countM * countR * countH;
count += countM * countR * countC;
count += countM * countA * countH;
count += countM * countA * countC;
count += countM * countA * countR;
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String[] names = new String[N];
//ใใใใใใฎ้ ญๆๅญใฎๅๅใใใคไบบๆฐ
int countM = 0;
int countA = 0;
int countR = 0;
int countC = 0;
int countH = 0;
String[] I = new String[N];
for(int i = 0;i < N;i++) { // ๅๅใๅ
ฅๅใจใใฆๅใๅใ
names[i] = sc.next();
I[i] = names[i].substring(0,1); //ใใใใใใฎๅๅใฎ้ ญๆๅญใๆ ผ็ดใใ
}
for(int k = 0;k < N;k++) { // ใใใใใฎ้ ญๆๅญใๆใคๅๅใฎไบบ้ใไฝไบบใ่ชฟในใ
if(I[k].equals("M")) countM++;
else if(I[k].equals("A")) countA++;
else if(I[k].equals("R")) countR++;
else if(I[k].equals("C")) countC++;
else if(I[k].equals("H")) countH++;
}
System.out.println(countM+" "+countA+" "+countR+" "+countC+" "+countH);
System.out.println(Examine(countM,countA,countR,countC,countH));
sc.close();
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
char check[5] = {'M', 'A', 'R', 'C', 'H'};
unsigned long long cnt[5] = {0, 0, 0, 0, 0};
unsigned long long com(unsigned long long n) {
return n * (n - 1) * (n - 2) / 6;
}
int main() {
int n;
unsigned long long ans = 0;
unsigned long long CNT1 = 0, CNT2 = 0, multi = 1, sum = 0;
string s[100005] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 5; j++) {
if (s[i][0] == check[j]) {
cnt[j]++;
}
}
}
for (int i = 0; i < 5; i++) {
if (cnt[i] == 1) {
CNT1++;
}
}
ans += com(CNT1);
if (ans != 0) {
multi *= CNT1;
}
for (int i = 0; i < 5; i++) {
if (cnt[i] > 1) {
multi *= cnt[i];
CNT2++;
}
sum += cnt[i];
}
if (sum < 3 && CNT2 < 2) {
cout << 0 << endl;
} else {
ans += multi;
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())
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 | UNKNOWN | using System;
namespace abc089_c
{
class Program
{
static void Main(string[] args)
{
var n = int.Parse(System.Console.ReadLine());
var march = new int[5];
for (var i = 0; i < n; i++)
{
var s = System.Console.ReadLine();
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 ans = 0;
for (var i = 0; i < 3; i++)
{
for (var j = i + 1; j < 4; j++)
{
for (var h = j + 1; h < 5; h++)
{
ans += march[i] * march[j] * march[h];
}
}
}
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>
int main() {
int n;
std::vector<char> s;
std::cin >> n;
std::string b;
std::cin.ignore();
for (int i = 0; i < n; i++) {
std::getline(std::cin, b);
if (b[0] == 'M' || b[0] == 'A' || b[0] == 'R' || b[0] == 'C' || b[0] == 'H')
s.push_back(b[0]);
}
if (s.size() < 3) std::cout << "0" << std::endl;
std::sort(s.begin(), s.end());
int ans = 0;
for (int i = 2; i < s.size(); i++) {
for (int j = 1; j < i; j++) {
for (int k = 0; k < j; k++) {
if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans++;
}
}
}
std::cout << ans << 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;
using ll = long long;
using ld = long double;
int main() {
ll N;
cin >> N;
vector<ll> v(5, 0);
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
if (s[0] == 'M')
v[0]++;
else if (s[0] == 'A')
v[1]++;
else if (s[0] == 'R')
v[2]++;
else if (s[0] == 'C')
v[3]++;
else if (s[0] == 'H')
v[4]++;
}
for (int i = 0; i < 5; ++i) {
cout << v[i] << " ";
}
cout << endl;
ll ans = 0;
for (int i = 0; i < 3; ++i) {
for (int j = i + 1; j < 4; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += (v[i] * v[j] * v[k]);
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
std::set<string> dict;
int n;
scanf("%d", &n);
string str;
int countM = 0;
int countA = 0;
int countR = 0;
int countC = 0;
int countH = 0;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M') {
countM++;
}
if (str[0] == 'A') {
countA++;
}
if (str[0] == 'R') {
countR++;
}
if (str[0] == 'C') {
countC++;
}
if (str[0] == 'H') {
countH++;
}
}
unsigned long long sum = 0;
sum += countM * countA * countR;
sum += countM * countA * countC;
sum += countM * countA * countH;
sum += countM * countR * countC;
sum += countM * countR * countH;
sum += countM * countC * countH;
sum += countA * countR * countC;
sum += countA * countR * countH;
sum += countA * countC * countH;
sum += countR * countC * countH;
printf("%llu", sum);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char s[20000];
int a[10];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s);
if (s[0] == 'M') a[1]++;
if (s[0] == 'A') a[2]++;
if (s[0] == 'R') a[3]++;
if (s[0] == 'C') a[4]++;
if (s[0] == 'H') a[5]++;
}
int ans = 0;
for (int i = 1; i <= 5; i++) {
for (int j = i + 1; j <= 5; j++) {
for (int k = j + 1; k <= 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
printf("%d", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | #encoding:utf-8
import math
import itertools
n = int(input())
s = []
for i in range(n):
s.append(str(input()))
chosen_names = {"m":0,"a":0,"r":0,"c":0,"h":0}
for name in s:
if name[0] == "M":
chosen_names["m"] += 1
elif name[0] == "A":
chosen_names["a"] += 1
elif name[0] == "R":
chosen_names["r"] += 1
elif name[0] == "C":
chosen_names["c"] += 1
elif name[0] == "H":
chosen_names["h"] += 1
answer = 0
capitals = list("march")
capital_set = itertools.com
binations(capitals,3)
for capital in capital_set:
answer += chosen_names[capital[0]] * chosen_names[capital[1]] * chosen_names[capital[2]]
print(answer)
# def combinations_count(n,r):
# return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long nCk(long long n, long long k) {
long long res = 1;
for (long long i = 1; i <= k; i++) {
res = (res * (n - i + 1) / i);
}
return res;
}
void solve() {
long long n;
cin >> n;
map<char, long long> mp;
for (int i = 0, i_len = (n); i < i_len; ++i) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
mp[s[0]]++;
}
}
if (mp.size() < 3)
cout << 0 << endl;
else {
long long cnt1 = 0;
long long sol = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
if ((it->second) > 1) {
sol += (it->second) * nCk(mp.size() - 1, 2);
} else {
cnt1++;
}
}
if (cnt1 > 2) sol += nCk(cnt1, 3);
cout << sol << 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 <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
long long nums[5] = {0};
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S.at(0) == 'M')
nums[0]++;
else if (S.at(0) == 'A')
nums[1]++;
else if (S.at(0) == 'R')
nums[2]++;
else if (S.at(0) == 'C')
nums[3]++;
else if (S.at(0) == 'H')
nums[4]++;
}
long long ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 4; k++) {
if (nums[i] == 0 || nums[j] == 0 || nums[k] == 0) continue;
ans += nums[i] * nums[j] * nums[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;
const long long mod = 1e9 + 7;
typedef vector<long long> VL;
typedef vector<VL> VLL;
typedef vector<pair<long long, long long>> PS;
template <class T, class U>
bool chmax(T &map<long long, long long> MP;, U b) {
if (map<long long, long long> MP; <= b) {
map<long long, long long> MP;
= b;
return 1;
}
return 0;
}
template <class T, class U>
bool chmin(T &map<long long, long long> MP;, U b) {
if (map<long long, long long> MP; > b) {
map<long long, long long> MP;
= b;
return 1;
}
return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
os << "{";
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i < v.size() - 1 ? ", " : "");
}
os << "}";
return os;
}
const int MAX = 510000;
const int MOD = 1000000007;
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 % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
long long n, k, m, x = 0, y = 0, z = 0, cnt = 0, h = 0, w = 0, ans = 0,
sum = 0, Max = -1, Min = 3e9 + 1;
string s;
cin >> n;
COMinit();
vector<string> map<long long, long long> MP;
(n);
VL b(5);
for (int i = 0; i < n; i++) {
cin >> map<long long, long long> MP;
[i];
if (map<long long, long long> MP;[i][0] == 'M') {
b[0]++;
}
if (map<long long, long long> MP;[i][0] == 'A') {
b[1]++;
}
if (map<long long, long long> MP;[i][0] == 'R') {
b[2]++;
}
if (map<long long, long long> MP;[i][0] == 'C') {
b[3]++;
}
if (map<long long, long long> MP;[i][0] == 'H') {
b[4]++;
}
}
for (int i = 0; i < 5; i++) {
if (b[i] > 0) x++;
}
ans = COM(x, 3);
for (int i = 0; i < 5; i++) {
if (b[i] > 1) {
cnt++;
ans *= b[i];
}
}
while (cnt > 0) {
ans -= COM(x - 1, 3);
cnt--;
}
cout << (ans) << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool check(string s) {
for (int i = 0; i < s.size(); i++) {
s[i] = char(tolower(s[i]));
}
for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[5] = {
0,
};
string s;
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]++;
}
}
int sum = 0, k = 0;
for (int i = 0; i < 5; i++) {
if (a[i]) {
k++;
}
}
for (int i = 0; i < 5; i++) {
if (a[i] > 1) {
sum += (k - 1) / 3 * a[i];
} else {
sum += a[i];
}
}
cout << sum;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in S:
if i[0] in march:
march[i[0]] += 1
ans = 0
for first, second, third in combinations(march.values(), 3):
ans += first * second * third
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>
using namespace std;
int main(void){
int n;
cin >> n;
string a;
int m,a,r,c,h = 0;
for (int i = 0; i < n; i++)
{
cin >> a;
if (a[0] = 'M') m++;
if (a[0] = 'A') a++;
if (a[0] = 'R') r++;
if (a[0] = 'C') c++;
if (a[0] = 'H') h++;
}
cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h +r*c*h << endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline string uppercase(string s) {
int n = (int)s.size();
for (int i = 0; i < n; i++)
if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
return s;
}
inline string lowercase(string s) {
int n = (int)s.size();
for (int i = 0; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
return s;
}
int main() {
long long n, ans = 0;
cin >> n;
vector<string> s(n);
string str;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] != 'M' && str[0] != 'A' && str[0] != 'R' && str[0] != 'C' &&
str[0] != 'H')
n--;
else
s[i] = str;
}
sort((s).begin(), (s).end());
for (int i = 0; i < n; i++) {
for (int j = (i + 1); j < (n); j++) {
for (int k = (j + 1); k < (n); k++) {
if (i == j || i == k)
continue;
else {
if (s[i][0] == s[j][0]) {
break;
}
if (s[i][0] != s[k][0] && s[j][0] != s[k][0]) {
ans++;
}
}
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N;
const int MAX_N = 1.0e5 + 100;
string S[MAX_N];
int main() {
cin >> N;
for (int i = 0; i < N; i++) cin >> S[i];
int MARCH[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M')
MARCH[0]++;
else if (S[i][0] == 'A')
MARCH[1]++;
else if (S[i][0] == 'R')
MARCH[2]++;
else if (S[i][0] == 'C')
MARCH[3]++;
else if (S[i][0] == 'H')
MARCH[4]++;
}
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 += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long combination(long long n, long long k) {
long long r = 1;
for (long long d = 1; d <= k; ++d) {
r *= n--;
r /= d;
}
return r;
}
int main() {
int N;
cin >> N;
vector<char> chars = {'M', 'A', 'R', 'C', 'H'};
map<char, int> n_persons;
string name;
for (int i = 0; i < N; i++) {
cin >> name;
for (int j = 0; j < chars.size(); j++) {
if (name.at(0) == chars.at(j)) {
n_persons[chars.at(j)]++;
}
}
}
long long all_patterns = 0;
for (pair<char, int> n_p : n_persons) {
all_patterns += n_p.second;
}
long long group_patterns = combination(all_patterns, 3);
for (pair<char, int> n_p : n_persons) {
if (n_p.second == 1) {
continue;
}
group_patterns -= combination(n_p.second, 3);
group_patterns -=
combination(n_p.second, 2) * combination(N - n_p.second, 1);
}
cout << group_patterns << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import combinations
n = int(input())
march = ("M","A","R","C","H")
d = []
for _ in range(n):
pre = input()[0]
if pre in march: d.append(pre)
if len(d) < 3:
print(0)
exit()
ans = 0
for i in combinations(d,3):
if len(set(i)) == 3:
ans += 1
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int change(char a) {
if (a == 'M')
return 1;
else if (a == 'A')
return 2;
else if (a == 'R')
return 3;
else if (a == 'C')
return 4;
else if (a == 'H')
return 5;
}
int a[6] = {0};
long long ans;
int main() {
int n, cnt = 0;
string s;
cin >> n;
while (n--) {
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
a[change(s[0])]++;
}
}
ans = a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[2] * a[5] +
a[2] * a[3] * a[4] + a[2] * a[3] * a[5] + a[1] * a[3] * a[4] +
a[1] * a[3] * a[5] + a[2] * a[4] * a[5] + a[3] * a[4] * a[5];
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
int m = 0, a = 0, r = 0, c = 0, h = 0;
Set<String> names = new HashSet<>();
for (int i = 0; i < n; i++) {
String name = sc.next();
if (names.contains(name)) {
continue;
}
names.add(name);
char ch = name.charAt(0);
if (ch == 'M') {
m++;
} else if (ch == 'A') {
a++;
} else if (ch == 'R') {
r++;
} else if (ch == 'C') {
c++;
} else if (ch == 'H') {
h++;
}
}
int count = m * a * r + m * a * c + m * a * h
+ m * r * c + m * r * h + m * c * h
+ a * r * c + +a * r * h + a * c * h
+ r * c * h;
System.out.println(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 | use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;
fn main() {
let n: i64 = read();
let mut vec: Vec<String> = (0..n).map(|_| read()).collect();
let mut map: HashMap<char, i64> = HashMap::new();
map.insert('M', 0);
map.insert('A', 0);
map.insert('R', 0);
map.insert('C', 0);
map.insert('H', 0);
let march_vec = vec!['M', 'A', 'R', 'C', 'H'];
for s in vec.iter() {
let char_vec: Vec<char> = s.chars().collect();
let first_letter = char_vec[0];
if march_vec.contains(&first_letter) {
let count = map.get(&first_letter).unwrap();
map.insert(first_letter, count+1);
}
}
let mut count = 0;
for i in 0..i64::pow(2, march_vec.len() as u32) {
let mut each_vec: Vec<char> = Vec::new();
for j in 0..march_vec.len() {
if (1 & i >> j) == 1 {
each_vec.push(march_vec[j].clone());
}
}
let mut each_count = 1;
if each_vec.len() == 3 {
for s in each_vec.iter() {
let val = map.get(s).unwrap().clone();
each_count *= val;
}
count+=each_count;
}
}
println!("{:?}", count);
}
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("failed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}
// ๆๅคงๅ
ฌ็ดๆฐ
fn gcd(a: i32, b: i32) -> i32 {
match b {
0 => a,
_ => gcd(b, a % b)
}
}
// ๆๅฐๅ
ฌๅๆฐ
fn lcm(a: i32, b: i32) -> i32 {
a * b / gcd(a, b)
}
// ้ไน
fn kaijou(n: i32)->i32 {
if n == 1 {
return n;
}
return n * kaijou(n-1);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int freq[5];
for (int i = 0; i < 5; i++) {
freq[i] = 0;
}
cin >> N;
unsigned long long ans = 0;
for (int i = 0; i < N; i++) {
string name;
cin >> name;
if (name[0] == 'M')
freq[0]++;
else if (name[0] == 'A')
freq[1]++;
else if (name[0] == 'R')
freq[2]++;
else if (name[0] == 'C')
freq[3]++;
else if (name[0] == 'H')
freq[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 += freq[i] * freq[j] * freq[k];
}
}
}
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string s[100000];
int main() {
int n;
int ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int nm[5] = {0};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
nm[0]++;
} else if (s[i][0] == 'A') {
nm[1]++;
} else if (s[i][0] == 'R') {
nm[2]++;
} else if (s[i][0] == 'C') {
nm[3]++;
} else if (s[i][0] == 'H') {
nm[4]++;
}
}
ans += nm[0] * nm[1] * nm[2];
ans += nm[0] * nm[1] * nm[3];
ans += nm[0] * nm[1] * nm[4];
ans += nm[0] * nm[2] * nm[3];
ans += nm[0] * nm[2] * nm[4];
ans += nm[0] * nm[3] * nm[4];
ans += nm[1] * nm[2] * nm[3];
ans += nm[1] * nm[2] * nm[4];
ans += nm[1] * nm[3] * nm[4];
ans += nm[2] * nm[3] * nm[4];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int INFL = 1ll << 60;
long long int INF = 1 << 30;
int main() {
int n;
cin >> n;
vector<int> v(5);
string march = "MARCH";
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if ((find(march.begin(), march.end(), s[0]) != march.end())) {
v[find(march.begin(), march.end(), s[0]) - march.begin()]++;
}
}
long long int ans = 0;
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 5; k++) ans += v[i] * v[j] * v[k];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
void solve() {
int N;
cin >> N;
map<char, int> initial;
for (int i = 0; i < (int)(N); ++i) {
string name;
cin >> name;
++initial[name[0]];
}
string MARCH = "MARCH";
ll ans = 0;
for (int i = 0; i < 3; ++i) {
char x = MARCH[i];
for (int j = i + 1; j < 4; ++j) {
char y = MARCH[j];
for (int k = j + 1; k < 5; ++k) {
char z = MARCH[k];
ans += initial[x] * initial[y] * initial[z];
}
}
}
cout << ans << endl;
return;
}
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 | java | import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt();
Map<Character, Long> hm = new HashMap<>();
while (n-- > 0) {
char c = in.nextLine().charAt(0);
hm.put(c, hm.getOrDefault(c, (long) 0) + 1);
}
List<Long> num = new ArrayList<>();
for (char c : hm.keySet()) {
if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
num.add(hm.get(c));
}
}
int res = 0;
for (int i = 0; i < num.size(); i++) {
for (int j = i + 1; j < num.size(); j++) {
for (int k = j + 1; k < num.size(); k++) {
res += num.get(i) * num.get(j) * num.get(k);
}
}
}
out.println(res);
out.close();
//INT OVERFLOW -> USE LONG
//ARR OUT OF BOUNDS
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public double[] nextDoubleArray(int n) {
double[] arr = new double[n];
for (int i = 0; i < n; i++) {
arr[i] = nextDouble();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public char[] nextCharArray(int n) {
char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
return arr;
}
public String[] nextStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = next();
}
return arr;
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string tmp;
int num[5] = {};
int n;
char tmpm[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int x = 0; x < 5; x++) {
if (tmp[0] == tmpm[x]) {
num[x]++;
break;
}
}
}
unsigned 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 += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
void swap(long long *a, long long *b) {
long long c;
c = *b;
*b = *a;
*a = c;
}
long long max2(long long a, long long b) { return a >= b ? a : b; }
long long min2(long long a, long long b) { return a >= b ? b : a; }
long long ABS(long long a) { return a >= 0 ? a : (-a); }
typedef struct {
long long aa;
long long bb;
} frequent;
int compare(const void *a, const void *b) {
return *(long long *)a - *(long long *)b;
}
int main(void) {
long long n, i, ans = 0;
scanf("%lld", &n);
char s[12], ini[n];
for (i = 0; i < n; i++) {
scanf("%s", s);
ini[i] = s[0];
}
long long letter[] = {0, 0, 0, 0, 0};
for (i = 0; i < n; i++) {
if (ini[i] == 'M') letter[0]++;
if (ini[i] == 'A') letter[1]++;
if (ini[i] == 'R') letter[2]++;
if (ini[i] == 'C') letter[3]++;
if (ini[i] == 'H') letter[4]++;
}
for (i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
for (long long k = j + 1; k < n; k++) {
ans += letter[i] * letter[j] * letter[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(void) {
int n;
scanf("%d\n", &n);
int a[5] = {0};
for (int i = 0; i < n; ++i) {
char c;
scanf("%c", &c);
if (c == 'M') {
a[0]++;
} else if (c == 'A') {
a[1]++;
} else if (c == 'R') {
a[2]++;
} else if (c == 'C') {
a[3]++;
} else if (c == 'H') {
a[4]++;
}
while (c != 10) {
scanf("%c", &c);
}
}
int s = 0;
s += a[0] * a[1] * a[2];
s += a[0] * a[1] * a[3];
s += a[0] * a[1] * a[4];
s += a[0] * a[2] * a[3];
s += a[0] * a[2] * a[4];
s += a[0] * a[3] * a[4];
s += a[1] * a[2] * a[3];
s += a[1] * a[2] * a[4];
s += a[1] * a[3] * a[4];
s += a[2] * a[3] * a[4];
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() {
int n;
cin >> n;
string s[n];
int a[5] = {};
string march = "MARCH";
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 5; j++)
if (s[i].at(0) == march[j]) a[j]++;
}
long long int ans = 0;
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++)
for (int k = j + 1; k < 5; k++) ans += a[i] * a[j] * a[k];
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
str = input()
if str[0] in march:
march[str[0]] += 1
for i in list(march):
if march[i] == 0:
march.pop(i)
c = 0
if len(march) == 3:
tmpc = 1
for chr in march:
tmpc *= march[chr]
c += tmpc
elif len(march) == 4:
for i in march:
tmpm = march.copy()
tmpm.pop(i)
tmpc = 1
for chr in tmpm:
tmpc *= tmpm[chr]
c += tmpc
elif len(march) == 5:
for i in march:
tmpm1 = march.copy()
tmpm1.pop(i)
for j in tmpm1:
tmpm2 = tmpm1.copy()
tmpm2.pop(j)
tmpc = 1
for chr in tmpm:
tmpc *= tmpm[chr]
c += tmpc
print(c) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Linq;
using System.Collections.Generic;
public class c
{
public static void Main()
{
int n=int.Parse(Console.ReadLine());
int[] march =new int[5];
for(int i=0;i<n;i++)
{
string s=Console.ReadLine();
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 ans=(march[0]*march[1]*march[2]+march[0]*march[1]*march[3]+march[0]*march[1]*march[4]);
ans+=(march[0]*march[2]*march[3]+march[0]*march[2]*march[4]+march[0]*march[3]*march[4]);
ans+=(march[1]*march[2]*march[3]+march[1]*march[2]*march[4]+march[1]*march[3]*march[4]+march[0]*march[3]*march[4]);
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>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using namespace std;
long long combination(const map<char, int> &map) {
long long ans = 1;
for (long long i = map.size(); i >= map.size() - 3; --i) ans *= i;
return ans / 6ll;
}
int main() {
int N;
cin >> N;
vector<int> count(5, 0);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M')
++count[0];
else if (s[0] == 'A')
++count[1];
else if (s[0] == 'R')
++count[2];
else if (s[0] == 'C')
++count[3];
else if (s[0] == 'H')
++count[4];
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = (i + 1); j < 4; j++) {
for (int k = (j + 1); k < 5; k++) {
ans += count[i] * count[j] * count[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, M = 0, A = 0, R = 0, C = 0, H = 0, result = 0;
int march[5];
string s;
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++;
}
march[0] = M;
march[1] = A;
march[2] = R;
march[3] = C;
march[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++) {
int tmp = march[i] * march[j] * march[k];
result += tmp;
}
}
}
cout << result << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long f(int a, int b, int c) { return a * b * c; }
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S.at(i);
vector<vector<string>> v(5);
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M') {
v.at(0).push_back(S.at(i));
}
if (S.at(i).at(0) == 'A') {
v.at(1).push_back(S.at(i));
}
if (S.at(i).at(0) == 'R') {
v.at(2).push_back(S.at(i));
}
if (S.at(i).at(0) == 'C') {
v.at(3).push_back(S.at(i));
}
if (S.at(i).at(0) == 'H') {
v.at(4).push_back(S.at(i));
}
}
long long sum = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
sum += f(v.at(i).size(), v.at(j).size(), v.at(k).size());
}
}
}
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 = 1000000000;
void chmin(int &a, int b) {
if (a > b) a = b;
}
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) cin >> S[i];
map<char, int> ma;
char list[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) ma[list[i]] = 0;
for (int i = 0; i < N; i++) ma[S[i].front()]++;
for (int i = 0; i < 5; i++) {
cout << list[i] << ": " << ma[list[i]] << endl;
}
long long res = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
res += ma[list[i]] * ma[list[j]] * ma[list[k]];
}
}
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int a[5];
int main() {
for (int i = 0; i < 5; i++) a[i] = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char tmp[15];
cin >> tmp;
for (int j = 0; j < 5; j++) {
if (tmp[0] == c[j]) {
a[j]++;
break;
}
}
}
int out = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
out += a[i] * a[j] * a[k];
}
}
}
cout << out << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
s = ["" for _ in range(n)]
for i in range(n):
s[i] = str(input())
march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]
for i in range(n):
if s[i][0] in march:
march_num[march.index(s[i][0])] += 1
ans = 0
for i in range(len(s)-2):
for j in range(i+1,len(s)-1):
for k in range(j+1,len(s)):
ans += (march_num[i]*march_num[j]*march_num[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 ll = long long;
int main() {
int n;
cin >> n;
int m[5] = {};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
m[0]++;
} else if (s[0] == 'A') {
m[1]++;
} else if (s[0] == 'R') {
m[2]++;
} else if (s[0] == 'C') {
m[3]++;
} else if (s[0] == 'H') {
m[4]++;
}
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
cnt++;
}
}
if (cnt < 3) {
cout << 0 << '\n';
return 0;
}
int ans = 1;
int tmp = 0;
if (cnt == 3) {
tmp = 1;
} else if (cnt == 4) {
tmp = 4;
vector<int> v;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
v.push_back(m[i]);
}
}
ans = v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[0] * v[2] * v[3] +
v[1] * v[2] * v[3];
cout << ans << endl;
return 0;
} else if (cnt == 5) {
tmp = 10;
vector<int> v;
for (int i = 0; i < 5; i++) {
if (m[i] > 0) {
v.push_back(m[i]);
}
}
ans = v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[2] * v[3] +
v[1] * v[2] * v[3] + v[0] * v[1] * v[4] + v[0] * v[2] * v[4] +
v[0] * v[3] * v[4] + v[1] * v[2] * v[4] + v[1] * v[3] * v[4] +
v[2] * v[3] * v[4];
cout << ans << endl;
return 0;
}
for (int i = 0; i < 5; i++) {
if (m[i] == 0) {
continue;
} else {
ans *= m[i];
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int m, a, r, c, h;
int main() {
int n;
cin >> n;
for (int i = 1; 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 s = m * a * h + m * a * c + m * a * r + m * r * c + m * r * h +
m * c * h + a * r * c + a * c * h + r * c * h;
cout << s;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 zen = 0;
int gou = 0, ans = 0, kai = 1, koi = 1;
scanf("%d", &n);
char s[11];
for (i = 0; i < n; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
count[0]++;
zen++;
break;
case 'A':
count[1]++;
zen++;
break;
case 'R':
count[2]++;
zen++;
break;
case 'C':
count[3]++;
zen++;
break;
case 'H':
count[4]++;
zen++;
break;
}
}
for (i = 0; i < 5; i++) {
if (count[i] > 0) {
gou++;
}
}
for (i = zen - 2; i <= zen; ++i) {
kai = kai * i;
}
ans = kai / 6;
for (i = 0; i < 5; i++) {
koi = 1;
if (count[i] == 2) {
ans = ans - (zen - count[i]);
} else if (count[i] > 2) {
for (j = count[i] - 1; j <= count[i]; ++j) {
koi = koi * i;
}
ans = ans - (koi / 6);
ans = ans - (koi / 2) * (zen - count[i]);
}
}
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 | python3 | n = int(input())
ans = [0]*5
x = 1
for i in range(n):
s = input()
if s[0] == "M":
ans[0] = ans[0] + 1
if s[0] == "A":
ans[1] = ans[1] + 1
if s[0] == "R":
ans[2] = ans[2] + 1
if s[0] == "C":
ans[3] = ans[3] + 1
if s[0] == "H":
ans[4] = ans[4] + 1
if ans.count(0) == 5:
print(0)
else:
for i in ans:
if i != 0:
x *= i
print(x)
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s, s + n);
int m, a, r, c, h;
m = lower_bound(s, s + n, "N") - lower_bound(s, s + n, "M");
a = lower_bound(s, s + n, "B") - lower_bound(s, s + n, "A");
r = lower_bound(s, s + n, "S") - lower_bound(s, s + n, "R");
c = lower_bound(s, s + n, "D") - lower_bound(s, s + n, "C");
h = lower_bound(s, s + n, "I") - lower_bound(s, s + n, "H");
long long ans;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + r * c * h;
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mei = (long long)1e9 + 7;
int main() {
long long a, b, c, d, e, k;
k = 0;
string s;
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
long long n;
for (long long i = 0; i < (long long)(n); i++) {
cin >> s;
if (s[0] == 'M') a++;
if (s[0] == 'A') b++;
if (s[0] == 'R') c++;
if (s[0] == 'C') d++;
if (s[0] == 'H') e++;
}
k += a * b * c;
k += a * b * d;
k += a * b * e;
k += a * c * d;
k += a * c * e;
k += a * d * e;
k += b * c * d;
k += b * c * e;
k += b * d * e;
k += c * d * e;
cout << k;
cout << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string tmp;
int num[5] = {};
int n;
char tmpm[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int x = 0; x < 5; x++) {
if (tmp[0] == tmpm[x]) {
num[x]++;
break;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += num[i] * num[j] * num[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;
vector<char> s;
char h[5] = {'A', 'C', 'H', 'M', 'R'};
long long a, b, c, d, e, ans = 0;
int main() {
cin >> a;
string q;
char rre;
for (int i = 0; i < a; i++) {
cin >> q;
rre = q[0];
s.push_back(rre);
}
sort(s.begin(), s.end());
for (int i = 0; i < a - 2; i++) {
for (int j = i + 1; j < a - 1; j++) {
for (int y = j + 1; y < a; y++) {
if (int(s[i] - '0') < int(s[j] - '0') &&
int(s[j] - '0') < int(s[y] - '0'))
ans++;
}
}
}
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;
string z;
int M, A, R, C, H;
int main() {
while (cin >> z) {
if (z[0] == 'M') M++;
if (z[0] == 'A') A++;
if (z[0] == 'R') R++;
if (z[0] == 'C') C++;
if (z[0] == 'H') H++;
}
long long int a = C * H * (M + C + H), b = C * H * (M + A + R),
c = (M * (C + H) * (A + R));
cout << a + b + c << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
static long Examine(long countM,long countA,long countR,long countC,long countH) {
long count = 0;
count += countM * countA * countR;
count += countM * countA * countC;
count += countM * countA * countH;
count += countM * countR * countC;
count += countM * countR * countH;
count += countM * countR * countH;
count += countA * countR * countC;
count += countA * countR * countH;
count += countA * countC * countH;
count += countR * countC * countH;
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String[] names = new String[N];
long countM = 0;
long countA = 0;
long countR = 0;
long countC = 0;
long countH = 0;
String[] I = new String[N];
for(int i = 0;i < N;i++) {
names[i] = sc.next();
I[i] = names[i].substring(0,1);
}
for(int k = 0;k < N;k++) {
if(I[k].equals("M")) countM++;
else if(I[k].equals("A")) countA++;
else if(I[k].equals("R")) countR++;
else if(I[k].equals("C")) countC++;
else if(I[k].equals("H")) countH++;
}
System.out.println(Examine(countM,countA,countR,countC,countH));
sc.close();
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 sys import stdin
from itertools import combinations
n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]
lin = []
for i in range(n):
if li[i][0] in "MARCH":
lin.append(li[i][0])
liv = list(combinations(lin, 3))
point = 0
for i in liv:
if i[0] != i[1] and i[0] != i[2] and i[2] != i[1]:
point += 1
print(point) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y) {
if (y == 0) return x;
return gcd(y, x % y);
}
template <typename T>
T lcm(T x, T y) {
if (x == 0 || y == 0) return 0;
return x / gcd(x, y) * y;
}
int main() {
int N;
cin >> N;
map<char, int> mp;
const string march = "MARCH";
for (int i = 0; i < N; i++) {
string S;
cin >> S;
mp[S[0]]++;
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += mp[march[i]] * mp[march[j]] * mp[march[k]];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> cnt(6);
map<char, int> mp;
mp['M'] = 1;
mp['A'] = 2;
mp['R'] = 3;
mp['C'] = 4;
mp['H'] = 5;
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
if (mp[s[0]]) ++cnt[mp[s[0]]];
}
int ans = 0;
for (int i = 1; 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];
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;
long long mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n;
cin >> n;
string s[n];
long long res[5] = {};
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') res[0]++;
if (s[i][0] == 'A') res[1]++;
if (s[i][0] == 'R') res[2]++;
if (s[i][0] == 'C') res[3]++;
if (s[i][0] == 'H') res[4]++;
}
long long rec = 0, ans = 1;
for (int i = 0; i < 5; i++) {
if (res[i]) {
rec++;
ans *= res[i];
}
}
if (rec <= 2) {
cout << 0 << endl;
return 0;
}
if (rec == 3) {
cout << ans << endl;
return 0;
}
if (rec == 4) {
long long m, cc = 1;
for (int i = 0; i < 5; i++) {
if (res[i] == 0)
m = i;
else
cc *= res[i];
}
long long cnt = 0;
for (int i = 0; i < 5; i++) {
if (i == m) continue;
cnt += cc / res[i];
}
cout << cnt << endl;
return 0;
}
if (rec == 5) {
long long m, cc = 1, cnt = 0;
for (int i = 0; i < 5; i++) cc *= res[i];
for (int i = 0; i < 5; i++) cnt += cc / res[i];
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 | java | import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
int list[] = {0,0,0,0,0};
for(int x=1;x<=n;x++) {
String first = sc.next();
String top = first.substring(0,1);
if(top.equals("M")) {
list[0] += 1;
}
if(top.equals("A")) {
list[1] += 1;
}
if(top.equals("R")) {
list[2] += 1;
}
if(top.equals("C")) {
list[3] += 1;
}
if(top.equals("H")) {
list[4] += 1;
}
}
System.out.println(list[0]*list[1]*list[2]+list[0]*list[1]*list[3]+list[0]*list[1]*list[4]+list[0]*list[2]*list[3]+list[0]*list[2]*list[4]+list[0]*list[3]*list[4]+list[1]*list[2]*list[3]+list[1]*list[2]*list[4]+list[1]*list[3]*list[4]+list[2]*list[3]*list[4]);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string s = "MARCH";
int c[5] = {0};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string t;
cin >> t;
for (int 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 | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int Len(int n) {
int s = 0;
while (n != 0) s++, n /= 10;
return s;
}
int Sint(int n) {
int m = 0, s = 0, a = n;
while (a != 0) s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int Svec(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++) n += v[i];
return n;
}
int GCD(int a, int b) {
int r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
int LCM(int a, int b) {
int c = a, d = b, r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
int Factorial(int n) {
int m = 1;
while (n >= 1) m *= n, n--;
return m;
}
int main() {
int n;
cin >> n;
vector<int> c(5);
for (int i = 0; i < (5); i++) c[i] = 0;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
c[0]++;
} else if (s[0] == 'A') {
c[1]++;
} else if (s[0] == 'R') {
c[2]++;
} else if (s[0] == 'C') {
c[3]++;
} else if (s[0] == 'H') {
c[4]++;
}
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import numpy as np
N = int(input())
S = np.empty(5, dtype=str)
for i in range(N):
S[i] = input()
S_M = np.array([S[i] for i in range(N) if S[i][0] == 'M'])
S_A = np.array([S[i] for i in range(N) if S[i][0] == 'A'])
S_R = np.array([S[i] for i in range(N) if S[i][0] == 'R'])
S_C = np.array([S[i] for i in range(N) if S[i][0] == 'C'])
S_H = np.array([S[i] for i in range(N) if S[i][0] == 'H'])
souwa = 0
kahi = np.array([0, 0, 0, 0, 0])
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)
kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
print(0)
else:
for i in range(len(kahi_not0)-2):
for j in range(i+1, len(kahi_not0)-1):
for k in range(j+1, len(kahi_not0)):
souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]
print(souwa) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int MOD = 1000000007;
int main(int argc, char const* argv[]) {
long long n;
cin >> n;
map<char, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or
s[0] == 'H') {
mp[s[0]]++;
}
}
long long ans = 0;
vector<long long> cmb{0, 0, 1, 1, 1};
vector<long long> sel{'M', 'A', 'R', 'C', 'H'};
do {
long long tmp = 1;
for (int i = 0; i < 5; i++) {
if (cmb[i]) {
tmp *= mp[sel[i]];
}
}
ans += tmp;
} while (next_permutation(cmb.begin(), cmb.end()));
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(void) {
int n, i, j, cnt[5] = {0}, tmp, sum = 0, cnt1;
string s;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M')
cnt[0]++;
else if (s[0] == 'A')
cnt[1]++;
else if (s[0] == 'R')
cnt[2]++;
else if (s[0] == 'C')
cnt[3]++;
else if (s[0] == 'H')
cnt[4]++;
}
for (i = 0; i < 1 << 5; i++) {
tmp = 1;
cnt1 = 0;
for (j = 0; j < 5; j++) {
if (1 & i >> j) {
tmp *= cnt[j];
cnt1++;
}
}
if (cnt1 == 3) sum += tmp;
}
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(void) {
long n;
cin >> n;
long m = 0, a = 0, r = 0, c = 0, h = 0;
vector<long> v(5);
for (long i = 0; i < n; i++) {
string name;
cin >> name;
switch (name[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
long sum = 0;
sum += m * a * r;
sum += m * a * c;
sum += m * a * h;
sum += m * r * c;
sum += m * r * h;
sum += m * c * h;
sum += a * r * c;
sum += a * r * h;
sum += a * r * h;
sum += r * c * h;
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;
int a[5] = {0};
char tmp[50];
int count = 0;
for (int i = 0; i < n; i++) {
cin >> tmp;
if (tmp[0] == 'M') a[0]++;
if (tmp[0] == 'A') a[1]++;
if (tmp[0] == 'R') a[2]++;
if (tmp[0] == 'C') a[3]++;
if (tmp[0] == 'H') a[4]++;
}
for (int i = 0; i < 3; i++) {
for (int j = 1; j <= 3 && ((i + j) < 5); j++) {
for (int k = 1; (k <= 3) && ((i + j + k) < 5); k++) {
count += a[i] * a[i + j] * a[i + j + k];
}
}
}
printf("%d\n", count);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
map<char, int> mp;
for (int i = 0; i < 26; ++i) mp['A' + i] = 0;
string S;
for (int i = 0; i < N; ++i) {
cin >> S;
++mp[S[0]];
}
long ans = 0, plus;
map<int, string> se;
se[0] = "MAR";
se[1] = "MAC";
se[2] = "MAH";
se[3] = "MRC";
se[4] = "MRH";
se[5] = "MCH";
se[6] = "ARC";
se[7] = "ARH";
se[8] = "ACH";
se[9] = "RCH";
for (int i = 0; i < 10; ++i) {
plus = mp[se[i][0]] * mp[se[i][1]] * mp[se[i][2]];
ans += plus;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
i=0
L=[0,0,0,0,0]
while i < N:
name=input()
if name[0] == 'M':
L[0] += 1
elif name[0] == 'A':
L[1] += 1
elif name[0] == 'R':
L[2] += 1
elif name[0] == 'C':
L[3] += 1
elif name[0] == 'H':
L[4] += 1
i += 1
l=L[0]+L[1]+L[2]+L[3]+L[4]
if l < 3:
print('0')
else:
q = 0
Q=[]
j = 0
while j < 5:
if L[j] != 0:
q += 1
Q.append(L[j])
j += 1
if q < 3:
p = 0
elif q == 3:
p = Q[0]*Q[1]*Q[2]
elif q == 4:
p = Q[0]*Q[1]*Q[2] + Q[0]*Q[2]*Q[3] + Q[0]*Q[1]*Q[3] + Q[1]*Q[2]*Q[3]
else:
p = Q[0]*Q[1]*Q[2]*Q[3] + Q[0]*Q[1]*Q[2]*Q[4] + Q[0]*Q[1]*Q[3]*Q[4] + Q[0]*Q[2]*Q[3]*Q[4] + Q[4]*Q[1]*Q[2]*Q[3]
print(p) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, i, M, A, R, C, H;
long ans;
string Name;
M = 0;
A = 0;
R = 0;
C = 0;
H = 0;
cin >> N;
for (i = 0; i < N; i++) {
cin >> Name;
if (Name[0] == 'M') {
M++;
} else if (Name[0] == 'A') {
A++;
} else if (Name[0] == 'R') {
R++;
} else if (Name[0] == 'C') {
C++;
} else if (Name[0] == 'H') {
H++;
}
}
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
cout << ans << endl;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.