Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program
{
internal static void Main(string[] args)
{
var N = int.Parse(ReadLine());
var S = new Dictionary<String, int>() {
{"M", 0},
{"A", 0},
{"R", 0},
{"C", 0},
{"H", 0}
};
for (int i = 0; i < N; i++) {
var str = ReadLine().Substring(0, 1);
switch (str) {
case "M":
case "A":
case "R":
case "C":
case "H":
if (S.ContainsKey(str)) {
S[str]++;
}
break;
}
}
string[] p = { "M", "M", "M", "M", "M", "M", "A", "A", "A", "R" };
string[] q = { "A", "A", "A", "R", "R", "C", "R", "R", "C", "C" };
string[] r = { "R", "C", "H", "C", "H", "H", "C", "H", "H", "H" };
int ans = 0;
for (int i = 0; i < 10; i++) {
ans += S[p[i]] * S[q[i]] * S[r[i]];
}
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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int many[5] = {0};
int hoge, hogera;
char s[16] = {0};
long long int math = 0;
scanf("%d", &hoge);
for (hogera = 0; hogera < hoge; hogera++) {
scanf("%s", &s);
switch (s[0]) {
case 'M':
many[0]++;
break;
case 'A':
many[1]++;
break;
case 'R':
many[2]++;
break;
case 'C':
many[3]++;
break;
case 'H':
many[4]++;
break;
}
}
math += (many[0] * many[1] * many[2]);
math += (many[0] * many[1] * many[3]);
math += (many[0] * many[1] * many[4]);
math += (many[0] * many[2] * many[3]);
math += (many[0] * many[2] * many[4]);
math += (many[0] * many[3] * many[4]);
math += (many[1] * many[2] * many[3]);
math += (many[1] * many[2] * many[4]);
math += (many[1] * many[3] * many[4]);
math += (many[2] * many[3] * many[4]);
printf("%d", math);
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>
namespace {
const int STRING_NUM = 5;
const char char_vec[STRING_NUM] = {'M', 'A', 'R', 'C', 'H'};
} // namespace
int main() {
int n;
std::cin >> n;
std::vector<int> str_count(STRING_NUM, 0);
for (auto i = 0; i < n; ++i) {
std::string tmp;
std::cin >> tmp;
for (auto j = 0; j < STRING_NUM; ++j) {
if (tmp[0] == char_vec[j]) {
++(str_count[j]);
break;
}
}
}
uint64_t result = 0;
for (auto i = 0; i < STRING_NUM - 2; ++i) {
for (auto j = i + 1; j < STRING_NUM - 1; ++j) {
for (auto k = j + 1; k < STRING_NUM; ++k) {
result += str_count[i] * str_count[j] * str_count[k];
}
}
}
std::cout << result << std::endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char name[11];
int march[5] = {0};
for (int i = 0; i < n; i++) {
cin >> name;
if (name[0] == 'M')
march[0]++;
else if (name[0] == 'A')
march[1]++;
else if (name[0] == 'R')
march[2]++;
else if (name[0] == 'C')
march[3]++;
else if (name[0] == 'H')
march[4]++;
}
unsigned long long combination = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
combination += march[i] * march[j] * march[k];
}
}
}
cout << combination << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC089C
{
class Program
{
static void Main(string[] args)
{
var n = int.Parse(Console.ReadLine());
var count = new Dictionary<char, int>();
count.Add('M', 0);
count.Add('A', 0);
count.Add('R', 0);
count.Add('C', 0);
count.Add('H', 0);
foreach (var i in Enumerable.Range(0, n))
{
var currentName = Console.ReadLine();
var initialChar = currentName.First();
if (initialChar == 'M' ||
initialChar == 'A' ||
initialChar == 'R' ||
initialChar == 'C' ||
initialChar == 'H')
{
count[initialChar]++;
}
}
var pattern = new List<string>();
pattern.Add("MAR");
pattern.Add("MAC");
pattern.Add("MAH");
pattern.Add("MRC");
pattern.Add("MRH");
pattern.Add("MCH");
pattern.Add("ARC");
pattern.Add("ARH");
pattern.Add("ACH");
pattern.Add("RCH");
var result = 0L;
foreach( var currentPattern in pattern)
{
result += count[currentPattern[0]] * count[currentPattern[1]] * count[currentPattern[2]];
}
Console.WriteLine(result);
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int march[5] = {};
for (int i = (int)0; i < (int)n; ++i) {
string s;
cin >> s;
if (s[0] == 'M')
march[0]++;
else if (s[0] == 'A')
march[1]++;
else if (s[0] == 'R')
march[2]++;
else if (s[0] == 'C')
march[3]++;
else if (s[0] == 'H')
march[4]++;
}
long long ans = 0;
for (int i = (int)0; i < (int)5; ++i) {
for (int j = (int)i + 1; j < (int)5; ++j) {
for (int k = (int)j + 1; k < (int)5; ++k) {
long long tmp = march[i] * march[j] * march[k];
if (tmp) ans += tmp;
}
}
}
cout << ans << '\n';
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, rs, f[5];
string s;
int main() {
cin >> n;
memset(f, 0, sizeof(f));
while (n-- > 0) {
cin >> s;
if (s[0] == 'M')
f[0]++;
else if (s[0] == 'A')
f[1]++;
else if (s[0] == 'R')
f[2]++;
else if (s[0] == 'C')
f[3]++;
else if (s[0] == 'H')
f[4]++;
}
int ly = 0;
rs = 0;
for (int i = 0; i < 5; i++)
if (f[i] > 0) ly++;
if (ly >= 3) {
for (int i = 0; i < 5; i++) {
if (f[i] == 0) continue;
for (int j = i; j < 5; j++) {
if (j == i || f[j] == 0) continue;
for (int t = j; t < 5; t++) {
if (i == t || t == j || f[t] == 0) continue;
rs += f[i] * f[j] * f[t];
}
}
}
}
cout << rs << 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;
string yn(bool x) { return x ? "Yes" : "No"; }
int main() {
int n;
cin >> n;
string name[n];
for (int i = 0; i < n; i++) cin >> name[i];
int a[5] = {0, 0, 0, 0, 0};
string c = "MARCH";
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
if (name[i][0] == c[j]) a[j]++;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <stdio.h>
int main(){
int n;
scanf("%d¥n",n);
int m=0;
int r=0;
int c=0;
int a=0;
int h=0;
for(int i = 0;i<n;i++){
char str[64];
scanf("%s¥n",&str);
if(str[0] == "M"){m++;}
if(str[0] == "C"){c++;}
if(str[0] == "A"){a++;}
if(str[0] == "R"){r++;}
if(str[0] == "H"){h++;}
}
unsigned long ans;
ans = (m+c+a+r+h)*(m+c+a+r+h)*(m+c+a+r+h);
ans -= (m+c+a+r+h)*3*a*a-2*a*a;
ans -= (m+c+a+r+h)*3*m*m-2*m*m;
ans -= (m+c+a+r+h)*3*h*h-2*h*h;
ans -= (m+c+a+r+h)*3*r*r-2*r*r;
ans -= (m+c+a+r+h)*3*c*c-2*c*c;
printf();
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;
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
int cnt[5];
for (int i = (0); i < (5); ++i) cnt[i] = 0;
string S;
char march[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = (0); i < (N); ++i) {
cin >> S;
for (int i = (0); i < (5); ++i)
if (S[0] == march[i]) cnt[i]++;
}
long long int ans = 0;
ans += cnt[0] * cnt[1] * cnt[2];
ans += cnt[0] * cnt[1] * cnt[3];
ans += cnt[0] * cnt[1] * cnt[4];
ans += cnt[0] * cnt[2] * cnt[3];
ans += cnt[0] * cnt[2] * cnt[4];
ans += cnt[0] * cnt[3] * cnt[4];
ans += cnt[1] * cnt[2] * cnt[3];
ans += cnt[1] * cnt[2] * 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;
void Show(vector<bool>& Ps) {
for (int i = 0; i < Ps.size(); i++) {
if (Ps[i]) {
cout << "T" << endl;
} else {
cout << "F" << endl;
}
}
}
void Show(vector<vector<int>>& Ns) {
for (int i = 0; i < Ns.size(); i++) {
for (int j = 0; j < Ns[i].size(); j++) {
cout << Ns[i][j] << " ";
}
cout << endl;
}
}
int main() {
array<int, 5> MARCH;
for (int i = 0; i < 5; i++) {
MARCH[i] = 0;
}
int N;
long long Count = 0;
cin >> N;
string S;
for (int i = 0; i < N; i++) {
cin >> S;
if (S[0] == 'M') MARCH[0]++;
if (S[0] == 'A') MARCH[1]++;
if (S[0] == 'R') MARCH[2]++;
if (S[0] == 'C') MARCH[3]++;
if (S[0] == 'H') MARCH[4]++;
}
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
int C = 1;
for (int k = 0; k < 5; k++) {
if (k != i && k != j) {
C *= MARCH[k];
}
}
Count += C;
}
}
cout << Count << 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 | a = gets.to_i.times.map{gets[0]}.reduce({'m':0,'a':0,'r':0,'c':0,'h':0}) do |e, c|
e[c] += 1 if e[c]
e
end.map{|e|e[1]}
res = 0
5.times do |i|
(i...5).each do |j|
(j...5).each do |k|
res += a[i]*a[j]*a[k]
end
end
end
puts res |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long nCr(int n, int r) {
long long ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int main() {
int n;
cin >> n;
string str;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < (n); ++i) {
cin >> str;
if (str[0] == 'M') {
m++;
}
if (str[0] == 'A') {
a++;
}
if (str[0] == 'R') {
r++;
}
if (str[0] == 'C') {
c++;
}
if (str[0] == 'H') {
h++;
}
}
long long ans = 0;
ans += m * a * r;
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;
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 collections import Counter
n = int(input())
s = [input() for _ in range(n)]
name_count = [0 for _ in range(5)]
for i in s:
if i[0] == "M":
name_count[0] += 1
elif i[0] == "A":
name_count[1] += 1
elif i[0] == "R":
name_count[2] += 1
elif i[0] == "C":
name_count[3] += 1
elif i[0] == "H":
name_count[4] += 1
result = 0
for i in range(5):
result += name_count[i]*name_count[(i+1)%5]*name_count[(i+2)%5]
print(result) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
long[] record = new long[26];
for(int i=0;i<N;i++){
String cur = sc.next();
char initial = cur.charAt(0);
record[initial-'A'] += 1;
}
long[] med = new long[5];
med[0] = record[0];
med[1] = record['C'-'A'];
med[2] = record['H'-'A'];
med[3] = record['M'-'A'];
med[4] = record['R'-'A'];
Arrays.sort(med);
long ans = 0;
ans += record[0]*record[1]*record[2];
ans += record[0]*record[1]*record[3];
ans += record[0]*record[1]*record[4];
ans += record[0]*record[2]*record[3];
ans += record[0]*record[2]*record[4];
ans += record[0]*record[3]*record[4];
ans += record[1]*record[2]*record[3];
ans += record[1]*record[2]*record[4];
ans += record[1]*record[3]*record[4];
ans += record[2]*record[3]*record[4];
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string first = "MARCH";
vector<int> name(5);
for (int i = 0; i < 5; i++) {
name[i] = 0;
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == first[j]) {
name[j]++;
}
}
}
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 += name[i] * name[j] * name[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> count(5, 0);
for (int(i) = 0; (i) < (n); (i)++) {
string s;
cin >> s;
if (s.at(0) == 'M')
count.at(0)++;
else if (s.at(0) == 'A')
count.at(1)++;
else if (s.at(0) == 'R')
count.at(2)++;
else if (s.at(0) == 'C')
count.at(3)++;
else if (s.at(0) == 'H')
count.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++) {
long long p = count.at(i) * count.at(j) * count.at(k);
ans += p;
}
}
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 1e18;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
ll ans = 0, n;
string s;
cin >> n;
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
m[0]++;
}
if (s[0] == 'A') {
m[1]++;
}
if (s[0] == 'R') {
m[2]++;
}
if (s[0] == 'C') {
m[3]++;
}
if (s[0] == 'H') {
m[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 += m[i] * m[j] * m[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | use std::io::{self, BufRead};
fn readline() -> String {
let mut line = String::new();
io::stdin().lock().read_line(&mut line).unwrap();
line.trim().to_string()
}
fn id(first: char) -> Option<usize> {
let str = "MARCH";
for (i, c) in str.chars().enumerate() {
if c == first {
return Some(i);
}
}
None
}
fn main() {
let n: i32 = readline().parse().unwrap();
let mut count: [i32; 5] = [0, 0, 0, 0, 0];
for i in 0..n {
let str = readline();
if let Some(j) = id(str.chars().next().unwrap()) {
count[j] = count[j] + 1;
}
}
let mut ans: i32 = 0;
for i in 0..5 {
for j in i+1..5 {
for k in j+1..5 {
ans += count[i] * count[j] * count[k];
}
}
}
println!("{}", ans);
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner
{
static char[] CH = new char[5] { 'M', 'A', 'R', 'C', 'H' };
static void Main()
{
int N = RInt();
var dic = new Dictionary<char, int>();
dic.Add('M', 0);
dic.Add('A', 0);
dic.Add('R', 0);
dic.Add('C', 0);
dic.Add('H', 0);
for (int i = 0; i < N; i++)
{
var r = RString()[0];
if (dic.ContainsKey(r))
{
dic[r]++;
}
}
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 += dic[CH[i]] * dic[CH[j]] * dic[CH[k]];
}
}
}
WriteLine(ans);
}
}
class Modular
{
private const int M = 1000000007;
private long value;
public Modular(long value = 0) { this.value = value; }
public static implicit operator Modular(long a)
{
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b)
=> a.value + b.value;
public static Modular operator -(Modular a, Modular b)
=> a.value - b.value;
public static Modular operator *(Modular a, Modular b)
=> a.value * b.value;
public static Modular Pow(Modular a, int n)
{
switch (n)
{
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b)
{
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
public static Modular Fac(int n) //階乗
{
for (int i = facs.Count; i <= n; ++i)
{
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Fac(int r, int n)
{
int temp = 1;
for (int i = r; i <= n; i++)
{
temp = (int)(Math.BigMul(temp, i) % M);
}
return temp;
}
public static Modular Ncr(int n, int r) //nCr
{
return (n < r) ? 0
: (n == r) ? 1
: (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r))
: Fac(n - r + 1, n) / Fac(r);
}
public static explicit operator int(Modular a)
{
return (int)a.value;
}
}
class Scanner
{
public static int RInt() => int.Parse(Console.ReadLine());
public static long RLong() => long.Parse(Console.ReadLine());
public static string RString() => Console.ReadLine();
public static double RDouble() => double.Parse(Console.ReadLine());
public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
public static string[] RStrings() => Console.ReadLine().Split();
//public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
public static T1 ReadStream<T1>()
{
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
return r1;
}
public static (T1, T2) ReadStream<T1, T2>()
{
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
return (r1, r2);
}
public static (T1, T2, T3) ReadStream<T1, T2, T3>()
{
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
return (r1, r2, r3);
}
public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
{
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[0], typeof(T3));
var r4 = (T4)Convert.ChangeType(r[0], typeof(T4));
return (r1, r2, r3, r4);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k;
int n;
int num[5] = {0};
int total = 0;
string s[100001];
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') num[0]++;
if (s[i][0] == 'A') num[1]++;
if (s[i][0] == 'R') num[2]++;
if (s[i][0] == 'C') num[3]++;
if (s[i][0] == 'H') num[4]++;
}
int keta = 0;
for (i = 0; i < 5; i++) {
if (num[i] > 0) keta++;
}
if (keta < 3) {
cout << "0" << endl;
getchar();
getchar();
return 0;
}
long sum3 = 0;
int cnt = 0;
int sum[9999999] = {0};
for (i = 0; i < 5; i++) {
if (num[i] == 0) continue;
total = num[i];
int total1 = total;
for (j = i + 1; j < 5; j++) {
if (num[j] == 0) continue;
total = total1 * num[j];
int total2 = total;
for (k = j + 1; k < 5; k++) {
if (num[k] == 0) continue;
total = total * num[k];
sum3 = sum3 + (long)total;
total = total2;
}
}
}
cout << sum3 << endl;
getchar();
getchar();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import Counter
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
cnt_v = 0
for x, y in memo:
if x in check:
ans += y
if y > 1:
cnt += 1
cnt_v += y
if ans == 0:
print(0)
else:
print(combination(ans, 3) - (ans * cnt - cnt_v))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string s = "MARCH";
map<char, int> cnt;
long long res = 0;
void find(int p = 0, int l = 0, string prefix = "") {
if (p == 3) {
res += cnt[prefix[0]] * cnt[prefix[1]] * cnt[prefix[2]];
return;
}
for (int i = l; i < s.size(); i++) {
find(p + 1, i + 1, prefix + s[i]);
}
}
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
cnt[t[0]]++;
}
find();
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
for (int i = 1; i <= t; i++) {
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() {
int n;
cin >> n;
map<char, int> mp;
mp['M'] = 0;
mp['A'] = 0;
mp['R'] = 0;
mp['C'] = 0;
mp['H'] = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (mp.count(s[0])) {
mp[s[0]]++;
}
}
long long int ans = 0;
ans += mp['M'] * mp['A'] * mp['R'];
ans += mp['M'] * mp['A'] * mp['C'];
ans += mp['M'] * mp['A'] * mp['H'];
ans += mp['M'] * mp['R'] * mp['C'];
ans += mp['M'] * mp['R'] * mp['H'];
ans += mp['M'] * mp['C'] * mp['H'];
ans += mp['A'] * mp['R'] * mp['C'];
ans += mp['A'] * mp['R'] * mp['H'];
ans += mp['A'] * mp['C'] * mp['H'];
ans += mp['R'] * mp['C'] * mp['H'];
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
string s[n];
vector<char> c;
vector<int> v;
char march[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n; ++i) c.push_back(s[i][0]);
for (int i = 0; i < 5; ++i) {
int num;
num = count(c.begin(), c.end(), march[i]);
if (num != 0) {
v.push_back(num);
}
}
int l = v.size();
if (l <= 2) {
cout << 0 << endl;
} else if (l == 3) {
cout << (long long)(v[0] * v[1] * v[2]) << endl;
} else if (l == 4) {
cout << (long long)(v[0] * v[1] * v[2] + v[0] * v[1] * v[3] +
v[0] * v[2] * v[3] + v[1] * v[2] * v[3])
<< endl;
} else {
cout << (long long)(v[0] * v[1] * v[2] + v[0] * v[1] * v[3] +
v[0] * v[1] * v[4] + v[0] * v[2] * v[3] +
v[0] * v[2] * v[4] + v[0] * v[3] * v[4] +
v[1] * v[2] * v[3] + v[1] * v[2] * v[4] +
v[1] * v[3] * v[4] + v[2] * v[3] * v[4])
<< endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long int N;
cin >> N;
vector<string> S(N);
long long int Y = 0;
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i].at(0) == 'M') {
M++;
} else if (S[i].at(0) == 'A') {
A++;
} else if (S[i].at(0) == 'R') {
R++;
} else if (S[i].at(0) == 'C') {
C++;
} else if (S[i].at(0) == 'H') {
H++;
}
}
if (M > 0 && A > 0 && R > 0) {
Y += M * A * R;
}
if (M > 0 && A > 0 && C > 0) {
Y += M * A * C;
}
if (M > 0 && A > 0 && H > 0) {
Y += M * A * H;
}
if (M > 0 && R > 0 && C > 0) {
Y += M * R * C;
}
if (M > 0 && H > 0 && R > 0) {
Y += M * H * R;
}
if (M > 0 && C > 0 && H > 0) {
Y += M * C * H;
}
if (A > 0 && C > 0 && R > 0) {
Y += A * C * R;
}
if (H > 0 && A > 0 && R > 0) {
Y += H * A * R;
}
if (C > 0 && A > 0 && H > 0) {
Y += C * A * H;
}
if (H > 0 && C > 0 && R > 0) {
Y += H * C * R;
}
cout << Y << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string s = "MARCH";
int c[5] = {0};
int n;
scanf("%d", &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]++;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
printf("%lld", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chkmax(T &a, const T &b) {
return b > a ? a = b, true : false;
}
template <class T>
inline bool chkmin(T &a, const T &b) {
return b < a ? a = b, true : false;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const long long MAXn = 1e5 + 5;
const long long MOD = 1000000007;
const long long INF = (long long)1e18;
map<char, long long> cnt;
string tmp = "MARCH";
bool chk(string s) {
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
return true;
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (chk(s)) cnt[s[0]]++;
}
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 < n; k++) {
ans += cnt[tmp[i]] * cnt[tmp[j]] * cnt[tmp[k]];
}
}
}
cout << ans << '\n';
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | package main
import "fmt"
func main(){
var N int
fmt.Scan(&N)
S := make([]string,N)
for i:=0;i<N;i++{
fmt.Scan(&S[i])
}
m:= make(map[string]int)
for i:=0;i<N;i++{
first_char := S[i][0:1]
if (first_char == "M" || first_char == "A" || first_char == "R" || first_char == "C" || first_char == "H"){
m[first_char] += 1
}
}
fmt.Println(m)
P := [10]string{"M","M","M","M","M","M","A","A","A","R"}
Q := [10]string{"A","A","A","R","R","C","R","R","C","C"}
R := [10]string{"R","C","H","C","H","H","C","H","H","H"}
result :=0
for i:=0;i<10;i++{
// fmt.Println(m[P[i]]*m[Q[i]]*m[R[i]])
result += m[P[i]]*m[Q[i]]*m[R[i]]
}
fmt.Println(result)
// if len(m) <= 2{
// fmt.Println(0)
// }
// if len(m) == "C"{
// result := 1
// for _,v := range m{
// result *= v
// }
// fmt.Println(result)
// }
// if len(m) == 4{
// sum := 1
// for _,v := range m{
// sum *= v
// }
// result :=0
// for _,v := range m{
// result += (sum/v)
// }
// fmt.Println(result)
// }
// if len(m) == 5{
// result := 0
// for k1,v := range m{
// for k2,x := range m{
// for k3,y := range m{
// if k1 != k2 && k2 != k3{
// result += v*x*y
// }
// }
// }
// }
// fmt.Println(result)
// }
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int MARCH[5];
for (int i = 0; (5) > i; i++) MARCH[i] = 0;
for (int i = 0; (n) > i; i++) {
string tmp;
cin >> tmp;
if (tmp[0] == 'M')
MARCH[0]++;
else if (tmp[0] == 'A')
MARCH[1]++;
else if (tmp[0] == 'R')
MARCH[2]++;
else if (tmp[0] == 'C')
MARCH[3]++;
else if (tmp[0] == 'H')
MARCH[4]++;
}
long long kekka = 0;
for (int i = 0; (5) > i; i++) {
for (int j = i + 1; 5 > j; j++) {
for (int k = j + 1; 5 > k; k++) {
kekka += MARCH[i] * MARCH[j] * MARCH[k];
}
}
}
cout << kekka << 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 = 1e9 + 7;
int N;
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
bool flag = false;
int main(void) {
cin >> N;
for (int i = 0; i < N; i++) {
string t;
cin >> t;
if (t[0] == 'M') m++;
if (t[0] == 'A') a++;
if (t[0] == 'R') r++;
if (t[0] == 'C') c++;
if (t[0] == 'H') h++;
}
unsigned long long ans = m * a * r + m * a * c + m * a * h + m * r * c +
m * r * h + m * c * h + a * r * c + a * r * h +
a * c * h + r * c * h;
cout << ans << endl;
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 fn(int mh, int nm) {
if (nm < 2) {
return 0;
}
int sa = mh - nm;
long long rt = sa;
if (nm == 2) {
return rt;
}
return rt + nm * (nm - 1) * (nm - 2) / 6;
}
int main() {
int n;
cin >> n;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
char s1 = s.at(0);
if (s1 == 'M') {
m++;
} else if (s1 == 'A') {
a++;
} else if (s1 == 'R') {
r++;
} else if (s1 == 'C') {
c++;
} else if (s1 == 'H') {
h++;
}
}
long long ans = 0;
int mh = m + a + r + c + h;
long long cm = mh * (mh - 1) * (mh - 2) / 6;
ans = cm - fn(mh, m) - fn(mh, a) - fn(mh, r) - fn(mh, c) - fn(mh, h);
if (ans < 0) {
ans = 0;
}
if (m * a * r == 0 && m * a * c == 0 && m * a * h == 0 && m * r * c == 0 &&
m * r * h == 0 && m * c * h == 0 && a * r * c == 0 && a * r * h == 0 &&
a * c * h == 0 && c * h * r == 0) {
ans = 0;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int N;
cin >> N;
string name;
vector<char> S(N + 1);
long long int T = 0;
for (long long int i = 0; i < N; i++) {
cin >> name;
if (name[0] == 'M' || name[0] == 'A' || name[0] == 'R' || name[0] == 'C' ||
name[0] == 'H') {
S[i - T] = name[0];
} else {
T++;
}
}
N -= T;
sort(S.begin(), S.end());
long long int roop = 0;
long long int ch[27] = {0};
for (long long int i = 1; i < N; i++) {
ch[roop]++;
if (S[i] != S[i + 1]) {
roop++;
}
}
ch[roop]++;
long long int ans = 0;
for (long long int i = 0; i < roop; i++) {
for (long long int j = i + 1; j < roop + 1; j++) {
for (long long int k = j + 1; k < roop + 2; k++) {
ans += ch[i] * ch[j] * ch[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
long long pow(int x, int n) {
long long 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;
for (int i = 0; i < s.size(); ++i) {
t[i] = toupper(s[i]);
}
return t;
}
string toLower(string s) {
string t = s;
for (int i = 0; i < s.size(); ++i) {
t[i] = tolower(s[i]);
}
return t;
}
int dp[10000][10000];
long nCr(int n, int 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;
for (int i = 0; i < n; ++i) {
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;
for (int i = 0; i < 5; ++i) {
if (check[i]) T++;
}
if (cnt >= 3 && T >= 3) {
int tmp = 0;
for (int i = 0; i < 5; ++i) {
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 | python2 | # -*- coding: utf-8 -*-
import itertools
def filter_name(n):
return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"
def filter_ok(l):
if l[0][0:1] == l[1][0:1] or l[0][0:1] == l[2][0:1] or l[1][0:1] == l[2][0:1]:
return False
return True
n = input()
a = []
for i in range(n):
b = raw_input()
if filter_name(b[0:1]):
a.append(b)
a = list(itertools.combinations(a, 3))
a = filter(filter_ok, a)
print len(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 | python3 | #https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = [0]*max(N,3)
ans = 0
for s in S:
if s[0] == "M":
march[0] +=1
if s[0] == "A":
march[1] +=1
if s[0] == "R":
march[2] +=1
if s[0] == "C":
march[3] +=1
if s[0] == "H":
march[4] +=1
for i,j,k in itertools.combinations(march,3):
ans += i*j*k
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
N=int(input())
S=list(str(input()) for i in range(N))
m,a,r,c,h=[0]*5
ans=0
if S[0]=="M":m+=1
if S[0]=="A":a+=1
if S[0]=="R":r+=1
if S[0]=="C":c+=1
if S[0]=="H":h+=1
x=[m,a,r,c,h]
for i in itertools.combinations(x,3):
ans+=i[0]*i[1]*i[2]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Map<String, Integer> map = new HashMap<>();
map.put("M",0);
map.put("A",0);
map.put("R",0);
map.put("C",0);
map.put("H",0);
for (int i = 0; i < n; i++){
String s = String.valueOf(sc.next().charAt(0));
if (map.containsKey(s)) {
map.put(s, map.get(s) + 1);
}
}
int sum = 0;
sum += map.get("M")*map.get("A")*map.get("R");
sum += map.get("M")*map.get("A")*map.get("C");
sum += map.get("M")*map.get("A")*map.get("H");
sum += map.get("M")*map.get("R")*map.get("C");
sum += map.get("M")*map.get("R")*map.get("H");
sum += map.get("M")*map.get("C")*map.get("H");
sum += map.get("A")*map.get("R")*map.get("C");
sum += map.get("A")*map.get("R")*map.get("H");
sum += map.get("A")*map.get("C")*map.get("H");
sum += map.get("R")*map.get("C")*map.get("H");
System.out.println(sum);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int num = 0;
int main(void) {
int N;
cin >> N;
char name[5] = {'M', 'A', 'R', 'C', 'H'};
char s[11];
for (int i = 0; i < N; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == name[j]) {
num++;
}
}
}
cout << ((num * (num - 1) * (num - 2)) / 6) << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int mapping(char c) {
if (c == 'M') return 0;
if (c == 'A') return 1;
if (c == 'R') return 2;
if (c == 'C') return 3;
if (c == 'H') return 4;
}
int main() {
int n;
string s;
cin >> n;
int temp[5];
for (int i = 0; i < 5; i++) {
temp[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> s;
temp[mapping(s[0])]++;
}
int 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 += temp[i] * temp[j] * temp[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;
const int Nmax = 200010;
int nCr(int n, int r) {
int ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int main() {
long long N;
cin >> N;
string S[Nmax];
char c[Nmax];
int cnt[5] = {}, count = 0;
for (int i = 0; i < N; i++) {
cin >> S[i];
string str(S[i]);
c[i] = str[0];
if (c[i] == 'M') {
cnt[0]++;
count++;
}
if (c[i] == 'A') {
cnt[1]++;
count++;
}
if (c[i] == 'R') {
cnt[2]++;
count++;
}
if (c[i] == 'C') {
cnt[3]++;
count++;
}
if (c[i] == 'H') {
cnt[4]++;
count++;
}
}
if (count <= 2)
cout << "0" << endl;
else {
count = 0;
int n = 1, N = 0;
for (int i = 0; i < 5; i++)
if (cnt[i] >= 1) {
n *= cnt[i];
N += cnt[i];
count++;
}
cout << n * nCr(count, 3) - (N - count) << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k;
int n;
string s[100000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
}
int cnt = 0;
for (i = 0; i < n; i++) {
if (s[i][0] == 'M' || s[i][0] == 'A' || s[i][0] == 'R' || s[i][0] == 'C' ||
s[i][0] == 'H') {
for (j = i + 1; j < n; j++) {
if (s[j][0] == 'M' || s[j][0] == 'A' || s[j][0] == 'R' ||
s[j][0] == 'C' || s[j][0] == 'H') {
if (s[j][0] != s[i][0]) {
for (k = j + 1; k < n; k++) {
if (s[k][0] == 'M' || s[k][0] == 'A' || s[k][0] == 'R' ||
s[k][0] == 'C' || s[k][0] == 'H') {
if (s[k][0] != s[i][0] && s[k][0] != s[j][0]) {
cnt++;
}
}
}
}
}
}
}
}
cout << cnt << endl;
getchar();
getchar();
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 MARCH[5];
int main(int argc, const char* argv[]) {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string st;
cin >> st;
if (st[0] == 'M') MARCH[0]++;
if (st[0] == 'A') MARCH[1]++;
if (st[0] == 'R') MARCH[2]++;
if (st[0] == 'C') MARCH[3]++;
if (st[0] == 'H') MARCH[4]++;
}
long long rst = 0;
vector<int> v;
for (int i = 0; i < 5; i++) {
if (MARCH[i] != 0) v.push_back(MARCH[i]);
}
sort(v.begin(), v.end());
if (v.size() == 0) {
cout << 0 << endl;
return 0;
}
if (v.size() == 1) {
rst = v[0];
cout << rst << endl;
return 0;
}
if (v.size() == 2) {
rst = v[0] * v[1];
cout << rst << endl;
return 0;
}
if (v.size() == 3) {
rst = v[0] * v[1] * v[2];
cout << rst << endl;
return 0;
}
do {
int i = 0;
int s = 1;
for (auto x : v) {
if (i < 3) {
s *= x;
i++;
}
}
rst += s;
} while (next_permutation(v.begin(), v.end()));
cout << rst << 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;
string S;
char T[5] = {'M', 'A', 'R', 'C', 'H'};
int C[5] = {0};
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
for (int j = 0; j < 5; j++) {
if (S[0] == T[j]) C[j]++;
}
}
int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += C[i] * C[j] * C[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | //#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int n;
int cnt=0;
char g[20];
string s[10010];
ll ans=0;
int v1[9]={0,0,0,0,0,1,1,1,2};
int v2[9]={1,1,1,2,2,2,2,3,3};
int v3[9]={2,3,4,3,4,3,4,4,4};
int powa(int d,int e){
if(e<0)return 0;
return pow(d,e);
}
ll int ini[5];
int main(){
cin>>n;
REP(i,n){
cin>>g;
//g=g.substr(0,1);
//cout<<g[0];
if(g[0]=='M'){
ini[0]++;
}if(g[0]=='A'){
ini[1]++;
}if(g[0]=='R'){
ini[2]++;
}if(g[0]=='C'){
ini[3]++;
}if(g[0]=='H'){
ini[4]++;
}
}
int c=0;
REP(i,5){
if(ini[i]>0)c++;
}
if(c<3){
cout<<0<<endl;
return 0;
}
REP(i,9){
ans+=ini[v1[i]]*ini[v2[i]]*ini[v3[i]];
}
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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 (dict.find(str) == dict.end()) {
dict.insert(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 ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
vector<int> cnt(5);
for (ll i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') cnt[0]++;
if (s[0] == 'A') cnt[1]++;
if (s[0] == 'R') cnt[2]++;
if (s[0] == 'C') cnt[3]++;
if (s[0] == 'H') cnt[4]++;
}
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 += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans;
cout << "\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 | python3 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import Counter
from operator import mul
from functools import reduce
def cmb(n, r):
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1, r + 1))
return over // under
n = int(readline())
s = []
check = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
ss = readline().rstrip().decode()
if ss[0] in check:
s.append(ss[0])
counter = list(Counter(s).values())
if len(counter) < 3:
print(0)
exit()
ans = cmb(sum(counter), 3)
for v in counter:
if v >= 2:
ans -= cmb(v, 2) * (len(s) - v)
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 | UNKNOWN | #include <stdio.h>
int main(){
int n;
scanf("%d¥n",&n);
int m=0;
int r=0;
int c=0;
int a=0;
int h=0;
for(int i = 0;i<n;i++){
char str[64];
scanf("%s¥n",&str);
if(str[0] == "M"){m++;}
if(str[0] == "C"){c++;}
if(str[0] == "A"){a++;}
if(str[0] == "R"){r++;}
if(str[0] == "H"){h++;}
}
unsigned long ans;
ans = (m+c+a+r+h)*(m+c+a+r+h)*(m+c+a+r+h);
ans -= (m+c+a+r+h)*3*a*a-2*a*a*a;
ans -= (m+c+a+r+h)*3*m*m-2*m*m*m;
ans -= (m+c+a+r+h)*3*h*h-2*h*h*h;
ans -= (m+c+a+r+h)*3*r*r-2*r*r*r;
ans -= (m+c+a+r+h)*3*c*c-2*c*c*c;
printf("%lu",ans);
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char name[n][11];
int march[5] = {0};
for (int i = 0; i < n; i++) {
cin >> name[i];
if (name[i][0] == 'M')
march[0]++;
else if (name[i][0] == 'A')
march[1]++;
else if (name[i][0] == 'R')
march[2]++;
else if (name[i][0] == 'C')
march[3]++;
else if (name[i][0] == 'H')
march[4]++;
}
long combination = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
combination += march[i] * march[j] * march[k];
}
}
}
cout << combination << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int march[] = new int[5];
for(int i = 0; i < N; i++) {
String S = sc.next();
char x = S.charAt(0);
switch(x){
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
}
}
long sum = 0;
for(int a = 0; a < 3; a++) {
for(int b = a + 1; b < 4; b++) {
for(int c = b + 1; c < 5; c++){
sum += march[a] * march[b] * march[c];
}
}
}
System.out.println(sum);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int h[5];
int main() {
int N;
for (int i = 0; i < 5; i++) h[i] = 0;
cin >> N;
for (int i = 0; i < N; i++) {
char S[100];
cin >> S;
if (S[0] == 'M') h[0]++;
if (S[0] == 'A') h[1]++;
if (S[0] == 'R') h[2]++;
if (S[0] == 'C') h[3]++;
if (S[0] == 'H') h[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++)
for (int k = j + 1; k < 5; k++) {
ans += h[i] * h[j] * h[k];
}
return (printf("%lld\n", ans));
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
void cou(vector<vector<T>> a) {
long long b = a.size();
long long c = a[0].size();
for (long long i = 0; i < b; i++) {
for (long long j = 0; j < c; j++) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
long long wari(long long a, long long b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
long long keta(long long a) {
double b = a;
b = log10(b);
long long c = b;
return c + 1;
}
long long souwa(long long a) { return a * (a + 1) / 2; }
bool prime(long long a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
double b = sqrt(a);
for (long long i = 3; i <= b; i += 2) {
if (a % i == 0) {
return false;
}
}
return true;
}
struct Union {
vector<long long> par;
Union(long long a) { par = vector<long long>(a, -1); }
long long find(long long a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(long long a, long long b) { return find(a) == find(b); }
long long Size(long long a) { return -par[find(a)]; }
void unite(long long a, long long b) {
a = find(a);
b = find(b);
if (a == b) return;
if (Size(b) > Size(a)) swap<long long>(a, b);
par[a] += par[b];
par[b] = a;
}
};
long long ketas(long long a) {
string b = to_string(a);
long long c = 0;
for (long long i = 0; i < keta(a); i++) {
c += b[i] - '0';
}
return c;
}
long long gcm(long long a, long long b) {
if (b == 0) return a;
return gcm(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcm(a, b) * b; }
signed main() {
long long a, e = 0;
cin >> a;
string b;
vector<char> c(a);
vector<long long> d(5, 0);
for (long long i = 0; i < a; i++) {
cin >> b;
c[i] = b[0];
}
for (long long i = 0; i < a; i++) {
if (c[i] == 'M') d[0]++;
if (c[i] == 'A') d[1]++;
if (c[i] == 'R') d[2]++;
if (c[i] == 'C') d[3]++;
if (c[i] == 'H') d[4]++;
}
if (d[0] + d[1] + d[2] + d[3] + d[4] < 3)
cout << 0 << endl;
else {
for (long long i = 0; i < 5; i++) {
if (d[i] > 0) e++;
if (e < 3) cout << 0 << endl;
if (e == 3) {
sort(d.begin(), d.end());
cout << d[2] * d[3] * d[4] << endl;
}
if (e == 4) {
sort(d.begin(), d.end());
cout << d[1] * d[2] * d[3] +
(d[1] * d[2] + d[2] * d[3] + d[1] * d[3]) * d[4]
<< endl;
}
if (e == 5) {
sort(d.begin(), d.end());
long long f = d[1] * d[2] * d[3] +
(d[1] * d[2] + d[2] * d[3] + d[1] * d[3]) * d[4];
long long g = 0;
for (long long i = 1; i < 5; i++) {
for (long long j = i + 1; j < 5; j++) {
g += d[i] * d[j];
}
}
g *= d[0];
cout << f * g << 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 | #include <bits/stdc++.h>
using namespace std;
int N;
long long NM, NA, NR, NC, NH;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
char s[10];
scanf("%s", s);
if (s[0] == 'M')
NM += 1;
else if (s[0] == 'A')
NA += 1;
else if (s[0] == 'R')
NR += 1;
else if (s[0] == 'C')
NC += 1;
else if (s[0] == 'H')
NH += 1;
}
NM = (NM == 0) ? 1 : NM;
NA = (NA == 0) ? 1 : NA;
NR = (NR == 0) ? 1 : NR;
NC = (NC == 0) ? 1 : NC;
NH = (NH == 0) ? 1 : NH;
cout << NM * NA * NR * NC * NH << 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 name[15];
int cnt[5];
int main() {
int n, sum = 0, num = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", name);
if (name[0] == 'M')
cnt[0]++;
else if (name[0] == 'A')
cnt[1]++;
else if (name[0] == 'R')
cnt[2]++;
else if (name[0] == 'C')
cnt[3]++;
else if (name[0] == 'H')
cnt[4]++;
}
long long ans = 0;
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++)
for (int k = j + 1; k < 5; k++) ans += cnt[i] * cnt[j] * cnt[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;
const int INF = (1 << 30);
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
map<char, int> counter;
int main() {
int N;
cin >> N;
string names[N];
for (int i = 0; i < (int)(N); i++) {
cin >> names[i];
if (names[i][0] == 'M' || names[i][0] == 'A' || names[i][0] == 'R' ||
names[i][0] == 'C' || names[i][0] == 'H')
counter[names[i][0]] += 1;
}
long long ans = 0;
string tmp = "RCH";
for (int i = 0; i < (int)(3); i++) {
ans += counter['M'] * counter['A'] * counter[tmp[i]];
}
ans += counter['M'] * counter['R'] * counter['C'];
ans += counter['M'] * counter['R'] * counter['H'];
ans += counter['M'] * counter['C'] * counter['H'];
ans += counter['A'] * counter['R'] * counter['C'];
ans += counter['A'] * counter['R'] * counter['H'];
ans += counter['A'] * counter['C'] * counter['H'];
ans += counter['R'] * counter['C'] * counter['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 MOD = 1e9 + 7;
int main() {
int i, 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 < (int)(n); i++) {
string s;
cin >> s;
char t = s.at(0);
cout << t << endl;
if (s.at(0) == 'M')
m++;
else if (s.at(0) == 'A')
a++;
else if (s.at(0) == 'R')
r++;
else if (s.at(0) == 'C')
c++;
else if (s.at(0) == 'H')
h++;
}
int64_t g = m * a * (r + c + h) + m * r * (c + h) + m * c * h +
a * r * (c + h) + a * c * h + r * c * h;
cout << g << 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;
struct cww {
cww() {
if (1) {
ios::sync_with_stdio(false);
cin.tie(0);
}
}
} star;
template <typename T>
inline bool chmin(T &l, T r) {
bool a = l > r;
if (a) l = r;
return a;
}
template <typename T>
inline bool chmax(T &l, T r) {
bool a = l < r;
if (a) l = r;
return a;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &it : v) is >> it;
return is;
}
class range {
private:
struct I {
int x;
int operator*() { return x; }
bool operator!=(I &lhs) { return x < lhs.x; }
void operator++() { ++x; }
};
I i, n;
public:
range(int n) : i({0}), n({n}) {}
range(int i, int n) : i({i}), n({n}) {}
I &begin() { return i; }
I &end() { return n; }
};
int main() {
map<char, long long> in;
int N;
cin >> N;
for (int i : range(N)) {
string p;
cin >> p;
in[p[0]]++;
}
string s = "MARCH";
set<string> x;
do {
string t = s.substr(0, 3);
sort((t).begin(), (t).end());
x.insert(t);
} while (next_permutation((s).begin(), (s).end()));
long long ret = 0;
for (auto &it : x) {
ret += in[it[0]] * in[it[1]] * in[it[2]];
}
cout << ret << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
int main() {
int(N);
cin >> (N);
vector<string> s;
for (int a = 0; a < (N); ++a) {
string(str);
cin >> (str);
s.push_back(str);
}
int cou[5] = {0};
map<char, int> m;
for (int a = 0; a < (N); ++a) {
char q = s.at(a).at(0);
if (q == 'M') {
cou[0]++;
}
if (q == 'A') {
cou[1]++;
}
if (q == 'R') {
cou[2]++;
}
if (q == 'C') {
cou[3]++;
}
if (q == 'H') {
cou[4]++;
}
}
cout << (cou[0] * cou[1] * cou[2] + cou[0] * cou[1] * cou[3] +
cou[0] * cou[1] * cou[4] + cou[0] * cou[2] * cou[3] +
cou[0] * cou[2] * cou[4] + cou[0] * cou[3] * cou[4] +
cou[1] * cou[2] * cou[3] + cou[1] * cou[2] * cou[4] +
cou[1] * cou[3] * cou[4] + cou[2] * cou[3] * cou[4])
<< 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())
march_l = [0]*5
for _ in range(n):
s = input()
s0 = s[0]
if s0 == 'M':
march_l[0] += 1
elif s0 == 'A':
march_l[1] += 1
elif s0 == 'R':
march_l[2] += 1
elif s0 == 'C':
march_l[3] += 1
elif s0 == 'H':
march_l[4] += 1
march_cnt = [i for i in march_l if i != 0]
ans = 0
prod = 1
for i in march_cnt:
prod *= i
if len(march_cnt) > 3:
for i in march_cnt:
ans += prod//i
print(ans)
elif len(march_cnt) == 3:
ans = prod
else:
ans = 0
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long ans = 0;
string temp;
char target[5] = {'M', 'A', 'R', 'C', 'H'};
int count[5] = {0, 0, 0, 0, 0};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
for (int j = 0; j < 5; j++) {
if (temp[0] == target[j]) count[j]++;
}
}
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;
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())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
s = input()[0]
try:
march[s] += 1
except:
pass
ans = 0
for key1 in march.keys():
for key2 in march.keys():
if key1 != key2:
for key3 in march.keys():
if key3 != key1 and key3 != key2:
ans += key1 * key2 * key3
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
using namespace std;
int main(){
int N; cin>>N;
map<string,int> name;
for(int i=0;i<N;i++){
string S;cin>>S;
if(S.at(0)=='M'||S.at(0)=='A'||S.at(0)=='R'||S.at(0)=='C'||S.at(0)=='H'){
name[S]++;
}
}
long sum=name['M']*name['A']*name['R']+name['M']*name['A']*name['C']+name['M']*name['A']*name['H']+name['M']*name['R']*name['C']+name['M']*name['R']*name['H']+name['M']*name['C']*name['H']+name['C']*name['A']*name['R']+name['H']*name['A']*name['R']+name['C']*name['A']*name['H']+name['R']*name['C']*name['H'];
cout<<sum<<endl;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> vec(5, 0);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string dummy;
cin >> dummy;
if (dummy.at(0) == 'M') {
vec.at(0)++;
}
if (dummy.at(0) == 'A') {
vec.at(1)++;
}
if (dummy.at(0) == 'R') {
vec.at(2)++;
}
if (dummy.at(0) == 'C') {
vec.at(3)++;
}
if (dummy.at(0) == 'H') {
vec.at(4)++;
}
}
cout << vec[0] * vec[1] * vec[2] + vec[0] * vec[1] * vec[3] +
vec[0] * vec[1] * vec[4] + vec[0] * vec[2] * vec[3] +
vec[0] * vec[2] * vec[4] + vec[1] * vec[2] * vec[3] +
vec[1] * vec[2] * vec[4] + vec[1] * vec[3] * vec[4] +
vec[2] * vec[3] * vec[4]
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import*;d={}
for t in open(0).read().split():d[t]=d.get(t,0)+1
g=d.get;print(sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3))) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[5] = {0};
char tmp[10];
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 <= 2 && ((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;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<long long> num(6);
for (int i = 0; i < n; i++) {
char c;
string s;
cin >> c >> s;
int tmp;
switch (c) {
case 'M':
tmp = 0;
break;
case 'A':
tmp = 1;
break;
case 'R':
tmp = 2;
break;
case 'C':
tmp = 3;
break;
case 'H':
tmp = 4;
break;
default:
tmp = 5;
break;
}
num[tmp]++;
}
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 += 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 | 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[] nums = {0, 0, 0, 0, 0};
for(int i = 0; i < n; i++) {
String str = sc.next();
switch(str.charAt(0)) {
case 'M': nums[0]++; break;
case 'A': nums[1]++; break;
case 'R': nums[2]++; break;
case 'C': nums[3]++; break;
case 'H': nums[4]++; break;
}
}
int type = 0;
for(int i = 0; i < 5; i++) {
if(nums[i] != 0)
type++;
}
if(type < 3)
System.out.println(0);
else if(type == 3) {
long cnt = 1;
for(int i = 0; i < 5; i++) {
if(nums[i] != 0)
cnt*=nums[i];
}
System.out.println(cnt);
} else {
long cnt = 0;
for(int i = 0; i < 5; i++) {
if(nums[i] == 0) continue;
long buf= 0;
if(type == 4)
buf = 1;
else if(type == 5)
buf = 4;
for(int j = 0; j < 5; j++) {
if(i == j) continue;
if(nums[j] != 0)
buf *= nums[j];
}
cnt += buf;
}
System.out.println(cnt);
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int j, i, s1, s2, s3, s4, s5;
s1 = s2 = s3 = s4 = s5 = 0;
cin >> j;
string a;
for (i = 0; i < j; i++) {
cin >> a;
if (a[0] == 'M') s1++;
if (a[0] == 'A') s2++;
if (a[0] == 'R') s3++;
if (a[0] == 'C') s4++;
if (a[0] == 'H') s5++;
}
cout << s1 * s2 * s3 + s1 * s2 * s4 + s1 * s2 * s5 + s1 * s3 * s4 +
s1 * s3 * s5 + s1 * s4 * s5 + s2 * s3 * s4 + s2 * s3 * s5 +
s2 * s4 * s5 + s3 * s4 * s5
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
int n;
string s;
const string names="MARCH";
vector<int> checked;
bool checkMarch(int i) {
if (checked[i]==0) {
checked[i]=2;
for (auto c:names) {
if (s[i]==c) checked[i]=1;
}
}
return checked[i]==1;
}
ll march() {
sort(s.begin(), s.end(), [](string l, string r) {
return l < r;
});
ll ways=0;
for (auto i=0;i<n-2;i++) {
auto first=s[i];
if (!checkMarch(i)) continue;
for (auto j=i+1;j<n-1;j++) {
auto second=s[j];
if (!checkMarch(j)) continue;
if (first==second) continue;
for (auto k=j+1;k<n;k++) {
auto third=s[k];
if (!checkMarch(k)) continue;
if (first==third ||
second==third) continue;
ways++;
}
}
}
return ways;
}
int main(int argc, const char * argv[]) {
cin>>n;
s.assign(n, ' ');
for (auto &c:s) {
cin>>c;
}
checked.assign(n, 0);
cout<<march();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtC
{
class Program
{
static void Main(string[] args)
{
var N = ReadInt();
int[] namesCount =
{
0, 0, 0, 0, 0
};
for (int i = 0; i < N; i++)
{
var str = ReadString();
switch (str[0])
{
case 'M':
namesCount[0]++;
break;
case 'A':
namesCount[1]++;
break;
case 'R':
namesCount[2]++;
break;
case 'C':
namesCount[3]++;
break;
case 'H':
namesCount[4]++;
break;
}
}
long count = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i == j) continue;
for (int k = 0; k < 5; k++)
{
if (j == k || i == k) continue;
count += namesCount[i] * namesCount[j] * namesCount[k];
}
}
}
Out(count / 6);
}
//最小公倍数
static int LCM(int num1, int num2)
{
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
static long LCM(long num1, long num2)
{
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
static int GCD(int num1, int num2)
{
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0)
{
a = b;
b = mod;
}
return b;
}
static long GCD(long num1, long num2)
{
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0)
{
a = b;
b = mod;
}
return b;
}
static int[] ReadIntArray()
{
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt()
{
return int.Parse(Console.ReadLine());
}
static long[] ReadLongArray()
{
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong()
{
return long.Parse(Console.ReadLine());
}
static string ReadString()
{
return Console.ReadLine();
}
static void Out(object o)
{
Console.WriteLine(o);
}
}
static class EnumerableExtension
{
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
{
foreach (var x in enumerable)
{
function(x);
}
}
}
class PriorityQueue<T>
{
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long ans = 0;
vector<int> a((5), (0));
;
cin >> n;
vector<string> s(n);
for (int(i) = 0; (i) < (n); (i)++) {
cin >> s[i];
switch (s[i][0]) {
case 'M':
a[0]++;
break;
case 'A':
a[1]++;
break;
case 'R':
a[2]++;
break;
case 'C':
a[3]++;
break;
case 'H':
a[4]++;
break;
}
}
for (int(i) = 0; (i) < (3); (i)++) {
for (int(j) = i + 1; (j) < 4; (j)++) {
for (int(k) = j + 1; (k) < 5; (k)++) {
ans += (a[i] * a[j] * a[k]);
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, m = 0, a = 0, r = 0, c = 0, h = 0;
long long int ans = 0;
string S[100000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M') m++;
if (S[i][0] == 'A') a++;
if (S[i][0] == 'R') r++;
if (S[i][0] == 'C') c++;
if (S[i][0] == 'H') h++;
}
ans = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) +
a * c * h + r * c * h;
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 | UNKNOWN | var input=`
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
`;
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(v=> v.trim()).reverse();
var n=arr.pop()-0;
var obj={M:0,A:0,R:0,C:0,H:0}
arr.forEach(v=>{
if(obj.hasOwnProperty(v[0]))obj[v[0]]++;
});
var ary=Object.values(obj);
var sum=0;
for(var i=0;i<5;i++){
for(var j=i+1;j<5;j++){
for(var k=j+1;k<5;k++){
sum+=ary[i]*ary[j]*ary[k];
}
}
}
console.log(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>
#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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> PA;
typedef pair<ll, ll> LAP;
typedef pair<int, PA> PPA;
typedef pair<ll, LPA> LPPA;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main()
{
ll int N;
string name;
cin >> N;
ll int M = 0, A = 0, R = 0, C = 0, H = 0;
REP(i,N)
{
cin >> name;
if(name[0] == 'M') ++M;
if(name[0] == 'A') ++A;
if(name[0] == 'R') ++R;
if(name[0] == 'C') ++C;
if(name[0] == 'H') ++H;
}
ll int temp[5];
temp[0] = M;
temp[1] = A;
temp[2] = R;
temp[3] = C;
temp[4] = H;
ll int ans = 0;
REP(i,10) ans += temp[P[i]] * temp[Q[i]] * temp[R[i]];
cout << ans << endl;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n;
scanf("%d", &n);
char s[n][10];
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int ninn[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
ninn[0]++;
} else if (s[i][0] == 'A') {
ninn[1]++;
} else if (s[i][0] == 'R') {
ninn[2]++;
} else if (s[i][0] == 'C') {
ninn[3]++;
} else if (s[i][0] == 'H') {
ninn[4]++;
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += ninn[i] * ninn[j] * ninn[k];
}
}
}
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
switch (s[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'H':
h++;
break;
}
}
vector<int> v;
v.push_back(m);
v.push_back(a);
v.push_back(r);
v.push_back(c);
v.push_back(h);
sort(v.begin(), v.end());
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += v[i] * v[j] * v[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
map<char, int> mp;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
for (int i = 0; i < (5); i++) {
if (s[0] == c[i]) {
mp[c[i]]++;
}
}
}
long long ans = 0;
char c1, c2, c3;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
c1 = c[i];
c2 = c[j];
c3 = c[k];
ans += mp[c1] * mp[c2] * mp[c3];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string march = "MARCH";
vector<char> s;
string t;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
s.push_back(t[0]);
}
int sum = 0;
vector<int> v(n);
for (int i = n - 1; i > n - 4; i--) {
v[i] = 1;
}
if (s.size() < 3) {
cout << 0;
} else {
do {
set<char> m;
for (int i = 0; i < n; i++) {
if (v[i] == 0) continue;
if (march.find(s[i]) == string::npos) continue;
m.insert(s[i]);
}
if (m.size() == 3) {
sum++;
}
} while (next_permutation(v.begin(), v.end()));
cout << sum;
}
cout << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import java.util.*
fun main(args: Array<String>) {
val sc = Scanner(System.`in`)
val n = sc.nextInt()
val counts = IntArray(5)
for (i in 0..n) {
val line = sc.nextLine()
when (line[0]) {
'M' -> ++counts[0]
'A' -> ++counts[1]
'R' -> ++counts[2]
'C' -> ++counts[3]
'H' -> ++counts[4]
}
}
var ret:Long = 0L
for (i in 0 until 5 - 2) {
for (j in i + 1 until 5 - 1) {
for (k in j + 1 until 5 - 0) {
ret += counts[i] * counts[j] * counts[k]
}
}
}
println(ret)
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int a[5] = {0};
long long int ans = 0;
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]++;
}
}
ans += (a[0] * a[1] * a[2]);
ans += (a[0] * a[1] * a[3]);
ans += (a[0] * a[1] * a[4]);
ans += (a[0] * a[2] * a[3]);
ans += (a[0] * a[2] * a[4]);
ans += (a[0] * a[3] * a[4]);
ans += (a[1] * a[2] * a[3]);
ans += (a[1] * a[2] * a[4]);
ans += (a[1] * a[3] * a[4]);
ans += (a[2] * a[3] * a[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 | java | import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in);) {
solve(sc);
}
}
public static void solve(Scanner sc) {
long[] nums = new long[5];
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
String name = sc.next();
switch (name.charAt(0)) {
case 'M':
nums[0]++;
break;
case 'A':
nums[1]++;
break;
case 'R':
nums[2]++;
break;
case 'C':
nums[3]++;
break;
case 'H':
nums[4]++;
break;
}
}
BigInteger ans = BigInteger.valueOf(0l);
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
ans = ans.add(BigInteger.valueOf(nums[i]).multiply(BigInteger.valueOf(nums[j])).multiply(BigInteger.valueOf(nums[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() {
int N;
cin >> N;
char table[5] = {'M', 'A', 'R', 'C', 'H'};
int charcount[5] = {0, 0, 0, 0, 0};
string s;
for (int i = 0; i < N; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == table[j]) charcount[j]++;
}
}
long long answer = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
answer += charcount[i] * charcount[j] * charcount[k];
}
}
}
cout << answer << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int ans = 0;
int m = 0, a = 0, r = 0, c = 0, h = 0;
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++;
}
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;
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 ans;
int m, a, r, c, h;
int max(int x, int y, int z) {
return ((x > y ? x : y) > z ? (x > y ? x : y) : z);
}
int main() {
int n;
cin >> n;
string s[n + 5];
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i][0] == 'M') m++;
if (s[i][0] == 'A') a++;
if (s[i][0] == 'R') r++;
if (s[i][0] == 'C') c++;
if (s[i][0] == 'H') h++;
}
if (m && a && r) ans += max(m, a, r);
if (m && a && c) ans += max(m, a, c);
if (m && a && h) ans += max(m, a, h);
if (m && r && c) ans += max(m, r, c);
if (m && r && h) ans += max(m, r, h);
if (m && c && h) ans += max(m, c, h);
if (a && r && c) ans += max(a, r, c);
if (a && r && h) ans += max(a, r, h);
if (a && c && h) ans += max(a, c, h);
if (r && c && h) ans += max(r, c, h);
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from math import factorial
def convination(n, r):
a = factorial(n) / factorial(r) / factorial(n - r)
return int(a)
n = int(input())
march = [0]*5
for i in range(n):
temp = input()
if temp[0] == "M":
march[0] += 1
elif temp[0] == "A":
march[1] += 1
elif temp[0] == "R":
march[2] += 1
elif temp[0] == "C":
march[3] += 1
elif temp[0] == "H":
march[4] += 1
total = sum(march)
if total <= 2:
print(0)
quit()
else:
ans = convination(total, 3)
for i in range(5):
if march[i] >= 2:
ans -= (total-march[i])*convination(march[i], 2)
if march[i] >= 3:
ans -= convination(march[i], 3)
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;
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int a[5];
int main() {
for (int64_t i = 0; i < 5; i++) a[i] = 0;
int64_t n;
cin >> n;
for (int64_t i = 0; i < n; i++) {
char tmp[15];
cin >> tmp;
for (int64_t j = 0; j < 5; j++) {
if (tmp[0] == c[j]) {
a[j]++;
}
}
}
int64_t out = 0;
for (int64_t i = 0; i < 5; i++) {
for (int64_t j = i + 1; j < 5; j++) {
for (int64_t 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, i, M, A, R, C, H;
unsigned long 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++;
} else {
}
}
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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);
}
}
// それぞれの文字から始まる名前の数を集計
Integer mNum = m.size();
Integer aNum = a.size();
Integer rNum = r.size();
Integer cNum = c.size();
Integer hNum = h.size();
ArrayList<Integer> valid = new ArrayList<Integer>();
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つも成立しないので更新なし)
double pair = 0;
if(3 == valid.size()){
double allMulti = 1;
for(int i = 0 ; i < valid.size() ; i++){
allMulti = allMulti * valid.get(i);
}
pair = allMulti;
}else if(4 == valid.size()){
double allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
double tmp = allMulti/valid.get(i);
pair = pair + tmp;
}
}else if(5 == valid.size()){
double allMulti = 1;
for(int i = 0; i < valid.size(); i++){
allMulti = allMulti * valid.get(i);
}
for(int i = 0; i < valid.size(); i++){
double 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((int)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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d", &N);
char S[10000][11];
for (int i = 0; i < N; i++) {
scanf("%s", S[i]);
}
int name[5] = {0};
for (int i = 0; i < N; i++) {
switch (S[i][0]) {
case 'M':
name[0]++;
break;
case 'A':
name[1]++;
break;
case 'R':
name[2]++;
break;
case 'C':
name[3]++;
break;
case 'H':
name[4]++;
break;
}
}
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int ans = 0;
for (int i = 0; i < N; i++) {
ans += name[P[i]] * name[Q[i]] * name[R[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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> S(n);
for (int i = 0; i < n; i++) cin >> S[i];
int M = 0, A = 0, R = 0, C = 0, H = 0;
for (int i = 0; i < n; i++) {
if (S[i][0] == 'M') M++;
if (S[i][0] == 'A') A++;
if (S[i][0] == 'R') R++;
if (S[i][0] == 'C') C++;
if (S[i][0] == 'H') H++;
}
long long cnt = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H +
M * C * H + A * R * C + A * R * H + R * C * H + A * C * H;
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
#define int long long
using namespace std;
string a[1234567];
main(){
int n;
cin >> n;
int mm , ma ,mr, mc,mh;
mm = ma = mr = mc = mh = 0;
for(int i = 1 ; i <= n;i++){
cin >> a[i];
if(a[i][0] =='M')mm++;
if(a[i][0] =='A')ma++;
if(a[i][0] =='R')mr++;
if(a[i][0] =='C')mc++;
if(a[i][0] =='H')mh++;
}
int d[]={mm,ma,mr,mc,mh};
sort(d,d+5);
int ans = 0;
int son = d[4];
if(d[3] and d[2]){
ans += d[2] * d[3] * d[4];
}
if(d[0] and d[1]){
ans += d[0] * d[1] * d[4];
}
if(d[0] and d[3]){
ans += d[0] * d[3] * d[4];
}
if(d[1] and d[3]){
ans += d[1] * d[3] * d[4];
}
if(d[1] and d[2]){
ans += d[1]* d[2]*d[4];
}
if(d[3] and d[2] and d[1]){
ans += d[3] * d[2] * d[1];
}
if(d[2] and d[1] and d[0]){
ans += d[2] * d[1] * d[0];
}
cout << ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long sum = 0;
cin >> N;
vector<string> S(N);
vector<int> t(5);
for (int i = 0; i < N; i++) {
cin >> S.at(i);
}
for (int i = 0; i < N; i++) {
if (S.at(i).at(0) == 'M') {
t.at(0)++;
} else if (S.at(i).at(0) == 'A') {
t.at(1)++;
} else if (S.at(i).at(0) == 'R') {
t.at(2)++;
} else if (S.at(i).at(0) == 'C') {
t.at(3)++;
} else if (S.at(i).at(0) == 'H') {
t.at(4)++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
sum += t.at(i) * t.at(j) * t.at(k);
}
}
}
cout << sum << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
unsigned int Return4to3(unsigned int a, unsigned int b, unsigned int c,
unsigned int d) {
return (a * b * c + a * b * d + a * c * d + b * c * d);
}
unsigned int Return5to3(unsigned int a, unsigned int b, unsigned int c,
unsigned int d, unsigned int e) {
return (a * b * c + a * b * d + a * b * e + a * c * d + a * c * e +
a * d * e + b * c * d + b * c * e + b * d * e + c * d * e);
}
int main(void) {
int N, i = 0;
scanf("%d", &N);
char s[10];
unsigned int mi = 0, ai = 0, ri = 0, ci = 0, hi = 0;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (i = 0; i < N; i++) {
scanf(" %s", &s);
if (s[0] == 'M') {
mi++;
m = 1;
}
if (s[0] == 'A') {
ai++;
a = 1;
}
if (s[0] == 'R') {
ri++;
r = 1;
}
if (s[0] == 'C') {
ci++;
c = 1;
}
if (s[0] == 'H') {
hi++;
h = 1;
}
}
if (m + a + r + c + h < 3) {
printf("0\n");
fflush(stdout);
} else if (m + a + r + c + h == 3) {
if (m * a * r == 1) {
printf("%u\n", mi * ai * ri);
fflush(stdout);
} else if (m * a * c == 1) {
printf("%u\n", mi * ai * ci);
fflush(stdout);
} else if (m * a * h == 1) {
printf("%u\n", mi * ai * hi);
fflush(stdout);
} else if (m * r * c == 1) {
printf("%u\n", mi * ci * ri);
fflush(stdout);
} else if (m * r * h == 1) {
printf("%u\n", mi * hi * ri);
fflush(stdout);
} else if (m * c * h == 1) {
printf("%u\n", mi * ci * hi);
fflush(stdout);
} else if (a * r * c == 1) {
printf("%u\n", ci * ai * ri);
fflush(stdout);
} else if (a * r * h == 1) {
printf("%u\n", hi * ai * ri);
fflush(stdout);
} else if (a * c * h == 1) {
printf("%u\n", ci * ai * hi);
fflush(stdout);
} else if (r * c * h == 1) {
printf("%u\n", ri * ci * hi);
fflush(stdout);
}
} else if (m + a + r + c + h == 4) {
if (m * a * r * c == 1) {
printf("%u\n", Return4to3(mi, ai, ri, ci));
fflush(stdout);
} else if (m * a * r * h == 1) {
printf("%u\n", Return4to3(mi, ai, ri, hi));
fflush(stdout);
} else if (m * a * c * h == 1) {
printf("%u\n", Return4to3(mi, ai, ci, hi));
fflush(stdout);
} else if (m * r * c * h == 1) {
printf("%u\n", Return4to3(mi, ci, ri, hi));
fflush(stdout);
} else if (a * r * c * h == 1) {
printf("%u\n", Return4to3(ci, ai, ri, hi));
fflush(stdout);
}
} else if (m + a + r + c + h == 5) {
printf("%u\n", Return5to3(mi, ai, ri, ci, hi));
fflush(stdout);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
ll N, M, K, H, W, L, R, X;
string S, T;
int main() {
string march = "MARCH";
cin >> N;
map<char, int> mp;
for (long long i = 0; i < (int)N; i++) {
string s;
cin >> s;
for (long long j = 0; j < (int)5; j++) {
if (s[0] == march[j]) {
mp[s[0]]++;
break;
}
}
}
ll ans = 0;
ll temp = 1;
int cnt = mp.size();
if (cnt <= 2) {
cout << 0 << endl;
return 0;
} else if (cnt == 3) {
for (auto itr : mp) temp *= itr.second;
cout << temp << endl;
return 0;
} else if (cnt >= 4) {
for (auto itr1 : mp) {
for (auto itr2 : mp) {
if (itr2 <= itr1) continue;
for (auto itr3 : mp) {
if (itr3 <= itr2) continue;
ans += itr1.second * itr2.second * itr3.second;
}
}
}
cout << ans << endl;
return 0;
}
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, count = 0;
long long ans = 0;
int cnt[5] = {0, 0, 0, 0, 0};
char s[11];
cin >> n;
for (int 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 (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k < j; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int c[5];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
;
int n;
while (cin >> n) {
for (int i = 0; i < n; i++) {
string a;
cin >> a;
if (a[0] == 'M') {
c[0]++;
} else if (a[0] == 'A') {
c[1]++;
} else if (a[0] == 'R') {
c[2]++;
} else if (a[0] == 'C') {
c[3]++;
} else if (a[0] == 'H') {
c[4]++;
} else {
continue;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
ans = ans + c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
string S;
for (int i = 0; i < N; i++) {
cin >> S;
if (S.substr(0, 1) == "M") M++;
if (S.substr(0, 1) == "A") A++;
if (S.substr(0, 1) == "R") R++;
if (S.substr(0, 1) == "C") C++;
if (S.substr(0, 1) == "H") H++;
}
cout << M * A * R + M * A * C + M * A * H + M * R * C + M * R * H +
M * C * H + A * R * C + A * R * H + A * C * H + R * C * H
<< endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
map<char, int> mp;
map<char, int>::iterator it;
int n;
string str;
cin >> n;
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') {
mp[str[0]]++;
}
}
if (mp.size() < 3)
cout << "0" << endl;
else {
int a = mp['M'] * mp['A'] * mp['R'] + mp['M'] * mp['A'] * mp['C'] +
mp['M'] * mp['A'] * mp['H'] + mp['M'] * mp['R'] * mp['C'] +
mp['M'] * mp['R'] * mp['H'] + mp['M'] * mp['C'] * mp['H'] +
mp['A'] * mp['R'] * mp['C'] + mp['A'] * mp['R'] * mp['H'] +
mp['A'] * mp['C'] * mp['H'] + mp['R'] * mp['C'] * mp['H'];
cout << a << 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 | use std::io::Read;
use std::collections::HashMap;
fn main() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let answer = solve(&buf);
println!("{}", answer);
}
const ZERO: usize = 0;
fn solve(input: &str) -> String {
let mut iterator = input.split_whitespace();
let march: Vec<char> = "MARCH".chars().collect();
let n: usize = iterator.next().unwrap().parse().unwrap();
let mut counts: HashMap<char, usize> = HashMap::new();
for _ in 0..n {
let first_char = iterator.next().unwrap().chars().next().unwrap();
if march.contains(&first_char) {
*counts.entry(first_char).or_insert(0) += 1;
}
}
let mut ans = 0;
for i in 0..3 {
for j in (i + 1)..4 {
for k in (j + 1)..5 {
let ci = counts.get(&march[i]).unwrap_or(&ZERO);
let cj = counts.get(&march[j]).unwrap_or(&ZERO);
let ck = counts.get(&march[k]).unwrap_or(&ZERO);
ans += *ci * *cj * *ck;
}
}
}
return ans.to_string();
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.