Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int a[5], ans = 0;
for (int i = 0; i < (int)(n); i++) a[i] = 0;
for (int i = 0; i < (int)(n); i++) {
cin >> s;
if (s[0] == 'M') {
a[0]++;
} else if (s[0] == 'A') {
a[1]++;
} else if (s[0] == 'R') {
a[2]++;
} else if (s[0] == 'C') {
a[3]++;
} else if (s[0] == 'H') {
a[4]++;
}
}
ans = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[1] * a[4] +
a[0] * a[2] * a[3] + a[0] * a[2] * a[4] + a[0] * a[3] * a[4] +
a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[3] * a[4] +
a[2] * a[3] * a[4];
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from collections import combinations
n = int(input())
count = {x:0 for x in "MARCH"}
for _ in range(n):
s = input()[0]
if s in count:
count[s] += 1
sum_count = 0
for a, b, c in combinations("MARCH", 3):
sum_count += count[a] * count[b] * count[c]
print(sum_count) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, sum1, sum2, sum3, sum4, sum5, ans;
char a[100001][200];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
if (a[i][0] == 'M') sum1++;
if (a[i][0] == 'A') sum2++;
if (a[i][0] == 'R') sum3++;
if (a[i][0] == 'C') sum4++;
if (a[i][0] == 'H') sum5++;
}
ans += sum1 * sum2 * sum3;
ans += sum1 * sum2 * sum4;
ans += sum1 * sum2 * sum5;
ans += sum1 * sum3 * sum4;
ans += sum1 * sum3 * sum5;
ans += sum1 * sum4 * sum5;
ans += sum2 * sum3 * sum4;
ans += sum2 * sum3 * sum5;
ans += sum2 * sum4 * sum5;
ans += sum3 * sum4 * sum5;
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 N;
string S;
char T[5] = {'M', 'A', 'R', 'C', 'H'};
long C[5] = {0, 0, 0, 0, 0};
cin >> N;
int ans = 0;
for (int i = 0; i < N; i++) {
cin >> S;
for (int j = 0; j < 5; j++) {
if (S[0] == T[j]) C[j] += 1;
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += C[i] * C[j] * C[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int N;
scanf("%d\n", &N);
char S[N + 1];
for (int i = 0; i < N; i++) {
char name[11];
scanf("%s", name);
S[i] = name[0];
}
int M, A, R, C, H;
M = 0, A = 0, R = 0, C = 0, H = 0;
for (int j = 0; j < N; j++) {
switch (S[j]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
H++;
break;
}
}
long x = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H +
M * C * H + A * R * C + A * R * H + A * C * H + R * C * H;
printf("%lo\n", x);
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};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int n;
string s[100005];
char march[] = {'M', 'A', 'R', 'C', 'H'};
int cnt[5];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < (n); ++i) {
cin >> s[i];
for (int j = 0; j < (5); ++j) {
if (march[j] == s[i][0]) cnt[j]++;
}
}
long long ans = 0;
int pair<int, int>[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};
for (int i = 0; i < (10); ++i)
ans += cnt[pair<int, int>[i]] * cnt[Q[i]] * cnt[R[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() {
int n, m = 0, a = 0, r = 0, c = 0, h = 0;
long long ans;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
m++;
} else if (s[0] == 'A') {
a++;
} else if (s[0] == 'R') {
r++;
} else if (s[0] == 'C') {
c++;
} else if (s[0] == 'H') {
h++;
}
}
ans = m * (a * r + a * c + a * h + r * c + r * h + c * h) +
a * (r * c + r * h + 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 | python3 | import sys
import itertools
input = sys.stdin.readline
def main():
common = common_function()
N = int(input())
l = ['M', 'A', 'R', 'C', 'H']
m = [0]*5
for _ in range(N):
S = input()[:-1]
Shead = S[0]
for i, s0 in enumerate(l):
if Shead == s0:
m[i] += 1
break
ll = []
for i, n in enumerate(m):
if n >= 1:
ll.append(l[i])
if len(ll) <= 2:
print(0)
return
ans = 0
for i, j, k in itertools.combinations(ll, 3):
ans += m[l.index(i)] * m[l.index(j)] * m[l.index(k)]
print(ans)
if __name__ == "__main__":
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;
namespace CompetitionPrograming2
{
public sealed class Program : BaseProgram
{
public static void Main(string[] _) { using (new SetConsole()) { Solve(); } }
public static void Solve()
{
var n = GetNumber<int>();
var dic = new Dictionary<char, int>();
var initials = new char[] { 'M', 'A', 'R', 'C', 'H' };
foreach (var item in initials)
{
dic.Add(item, 0);
}
for (int i = 0; i < n; i++)
{
var name = GetString();
if (dic.ContainsKey(name[0]))
{
dic[name[0]]++;
}
}
BigInteger result = 0;
for (int i = 0; i < initials.Length; i++)
{
for (int j = i + 1; j < initials.Length; j++)
{
for (int k = j + 1; k < initials.Length; k++)
{
result += dic[initials[i]] * dic[initials[j]] * dic[initials[k]];
}
}
}
Write(result);
}
}
public abstract class BaseProgram
{
protected readonly static long divisor = 1000000007;
protected static int SafeInf(int margin = 1) => int.MaxValue - Abs(margin);
protected static void Write(object obj) => Console.WriteLine(obj);
protected static string GetString()
{
var str = Console.ReadLine();
if (str == null) { throw new NullReferenceException("標準入力がnullです Solveメソッド内の解答コードが間違っています"); }
return str;
}
protected static T GetNumber<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
{
var str = GetString();
var t = typeof(T);
try
{
if ((t == typeof(byte)))
{
return (T)(object)str.ToByte();
}
else if (t == typeof(int))
{
return (T)(object)str.ToInt();
}
else if (t == typeof(long))
{
return (T)(object)str.ToLong();
}
else if (t == typeof(double))
{
return (T)(object)str.ToDouble();
}
else if (t == typeof(decimal))
{
return (T)(object)str.ToDecimal();
}
else if (t == typeof(BigInteger))
{
return (T)(object)str.ToBigInteger();
}
}
catch (OverflowException)
{
throw new OverflowException("より大きい数値型を指定してください");
}
throw new NotSupportedException();
}
protected static T[] GetArray<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
{
return GetString().ToArray<T>();
}
protected static TResult[] GetArray<TResult>(Func<string, TResult> selector)
{
return (TResult[])(object)GetString().Split().Select(selector).ToArray();
}
protected static void Swap<T>(ref T item1, ref T item2)
{
var tmp = item1;
item1 = item2;
item2 = tmp;
}
protected sealed class SetConsole : IDisposable
{
readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
public SetConsole()
{
sw.AutoFlush = false;
Console.SetOut(sw);
}
public void Dispose()
{
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
}
}
public static class ExtentionsLibrary
{
public static T[,] CopyArray<T>(this T[,] array)
{
var firstDimentionLength = array.GetLength(0);
var secondDimentionLength = array.GetLength(1);
var newDArray = new T[firstDimentionLength, secondDimentionLength];
Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength);
return newDArray;
}
public static T[] ToArray<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
{
if (typeof(T) == typeof(string)) { return (T[])(object)str.Split(); }
return str.ConvertEnumerator<T>().ToArray();
}
public static IEnumerable<T> ConvertEnumerator<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
{
try
{
var t = typeof(T);
if (t == typeof(byte))
{
return (IEnumerable<T>)str.Split().Select(byte.Parse);
}
if (t == typeof(int))
{
return (IEnumerable<T>)str.Split().Select(int.Parse);
}
if (t == typeof(long))
{
return (IEnumerable<T>)str.Split().Select(long.Parse);
}
if (t == typeof(double))
{
return (IEnumerable<T>)str.Split().Select(double.Parse);
}
if (t == typeof(decimal))
{
return (IEnumerable<T>)str.Split().Select(decimal.Parse);
}
if (t == typeof(BigInteger))
{
return (IEnumerable<T>)str.Split().Select(BigInteger.Parse);
}
}
catch (OverflowException)
{
throw new OverflowException("より大きい数値型を指定してください");
}
throw new NotSupportedException();
}
public static byte ToByte(this string str) => byte.Parse(str);
public static byte ToByte(this char chr) => byte.Parse(chr.ToString());
public static int ToInt(this string str) => int.Parse(str);
public static int ToInt(this char chr) => int.Parse(chr.ToString());
public static long ToLong(this string str) => long.Parse(str);
public static double ToDouble(this string str) => double.Parse(str);
public static decimal ToDecimal(this string str) => decimal.Parse(str);
public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
public static string StringJoin(this object[] array, string separator = "") => string.Join(separator, array);
public static string StringJoin<T>(this IEnumerable<T> collection, string separator = "") => string.Join(separator, collection.Select(c => c.ToString()));
public static int LowerBound<T>(this IReadOnlyList<T> a, T v) => LowerBound(a, v, Comparer<T>.Default);
public static int LowerBound<T>(this IReadOnlyList<T> a, T v, Comparer<T> cmp)
{
var l = 0;
var r = a.Count - 1;
while (l <= r)
{
var mid = l + (r - l) / 2;
var result = cmp.Compare(a[mid], v);
if (result == -1)
{
l = mid + 1;
}
else
{
r = mid - 1;
}
}
return l;
}
public static int UpperBound<T>(this IReadOnlyList<T> a, T v) => UpperBound(a, v, Comparer<T>.Default);
public static int UpperBound<T>(this IReadOnlyList<T> a, T v, Comparer<T> cmp)
{
var l = 0;
var r = a.Count - 1;
while (l <= r)
{
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res <= 0) l = mid + 1;
else r = mid - 1;
}
return l;
}
}
public sealed class Settings
{
public enum Priority : byte
{
Smaller = 0,
Larger = 1
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int i, ans = 1, x = 0;
unsigned int ini[5] = {0};
string name[1000000];
cin >> i;
for (; i > 0; i--) {
cin >> name[i];
if (name[i][0] == 'M' || name[i][0] == 'A' || name[i][0] == 'R' ||
name[i][0] == 'C' || name[i][0] == 'H') {
x++;
}
if (name[i][0] == 'M') {
ini[0]++;
}
if (name[i][0] == 'A') {
ini[1]++;
}
if (name[i][0] == 'R') {
ini[2]++;
}
if (name[i][0] == 'C') {
ini[3]++;
}
if (name[i][0] == 'H') {
ini[4]++;
}
}
for (; x > 3; x--) {
ans *= x;
}
ans /= 2;
ans -= ini[0] - ini[1] - ini[2] - ini[3] - ini[4] + 5;
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long jihe(int m, int a, int r, int c, int h) {
int s = 0;
s += m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * c + a * c * h + r * c * h;
return s;
}
int main() {
long long n, s = 0, i;
int m, a, r, c, h;
string x;
for (i = 0; i < n; i++) {
cin >> x;
switch (x[0]) {
case 'M':
m++;
break;
case 'A':
a++;
break;
case 'R':
r++;
break;
case 'C':
c++;
break;
case 'h':
h++;
break;
default:
break;
}
}
s = jihe(m, a, r, c, h);
cout << s << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
long long m, a, r, c, 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++;
}
long long ans = 0;
ans = ans + m * a * r;
ans = ans + m * a * c;
ans = ans + m * a * h;
ans = ans + m * r * c;
ans = ans + m * r * h;
ans = ans + m * c * h;
ans = ans + a * r * c;
ans = ans + a * c * h;
ans = ans + a * r * h;
ans = 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 | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
public static partial class Program
{
//テンプレここから
public static int ToInt(this string str)
{
return int.Parse(str);
}
public static long ToLong(this string str)
{
return long.Parse(str);
}
public static IEnumerable<int> ToInt(this string[] strs)
{
return strs.Select(x => x.ToInt());
}
public static IEnumerable<long> ToLong(this string[] strs)
{
return strs.Select(x => x.ToLong());
}
public static IEnumerable<int> SplToInt(this string str, char opr = ' ')
{
return str.Split(opr).ToInt();
}
public static IEnumerable<long> SplToLong(this string str, char opr = ' ')
{
return str.Split(opr).ToLong();
}
public static string CRL()
{
return Console.ReadLine();
}
public static void CWL(object obj)
{
Console.WriteLine(obj);
}
public static int Diff(int a, int b)
{
return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
}
public static long Diff(long a, long b)
{
return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
}
public static int Sign(this int i)
{
return Math.Sign(i);
}
//テンプレここまで
}
public static partial class Program
{
static void Main()
{
var n = CRL().ToInt();
var strs = new List<string>();
for (int i = 0; i < n; i++)
{
strs.Add(CRL());
}
var counts = new int[5];
const string march = "MARCH";
for (int i = 0; i < 5; i++)
{
counts[i] = strs.Where(x => x[0] == march[i]).Count();
}
var num = 0;
var p = new int[] {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
var q = new int[] {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
var r = new int[] {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
for (int i = 0; i < 10; i++)
{
num += counts[p[i]] * counts[q[i]] * counts[r[i]];
}
CWL(num);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<char, int> name;
string s;
string march = "MARCH";
for (int i = 0; i < (n); i++) {
cin >> s;
bool flg = false;
for (int i = 0; i < (5); i++) {
if (s[0] == march[i]) {
flg = true;
}
}
if (flg) {
name[s[0]]++;
}
}
int cou = 0;
long long int res = 1;
for (pair<char, int> p : name) {
int se = p.second;
if (se) {
cou++;
res *= se;
}
}
if (cou == 3) {
cout << res << endl;
} else if (cou == 4) {
cout << res * 4 << endl;
} else if (cou == 5) {
cout << res * 10 << endl;
} else {
cout << 0 << 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 INF = 1LL << 60;
int main() {
int n;
cin >> n;
vector<string> sv(n);
string s = "MARCH";
set<char> st;
int ans[5] = {};
for (int i = 0; i < n; i++) {
cin >> sv[i];
int tmp = s.find(sv[i][0]);
if (tmp != -1) {
st.insert(s[tmp]);
ans[tmp]++;
}
}
int a = 0;
for (int i = 0; i < 3; i++) {
int tmp = ans[i];
for (int j = i + 1; j != 4; j++) {
int tmp2 = tmp * ans[j];
for (int k = j + 1; k != 5; k++) {
int tmp3 = tmp2 * ans[k];
a += tmp3;
}
}
}
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 | using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
var G = (from _ in Enumerable.Repeat(0, n)
let s = Console.ReadLine()
where s.StartsWith("M") || s.StartsWith("A") || s.StartsWith("R") || s.StartsWith("C") || s.StartsWith("H")
group s by s[0] into g
select g.Count()).ToArray();
long ans = 0;
for (int i = 0; i < G.Length; i++)
{
for (int j = i + 1; j < G.Length; j++)
{
for (int k = j + 1; k < G.Length; k++)
{
ans += G[i] * G[j] * G[k];
}
}
}
Console.WriteLine(ans);
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
char S[100000][11];
int n[5] = {0};
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i][0] == 'M')
n[0]++;
else if (S[i][0] == 'A')
n[1]++;
else if (S[i][0] == 'R')
n[2]++;
else if (S[i][0] == 'C')
n[3]++;
else if (S[i][0] == 'H')
n[4]++;
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += n[i] * n[j] * n[k];
}
}
}
cout << cnt << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1000000000000000;
const long long inf = -1e18;
long long ma = 1000000000 + 7;
long long h, w, n, k, m;
string s, t;
char maze[60][60];
int dis[101][101];
int graph[52][52];
bool vis[52];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long gcd(long long x, long long y) {
if (x % y == 0) return y;
return gcd(y, x % y);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
return a / g * b;
}
int main() {
cin >> n;
vector<int> mo(5);
long long res = 0;
for (long long i = 0; i < n; i++) {
string a;
cin >> a;
if (a[0] == 'M')
mo[0]++;
else if (a[0] == 'A')
mo[1]++;
else if (a[0] == 'R')
mo[2]++;
else if (a[0] == 'C')
mo[3]++;
else if (a[0] == 'H')
mo[4]++;
}
for (int bit = 0; bit < (1 << 5); bit++) {
int bn = 0;
for (long long i = 0; i < 5; i++) {
if (bit & (1 << i)) bn++;
}
if (bn == 3) {
int sum = 1;
for (long long i = 0; i < 5; i++) {
if (bit & (1 << i)) {
sum *= mo[i];
}
}
res += sum;
}
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int translate(char c);
int main() {
int n, initial[6]{};
long long ans{};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char name[16];
scanf("%s", name);
initial[translate(name[0])]++;
}
for (int i = 0; i < n; i++) {
if (!initial[i]) continue;
for (int j = i + 1; j < n; j++) {
if (!initial[j]) continue;
for (int k = j + 1; k < n; k++) {
ans += initial[i] * initial[j] * initial[k];
}
}
}
printf("%lld\n", ans);
return 0;
}
int translate(char c) {
char str[] = "MARCH";
for (int i = 0; i < 5; i++)
if (str[i] == c) return i;
return 5;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("filed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}
fn main() {
let n:usize = read();
let mut arr = vec![0; 5];
for _ in 0..n {
let s:String = read();
match &s[0..1] {
"M" => arr[0] += 1,
"A" => arr[1] += 1,
"R" => arr[2] += 1,
"C" => arr[3] += 1,
"H" => arr[4] += 1,
_ => continue
}
}
let mut ans = 0;
for i in 0..5 {
for j in 0..i {
for k in 0..j {
ans += arr[i] * arr[j] * arr[k];
}
}
}
println!("{}", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int c, r, m, a, h, n;
long long ans;
string s;
c = r = m = a = h = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'C') c++;
if (s[0] == 'R') r++;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'H') h++;
}
ans = (c * r * m + c * r * a + c * r * h + c * m * a + c * m * h + c * a * h +
r * m * a + r * m * h + r * a * h + m * a * h);
printf("%lld", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<string> s(n);
vector<int> vmp(5);
for (long long i = 0; i < (long long)n; ++i) cin >> s[i];
for (long long i = 0; i < (long long)n; ++i) {
if (s[i][0] == 'M') vmp[0]++;
if (s[i][0] == 'A') vmp[1]++;
if (s[i][0] == 'R') vmp[2]++;
if (s[i][0] == 'C') vmp[3]++;
if (s[i][0] == 'H') vmp[4]++;
}
long long ans = 0;
for (long long i = 0; i < (long long)3; ++i) {
for (long long j = i + 1; j < (long long)4; ++j) {
for (long long k = j + 1; k < (long long)5; ++k)
ans += vmp[i] * vmp[j] * vmp[k];
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
int N;
std::cin >> N;
std::vector<int> vs(N);
char march[] = {'M', 'A', 'R', 'C', 'H'};
int marchNum[5] = {0};
for (int i = 0; i < N; i++) {
std::string str;
std::cin >> str;
for (int j = 0; j < 5; j++) {
if (str[0] == march[j]) marchNum[j]++;
}
}
unsigned long comNum = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
comNum += marchNum[i] * marchNum[j] * marchNum[k];
}
}
}
std::cout << comNum << 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, cnt[5] = {0};
long long ans;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
int tmp = 0;
for (int j = 0; j < i; j++) {
if (s[i] == s[j]) tmp = 1;
}
if (tmp == 1) continue;
if (s[i][0] == 'M') cnt[0]++;
if (s[i][0] == 'A') cnt[1]++;
if (s[i][0] == 'R') cnt[2]++;
if (s[i][0] == 'C') cnt[3]++;
if (s[i][0] == 'H') cnt[4]++;
}
ans = cnt[0] * (cnt[1] * (cnt[2] + cnt[3] + cnt[4]) +
cnt[2] * (cnt[3] + cnt[4]) + cnt[3] * cnt[4]) +
cnt[1] * (cnt[2] * (cnt[3] + cnt[4]) + cnt[3] * cnt[4]) +
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 | python3 | n=int(input())
s=list(input() for i in range(n))
m=a=r=c=h=[]
mc=ac=rc=cc=hc=0
ans=1
for i in range(n):
if s[i][0] == "M" and not s[i] in m:
mc+=1
elif s[i][0] == "A" and not s[i] in a:
ac+=1
elif s[i][0] == "R" and not s[i] in r:
rc+=1
elif s[i][0] == "C" and not s[i] in c:
cc+=1
elif s[i][0] == "H" and not s[i] in h:
hc+=1
lis = [mc,ac,rc,cc,hc]
if sum(lis) == 0:
print(0)
else:
for i in range(5):
if lis[i]>0:
ans = ans*lis[i]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
unsigned nChoosek(unsigned n, unsigned k) {
if (k > n) return 0;
if (k * 2 > n) k = n - k;
if (k == 0) return 1;
int result = n;
for (int i = 2; i <= k; ++i) {
result *= (n - i + 1);
result /= i;
}
return result;
}
int main() {
long long n;
cin >> n;
vector<int> v(5, 0);
int sum = 0;
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
char x = s[0];
if (x == 'M') v[0]++;
if (x == 'A') v[1]++;
if (x == 'R') v[2]++;
if (x == 'C') v[3]++;
if (x == 'H') v[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 += v[i] * v[j] * v[k];
}
cout << sum;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import scala.io.StdIn
object Main extends App {
val n = StdIn.readLine().toInt
val linse = (0 until n).map(_ => StdIn.readLine())
val combis = "MARCH".split("").combinations(3).map(p => p.toList.map(_.charAt(0)))
//println(combis.mkString(" "))
val members = linse.filter{p =>
p.charAt(0) == 'M' || p.charAt(0) == 'A' || p.charAt(0) == 'R' || p.charAt(0) == 'C' || p.charAt(0) == 'H'
}.groupBy(name => name.charAt(0)).map(a => a._1 -> a._2.size)
//val combi = members.keys.toList.combinations(3)
//println(combi.mkString(" "))
val result = combis.foldLeft(0L){ (acc, l) =>
acc + (members.get(l(0)).getOrElse(0).toLong *
members.get(l(1)).getOrElse(0).toLong * members.get(l(2)).getOrElse(0).toLong)
}
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 | python3 | N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
s=input()
if s[0]=='M':
M.append(s)
elif s[0]=='A':
A.append(s)
elif s[0]=='R':
R.append(s)
elif s[0]=='C':
C.append(s)
elif s[0]=='H':
H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)
def dif(n):
if cnt[n]==0 or cnt[n]==1:
return 0
else:
a=0
for i in range(5):
if i!=n:
a+=cnt[i]
if cnt[n]==2:
return a
else:
b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
return int(a+b)
for i in range(5):
res-=dif(i)
c=0
for j in range(5):
if cnt[j]==0:
c+=1
if c>2:
print(0)
else:
print(res) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();
void abc089_c(vector<vector<string>> v) {
int n = atoi(v[0][0].c_str());
vector<string> vec;
for (int i = 1; i <= n; i++) {
if (v[i][0].substr(0, 1) == "M" || v[i][0].substr(0, 1) == "A" ||
v[i][0].substr(0, 1) == "R" || v[i][0].substr(0, 1) == "C" ||
v[i][0].substr(0, 1) == "H") {
vec.push_back(v[i][0]);
}
}
map<string, int> m;
for (auto x : vec) {
m[x.substr(0, 1)] += 1;
}
long mysum = 0;
int mcnt = m["M"];
int acnt = m["A"];
int rcnt = m["R"];
int ccnt = m["C"];
int hcnt = m["H"];
mysum += mcnt * acnt * rcnt;
mysum += mcnt * acnt * ccnt;
mysum += mcnt * acnt * hcnt;
mysum += mcnt * rcnt * ccnt;
mysum += mcnt * rcnt * hcnt;
mysum += mcnt * ccnt * hcnt;
mysum += acnt * rcnt * ccnt;
mysum += acnt * rcnt * hcnt;
mysum += acnt * ccnt * hcnt;
mysum += rcnt * ccnt * hcnt;
cout << mysum << endl;
}
int main() {
vector<vector<string>> vec_arr_result;
vec_arr_result = getinputdata();
abc089_c(vec_arr_result);
return 0;
}
vector<vector<double>> getinputdata3() {
string str;
string ret;
stringstream ss;
vector<string> v1;
vector<vector<double>> vec_arr;
while (getline(cin, str)) {
v1.push_back(str);
}
for (string s : v1) {
vector<double> array_data;
ss << s;
while (!ss.eof()) {
ss >> ret;
array_data.push_back(atof(ret.c_str()));
}
vec_arr.push_back(array_data);
ss.str("");
ss.clear(stringstream::goodbit);
}
return vec_arr;
}
vector<vector<int>> getinputdata2() {
string str;
string ret;
stringstream ss;
vector<string> v1;
vector<vector<int>> vec_arr;
while (getline(cin, str)) {
v1.push_back(str);
}
for (string s : v1) {
vector<int> array_data;
ss << s;
while (!ss.eof()) {
ss >> ret;
array_data.push_back(atoi(ret.c_str()));
}
vec_arr.push_back(array_data);
ss.str("");
ss.clear(stringstream::goodbit);
}
return vec_arr;
}
vector<vector<string>> getinputdata() {
string str;
string ret;
stringstream ss;
vector<string> v1;
vector<vector<string>> vec_arr;
while (getline(cin, str)) {
v1.push_back(str);
}
for (string s : v1) {
vector<string> array_data;
ss << s;
while (!ss.eof()) {
ss >> ret;
array_data.push_back(ret);
}
vec_arr.push_back(array_data);
ss.str("");
ss.clear(stringstream::goodbit);
}
return vec_arr;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int arr[25] = { 0 };
while (n--)
{
getchar();
char c[11] = { 0 };
scanf("%s", &c);
if (c[0] == 'M')
arr[0]++;
if (c[0] == 'A')
arr[1]++;
if (c[0] == 'R')
arr[2]++;
if (c[0] == 'C')
arr[3]++;
if (c[0] == 'H')
arr[4]++;
}
long long int ans = 1;
long long int tol = 0;
for (int i = 0; i < 5; i++)
{
if(arr[i]!=0)
tol++;
}
if (tol < 3)
ans = 0ll;
else if (tol == 3)
{
for (int i = 0; i < 5; i++)
{
if (arr[i] != 0)
ans *= arr[i];
}
}
else if (tol == 4)
{
ans--;
int tep[3] = { 0 };
int t=0;
for (int i = 0; i < 5; i++)
{
if (arr[i] != 0)
tep[t++] = arr[i];
}
ans += tep[0] * tep[1] * tep[2];
ans += tep[0] * tep[1] * tep[3];
ans +=tep[1] * tep[2] * tep[3];
ans += tep[0] * tep[3] * tep[2];
}
else {
ans--;
int tep[4] = { 0 };
int t;
for (int i = 0; i < 5; i++)
{
if (arr[i] != 0)
tep[t++] = arr[i];
}
ans += tep[0] * tep[1] * tep[2];
ans += tep[0] * tep[1] * tep[3];
ans += tep[0] * tep[1] * tep[4];
ans += tep[1] * tep[2] * tep[3];
ans += tep[4] * tep[2] * tep[3];
ans += tep[0] * tep[3] * tep[2];
ans += tep[0] * tep[4] * tep[2];
ans += tep[1] * tep[3] * tep[4];
ans += tep[1] * tep[2] * tep[4];
ans += tep[0] * tep[3] * tep[4];
}
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 | java | import java.util.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N;
int M=0,A=0,R=0,C=0,H=0;
ArrayList<Integer> numlist = new ArrayList<>();
N = sc.nextInt();
for (int a = 0; a < N; a++) {
String name = sc.next();
if(name.indexOf('M')==0){
M++;
}
else if(name.indexOf('A')==0){
A++;
}
else if(name.indexOf('R')==0){
R++;
}
else if(name.indexOf('C')==0){
C++;
}
else if(name.indexOf('H')==0){
H++;
}
}
numlist.add(M);
numlist.add(A);
numlist.add(R);
numlist.add(C);
numlist.add(H);
int num =0;
for(int a=0;a<3;a++){
for(int b=a+1;b<4;b++){
for(int c=b+1;c<5;c++){
if(numlist.get(a)!=0&&numlist.get(b)!=0&&numlist.get(c)!=0)
num =+(numlist.get(a)*numlist.get(b)*numlist.get(c));
}
}
}
System.out.println(num);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, sum = 0;
string s;
cin >> n;
vector<int> v(6);
for (int i = 0; i < n; i++) {
cin >> s;
if (s.substr(0, 1) == "M") v.at(0)++;
if (s.substr(0, 1) == "A") v.at(1)++;
if (s.substr(0, 1) == "R") v.at(2)++;
if (s.substr(0, 1) == "C") v.at(3)++;
if (s.substr(0, 1) == "H") v.at(4)++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
sum += v.at(i) * v.at(j) * v.at(k);
}
}
}
cout << sum << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 1e9;
const long long LLINF = 1e18;
using namespace std;
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int N;
string second[10101];
set<string> st[5];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> second[i];
if (second[i][0] == 'M') {
st[0].insert(second[i]);
} else if (second[i][0] == 'A') {
st[1].insert(second[i]);
} else if (second[i][0] == 'R') {
st[2].insert(second[i]);
} else if (second[i][0] == 'C') {
st[3].insert(second[i]);
} else if (second[i][0] == 'H') {
st[4].insert(second[i]);
}
}
long long ans = 0LL;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
long long tans = (long long)st[i].size() * (long long)st[j].size() *
(long long)st[k].size();
ans += tans;
}
}
}
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 {
@SuppressWarnings("resource")
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int march[] = new int[5];
for (int i = 0; i < n; i++) {
String s = scanner.next();
if (s.charAt(0) == 'M')
march[0]++;
else if (s.charAt(0) == 'A')
march[1]++;
else if (s.charAt(0) == 'R')
march[2]++;
else if (s.charAt(0) == 'C')
march[3]++;
else if (s.charAt(0) == 'H')
march[4]++;
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
cnt += (march[i] * march[j] * march[k]);
}
}
}
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;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
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; }
template<class T> inline auto __lcm(T& a, T& b)
{ return a * b / __gcd(a, b); }
int main() {
int N; cin >> N;
vector<string> S(N); rep(i, N) cin >> S[i];
string march = "MARCH";
vector<int> cnt(5, 0);
rep(i, N) {
rep(j, 5) {
if (march[j] == S[i][0]) {
++cnt[j];
}
}
}
ll ans = 0;
rep(i, 5) {
REP(j, i+1, 5) {
REP(k, j+1, 5) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
print(ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return b >= a ? a : b; }
int sei(int a) { return a > 0 ? a : 0; }
int factorial(int n) {
if (n > 0)
return n * factorial(n - 1);
else
return 1;
}
int compare_up_int(const void *a, const void *b) {
return *(int *)a - *(int *)b;
}
int compare_down_int(const void *a, const void *b) {
return *(int *)b - *(int *)a;
}
int euclid(int a, int b) {
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
int r = a % b;
if (r < 0) r += b;
while (r != 0) {
a = b;
b = r;
r = a % b;
if (r < 0) r += b;
}
return b;
}
int main() {
long int N, count = 0, c[5] = {0, 0, 0, 0, 0};
scanf("%ld", &N);
char s[N];
for (int i = 0; i < N; i++) scanf("%s\n", &s[i]);
for (int i = 0; i < N; i++) {
if (s[i] == 'M')
c[0] += 1;
else if (s[i] == 'A')
c[1] += 1;
else if (s[i] == 'R')
c[2] += 1;
else if (s[i] == 'C')
c[3] += 1;
else if (s[i] == 'H')
c[4] += 1;
}
count += c[0] * c[1] * c[2];
count += c[0] * c[1] * c[3];
count += c[0] * c[1] * c[4];
count += c[0] * c[2] * c[3];
count += c[0] * c[2] * c[4];
count += c[0] * c[3] * c[4];
count += c[1] * c[2] * c[3];
count += c[1] * c[2] * c[4];
count += c[1] * c[3] * c[4];
count += c[2] * c[3] * c[4];
printf("%d", count);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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() {
int n;
cin >> n;
int m, a, r, c, h = 0;
for (int i = 0; i < n; i++) {
string name;
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++;
}
}
long long result = 0;
int v[5] = {m, a, r, c, h};
for (int i = 0; i < 10; i++) {
result += v[P[i]] * v[Q[i]] * v[R[i]];
}
cout << result << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 0, c = 0, h = 0, m = 0, r = 0;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'A')
a++;
else if (s[0] == 'C')
c++;
else if (s[0] == 'H')
h++;
else if (s[0] == 'M')
m++;
else if (s[0] == 'R')
r++;
}
long long ans = 0;
ans += a * (c * h + c * m + c * r + h * m + h * r + m * r) +
c * (h * m + h * r + m * r) + h * m * r;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from collections import Counter
from itertools import combinations
n = int(input())
s = [input()[0] for _ in range(n)]
lc = Counter(s)
print(lc)
con = []
for c in 'MARCH':
if c in lc:
con.append(lc[c])
ans = 0
for a, b, c in combinations(con, 3):
ans += a * b * c
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() {
unsigned int i, ans = 1, x = 0;
unsigned int ini[5] = {0};
string name[1000000];
cin >> i;
for (; i > 0; i--) {
cin >> name[i];
if (name[i][0] == 'M' || name[i][0] == 'A' || name[i][0] == 'R' ||
name[i][0] == 'C' || name[i][0] == 'H') {
x++;
}
if (name[i][0] == 'M') {
ini[0]++;
}
if (name[i][0] == 'A') {
ini[1]++;
}
if (name[i][0] == 'R') {
ini[2]++;
}
if (name[i][0] == 'C') {
ini[3]++;
}
if (name[i][0] == 'H') {
ini[4]++;
}
}
for (; x > 3; x--) {
ans *= x;
}
ans /= 2;
for (int j = 0; j < 5; j++) {
if (ini[j] > 1) ans -= 3;
}
cout << ans;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] march = new int[5];
for (int i = 0; i < n; i++) {
String s = br.readLine();
if (s.charAt(0) == 'M') march[0]++;
if (s.charAt(0) == 'A') march[1]++;
if (s.charAt(0) == 'R') march[2]++;
if (s.charAt(0) == 'C') march[3]++;
if (s.charAt(0) == 'H') march[4]++;
}
long 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 += (long)march[i]*march[j]*march[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;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++)
os << v[i] << (i + 1 != v.size() ? " " : "");
return os;
}
template <int mod>
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod) {
x -= mod;
}
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod) {
x -= mod;
}
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0;
while (b > 0) {
int t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while (n > 0) {
if (n & 1) {
res *= mul;
}
mul *= mul;
n >>= 1;
}
return res;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<MOD>;
void solve() {
int n;
cin >> n;
map<char, ll> mp;
const string key = "MARCH";
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < key.size(); j++) {
if (s.front() == key[j]) mp[s.front()]++;
}
}
modint ans = 0;
int test = 0;
for (int bit = 0; bit < (1 << (int)key.size()); bit++) {
if (__builtin_popcount(bit) != 3) continue;
modint cnt = 1;
for (int i = 0; i < key.size(); i++) {
if (bit & (1 << i)) cnt *= (ll)mp[key[i]];
}
ans += cnt;
test++;
}
assert(test == 10);
cout << ans << endl;
}
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
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();
if(S.charAt(0) == 'M')
march[0] += 1;
if(S.charAt(0) == 'A')
march[1] += 1;
if(S.charAt(0) == 'R')
march[2] += 1;
if(S.charAt(0) == 'C')
march[3] += 1;
if(S.charAt(0) == 'H')
march[4] += 1;
}
long ans = 0;
for(int i = 0; i < 3; i++) {
for(int j = i+1; j < 4; j++) {
for(int k = j+1; k < 5; k++)
ans += march[i]*march[j]*march[k];
}
}
System.out.println(ans);
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const long long LINF = 1e18;
long long int n, cnt = 0, ans = 0, a = 0, b, c = 0, cmp, cmpp, cmppp, qq, data,
m = 0, h = 0, w, x, xx, xxx, xxxx, xxxxx, y, xcmp, ycmp,
sum = 0, r = 0;
string s;
vector<int> z;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
cmp = n;
cmpp = n;
for (long long int(i) = 0; (i) < (int)(n); (i)++) {
cin >> s;
if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
s[0] != 'H') {
cmp--;
cmpp--;
}
if (s[0] == 'M') {
m++;
x = 1;
} else if (s[0] == 'A') {
a++;
xx = 1;
} else if (s[0] == 'R') {
r++;
xxx = 1;
} else if (s[0] == 'C') {
c++;
xxxx = 1;
} else if (s[0] == 'H') {
h++;
xxxxx = 1;
}
}
cmppp = x + xx + xxx + xxxx + xxxxx;
if (cmppp < 3) {
cout << (0) << endl;
return 0;
}
if (m != 1 && m != 0) {
cnt = m;
qq += cmpp - m;
}
if (a != 1 && a != 0) {
cnt += a;
qq = cmpp - a;
}
if (r != 1 && r != 0) {
cnt += r;
qq += cmpp - r;
}
if (c != 1 && c != 0) {
cnt += c;
qq += cmpp - c;
}
if (h != 1 && h != 0) {
cnt += h;
qq += cmpp - h;
}
if (cmp * (cmp - 1) % 6 == 0) {
cmp = ((cmp * (cmp - 1)) / 6) * (cmp - 2);
} else {
cmp = (cmp * (((cmp - 1) * (cmp - 2)) / 6));
}
cout << (cmp - qq) << 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;
int N;
long long m, a, r, c, h;
long long D[5];
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
scanf("% d ", &N);
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
long long res = 0;
for (int d = 0; d < 10; d++) res += D[P[d]] * D[Q[d]] * D[R[d]];
printf("% lld \n ", res);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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+1)%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 | cpp | #include <bits/stdc++.h>
using namespace std;
int n, v[6], sol;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
v[1]++;
}
if (s[0] == 'A') {
v[2]++;
}
if (s[0] == 'R') {
v[3]++;
}
if (s[0] == 'C') {
v[4]++;
}
if (s[0] == 'H') {
v[5]++;
}
}
for (int i = 1; i <= 3; i++) {
for (int j = i + 1; j <= 4; j++) {
for (int k = j + 1; k <= 5; k++) {
sol += v[i] * v[j] * v[k];
}
}
}
cout << sol;
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;
char p;
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (int i = 0; i < N; i++) {
cin >> s;
p = s.at(0);
if (p == 'M') {
m++;
} else if (p == 'A') {
a++;
} else if (p == 'R') {
r++;
} else if (p == 'C') {
c++;
} else if (a == 'H') {
h++;
}
}
cout << m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + a * c * h + r * c * h
<< endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, b[5] = {}, ans = 0;
string s;
char a[5] = {'M', 'A', 'R', 'C', 'H'};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < 5; j++)
if (s[0] == a[j]) b[j]++;
}
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 += b[i] * b[j] * b[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
int cou[5];
char check[5] = {'M', 'A', 'R', 'C', 'H'};
for (int i = 0; i < 5; i++) {
cou[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 5; j++) {
if (s[i][0] == check[j]) {
cou[j]++;
}
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int m = 0; m < 5; m++) {
if (j == m || i == m || i == j) {
continue;
} else {
ans += cou[i] * cou[j] * cou[m];
}
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 1, m = 0, a = 0, r = 0, c = 0, h = 0, f = 0;
string s;
for (int i = 1; i <= n + 1; i++) {
getline(cin, s);
s = s[0];
if (s == "M") m++;
if (s == "A") a++;
if (s == "R") r++;
if (s == "C") c++;
if (s == "H") h++;
}
if (m != 0) sum *= m;
if (a != 0) sum *= a;
if (r != 0) sum *= r;
if (c != 0) sum *= c;
if (h != 0) sum *= h;
if (m != 0) f = 1;
if (a != 0) f = 1;
if (r != 0) f = 1;
if (c != 0) f = 1;
if (h != 0) f = 1;
if (f == 0)
cout << 0;
else
cout << sum;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, cm = 0, ca = 0, cr = 0, cc = 0, ch = 0, f = 0;
cin >> n;
vector<string> data(n);
for (int i = 0; i < n; i++) {
cin >> data.at(i);
}
for (int i = 0; i < data.size(); i++) {
if (data.at(i).at(0) == 'M') {
cm++;
} else if (data.at(i).at(0) == 'A') {
ca++;
} else if (data.at(i).at(0) == 'R') {
cr++;
} else if (data.at(i).at(0) == 'C') {
cc++;
} else if (data.at(i).at(0) == 'H') {
ch++;
}
}
long long ans;
ans = cm * ca * cr + cm * ca * cc + cm * ca * ch + cm * cr * cc +
cm * cr * ch + cm * cc * ch + ca * cr * cc + ca * cr * ch +
ca * cc * ch + cr * cc * ch;
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 init(int* a) {
for (int i = 0; i < sizeof(a) / sizeof(int); i++) {
a[i] = 0;
}
}
int main() {
int n;
long long int ans = 0;
int mch[5];
cin >> n;
string name[n];
for (int i = 0; i < sizeof(mch) / sizeof(int); i++) {
mch[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> name[i];
if (name[i][0] == 'M') {
mch[0]++;
} else if (name[i][0] == 'A') {
mch[1]++;
} else if (name[i][0] == 'R') {
mch[2]++;
} else if (name[i][0] == 'C') {
mch[3]++;
} else if (name[i][0] == 'H') {
mch[4]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
ans += mch[i] * mch[j] * mch[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 999999999999999;
ll kaijo(ll n) {
if (n == 0) return 1;
return n * kaijo(n - 1);
}
int main() {
ll n;
cin >> n;
string m = "MARCH";
vector<ll> cnt(5);
vector<string> s(n);
map<char, bool> chek;
for (ll i = 0; i < n; ++i) {
cin >> s.at(i);
for (ll j = 0; j < 5; ++j) {
if (s.at(i).at(0) == m.at(j)) {
cnt.at(j)++;
chek[m.at(j)] = true;
}
}
}
ll num = chek.size();
if (num < 3) {
cout << 0 << endl;
return 0;
}
ll ans = kaijo(num) / kaijo(3) / kaijo(num - 3);
for (ll i = 0; i < 5; ++i) {
if (cnt.at(i) > 1) {
ans += kaijo(num - 1) / kaijo(2) / kaijo(num - 1 - 2) * (cnt.at(i) - 1);
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
static int[] f = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
static int[] s = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
static int[] t = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int[] count = new int[5];
for (int i = 0; i < N; i++) {
String S = in.next();
if (S.charAt(0) == 'M') {
count[0]++;
}
if (S.charAt(0) == 'A') {
count[1]++;
}
if (S.charAt(0) == 'R') {
count[2]++;
}
if (S.charAt(0) == 'C') {
count[3]++;
}
if (S.charAt(0) == 'H') {
count[4]++;
}
}
int ans = 0;
for (int i = 0; i < 10; i++) {
ans += count[f[i]] * count[s[i]] * count[t[i]];
}
System.out.println(ans);
in.close();
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
name=[]
for i in range(N):
name.append(input())
M=0
A=0
R=0
C=0
H=0
letters=['M','A','R','C','H']
for i in range(N):
for j in letters:
if name[i][0]==j:
if j=='M':
M+=1
elif j=='A':
A+=1
elif j=='R':
R+=1
elif j=='C':
C+=1
elif j=='H':
H+=1
counter=0
if M==0:
M+=1
counter+=1
if A==0:
A+=1
counter+=1
if C==0:
C+=1
counter+=1
if R==0:
R+=1
counter+=1
if H==0:
H+=1
counter+=1
counter=5-counter
if counter<3:
print(0)
exit()
print(counter*(counter-1)*(counter-2)//6*M*A*C*R*H) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int march[5] = {0, 2, 7, 12, 17};
int main() {
int N;
cin >> N;
int name[26] = {};
string S;
for (int i = 0; i < N; i++) {
cin >> S;
name[int(S[0]) - 65] += 1;
}
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 += name[march[i]] * name[march[j]] * name[march[k]];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
long long dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
pair<long long, long long> a[99000];
long long d[99000];
long long ans[100000];
signed main() {
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 | python3 | from itertools import combinations
N = int(input())
answer_list = set(['M', 'A', 'R', 'C', 'H'])
name_count = []
for i in range(N):
name = input()
if name[0] in answer_list:
name_count.append(name[0])
result = list([1 for x in combinations(
name_count, 3) if len(set(x)) == len(x)])
print(sum(result))
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]
for name in name_list:
if name[0] in char_list:
count_list[char_list.index(name[0])] += 1
score = 1
flag= False
for x in count_list:
if x != 0:
flag = True
score *= x
if flag is True:
print(score)
else:
print("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 double EPS = 1e-10;
const double PI = acos(-1);
const long long INF = 1 << 30;
int main(int argc, char* argv[]) {
int n;
std::vector<int> march(5, 0);
std::cin >> n;
for (int i = 0; i < n; i++) {
std::string str;
std::cin >> str;
if (str[0] == 'M') {
march[0]++;
}
if (str[0] == 'A') {
march[1]++;
}
if (str[0] == 'R') {
march[2]++;
}
if (str[0] == 'C') {
march[3]++;
}
if (str[0] == 'H') {
march[4]++;
}
}
int size = march.size();
int cnt = 0;
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
for (int k = j + 1; k < size; k++) {
cnt += march[i] * march[j] * march[k];
}
}
}
std::cout << cnt << 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() {
string s = "MARCH";
int cnt[5] = {0};
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
for (int j = 0; j < 5; j++) {
if (t[0] == s[j]) cnt[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 += (cnt[i] * cnt[j] * cnt[k]);
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m_n = 0, a_n = 0, r_n = 0, c_n = 0, h_n = 0;
char name[15];
scanf("%d", &n);
while (n--) {
scanf("%s", name);
if (name[0] == 'M' || name[0] == 'm')
m_n++;
else if (name[0] == 'A' || name[0] == 'a')
a_n++;
else if (name[0] == 'R' || name[0] == 'r')
r_n++;
else if (name[0] == 'C' || name[0] == 'c')
c_n++;
else if (name[0] == 'H' || name[0] == 'h')
h_n++;
}
long long ans = 0;
ans += (long long)(m_n * a_n * (r_n + c_n + h_n));
ans += (long long)(m_n * r_n * (c_n + h_n));
ans += (long long)(m_n * c_n * h_n);
ans += (long long)(a_n * r_n * (c_n + h_n));
ans += (long long)(a_n * c_n * h_n);
ans += (long long)(r_n * c_n * h_n);
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 long MOD = 1e9 + 7;
int main() {
long n, m;
cin >> n;
vector<long> v(5, 0);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s[0] == 'M') v[0]++;
if (s[0] == 'A') v[1]++;
if (s[0] == 'R') v[2]++;
if (s[0] == 'C') v[3]++;
if (s[0] == 'H') v[4]++;
}
long count = 0;
for (int i = 0; i < 3; ++i) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
count += v[i] * v[j] * v[k];
count %= MOD;
}
}
}
cout << count << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned n;
cin >> n;
unsigned counts[5] = {};
char cur;
string str;
for (unsigned i = 0; i < n; i++) {
cin >> str;
cur = str.c_str()[0];
switch (cur) {
case 'M':
counts[0]++;
break;
case 'A':
counts[1]++;
break;
case 'R':
counts[2]++;
break;
case 'C':
counts[3]++;
break;
case 'H':
counts[4]++;
break;
default:
break;
}
}
unsigned long long int total = 0;
for (unsigned i = 0; i < 3; i++) {
for (unsigned j = i + 1; j < 4; j++) {
for (unsigned k = j + 1; k < 5; k++) {
total += counts[i] * counts[j] * counts[k];
}
}
}
cout << total << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
bool isprime(int p) {
if (p == 1) return false;
for (int i = (2); i < (p); ++i) {
if (p % i == 0) return false;
}
return true;
}
int main() {
int n, a[5];
long t;
cin >> n;
string s;
for (int i = (0); i < (5); ++i) {
a[i] = 0;
}
for (int i = (0); i < (n); ++i) {
cin >> s;
for (int j = (0); j < (5); ++j) {
if (s[0] == "MARCH"[j]) a[j]++;
}
}
if ((a[0] > 0) + (a[1] > 0) + (a[2] > 0) + (a[3] > 0) + (a[4] > 0) < 3) {
cout << 0;
return 0;
}
t = 0;
for (int i = (0); i < (3); ++i) {
for (int j = (1); j < (4); ++j) {
for (int k = (2); k < (5); ++k) {
if (i < j && j < k) {
t += a[i] * a[j] * a[k];
}
}
}
}
cout << t;
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 asc(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int desc(const void *a, const void *b) { return *(int *)b - *(int *)a; }
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
return a / g * b;
}
long long fac(long long n) {
if (n > 0) {
return n * fac(n - 1);
} else {
return 1;
}
}
int main() {
long long n, ans = 0;
cin >> n;
vector<int> cnt(n, 0);
string s;
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) < (n - 2); ++(i)) {
for (int(j) = (i + 1); (j) < (n - 1); ++(j)) {
for (int(k) = (j + 1); (k) < (n); ++(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;
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10 = 1024, X11 = 2048, X12 = 4096, X13 = 8196, X14 = 16392,
X15 = 32786, X16 = 65536, X17 = 131072, X18 = 262144, X19 = 524288,
X20 = 1048576;
const int MOD = (int)(1e9 + 7);
template <typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2) {
if (first1 == last1 || first2 == last2) return;
FI next = first2;
while (first1 != next) {
std::iter_swap(first1++, next++);
if (first1 == last1) first1 = first2;
if (next == last2) {
next = first2;
} else if (first1 == first2) {
first2 = next;
}
}
}
template <typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2) {
if (first1 == last1 || first2 == last2) return false;
auto target = last1;
--target;
auto last_elem = last2;
--last_elem;
while (target != first1 && !(*target < *last_elem)) --target;
if (target == first1 && !(*target < *last_elem)) {
parted_rotate(first1, last1, first2, last2);
return false;
}
auto next = first2;
while (!(*target < *next)) ++next;
std::iter_swap(target++, next++);
parted_rotate(target, last1, next, last2);
return true;
}
template <typename BI>
inline bool next_combination(BI first, BI mid, BI last) {
return next_combination_imp(first, mid, mid, last);
}
template <typename BI>
inline bool prev_combination(BI first, BI mid, BI last) {
return next_combination_imp(mid, last, first, mid);
}
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int A[5];
void _() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s[0] == 'M') A[0]++;
if (s[0] == 'A') A[1]++;
if (s[0] == 'R') A[2]++;
if (s[0] == 'C') A[3]++;
if (s[0] == 'H') A[4]++;
}
long long sum = 0;
for (__typeof(5) i = (0); i != (5); i += 1 - 2 * ((0) > (5)))
for (__typeof(5) j = (i + 1); j != (5); j += 1 - 2 * ((i + 1) > (5)))
for (__typeof(5) k = (j + 1); k != (5); k += 1 - 2 * ((j + 1) > (5)))
sum += A[i] * A[j] * A[k];
cout << sum << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
_();
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 Graph = vector<vector<int>>;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
map<char, int> mp;
int num = 0;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
mp[s[0]]++;
num++;
}
}
ll total = 0;
for (const auto& [key, value] : mp) {
if (value >= 2) total += value * (value - 1) * (num - value) / 2;
}
ll f = num * (num - 1) * (num - 2) / 6;
cout << f - total << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
int num[5] = {0};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
num[0]++;
} else if (s[0] == 'A') {
num[1]++;
} else if (s[0] == 'R') {
num[2]++;
} else if (s[0] == 'C') {
num[3]++;
} else if (s[0] == 'H') {
num[4]++;
}
}
long long ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += num[i] * num[j] * num[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
string X = "MARCH";
int S[5] = {};
int n;
long long ans = 0LL;
string input;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> input;
auto x = X.find(input[0]);
if (x == string::npos) continue;
S[x]++;
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += (S[i] * S[j] * S[k] * 1LL);
}
}
}
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> vec(5);
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S.at(0) == 'M') vec[0]++;
if (S.at(0) == 'A') vec[1]++;
if (S.at(0) == 'R') vec[2]++;
if (S.at(0) == 'C') vec[3]++;
if (S.at(0) == 'H') vec[4]++;
}
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
if (vec[2] == 0) {
cout << 0 << endl;
} else if (vec[3] == 0) {
cout << vec[0] * vec[1] * vec[2] << endl;
} else if (vec[4] == 0) {
cout << vec[0] * vec[1] * vec[2] + vec[0] * vec[1] * vec[3] +
vec[0] * vec[3] * vec[2] + vec[3] * vec[1] * vec[2]
<< endl;
} else {
cout << vec[2] * vec[3] * vec[4] + vec[1] * vec[3] * vec[4] +
vec[4] * vec[1] * vec[2] + vec[3] * vec[1] * vec[2] +
vec[2] * vec[3] * vec[0] + vec[1] * vec[3] * vec[4] +
vec[4] * vec[0] * vec[2] + vec[3] * vec[0] * vec[4] +
vec[1] * vec[0] * vec[4] + vec[1] * vec[0] * vec[3] +
vec[1] * vec[0] * vec[2]
<< endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s[0] == 'M') {
++m;
}
if (s[0] == 'A') {
++a;
}
if (s[0] == 'R') {
++r;
}
if (s[0] == 'C') {
++c;
}
if (s[0] == 'H') {
++h;
}
}
long long ans = 0;
ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h +
a * r * c + a * r * h + a * c * h + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int m = 0, a = 0, r = 0, c = 0, h = 0;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (S[0] == 'M')
m++;
else if (S[0] == 'A')
a++;
else if (S[0] == 'R')
r++;
else if (S[0] == 'C')
c++;
else if (S[0] == 'H')
h++;
else
continue;
}
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 + r * c * h + a * 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 | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
int n = 0;
char c = 0;
char name[16] = "";
long long names[5] = {};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", name);
switch (*name) {
case 'M':
names[0]++;
break;
case 'A':
names[1]++;
break;
case 'R':
names[2]++;
break;
case 'C':
names[3]++;
break;
case 'H':
names[4]++;
break;
}
}
long long sum = 0;
for (int i = 0; i <= 2; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = j + 1; k <= 4; k++) {
sum += names[i] * names[j] * names[k];
printf("%d %d %d\n", i, j, k);
}
}
}
printf("%lld\n", sum);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long dint n;
string s[100000];
long long int matching_num=0;
long long int num[5];
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];
}
for(int i=0;i<n;i++) {num[i]=0;}
for(int i=0;i<n;i++){
if(s[i][0]=='M'){
num[0]+=1;
}
else if(s[i][0]=='A'){
num[1]+=1;
}
else if(s[i][0]=='R'){
num[2]+=1;
}
else if(s[i][0]=='C'){
num[3]+=1;
}
else if(s[i][0]=='H'){
num[4]+=1;
}
}
for(int i=0;i<5;i++){
for(int j=i+1;j<5;j++){
for(int k=j+1;k<5;k++){
matching_num+=num[i]*num[j]*num[k];
}
}
}
cout<<matching_num<<endl;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long Factorial(long long k) {
int ans = 1;
for (int i = 1; i <= k; i++) ans *= i;
return ans;
}
long long nPk(long long n, long long k) {
int ans = 1;
for (int i = n - k + 1; i <= n; i++) ans *= i;
return ans;
}
long long nCk(long long n, long long k) { return nPk(n, k) / Factorial(k); }
int main() {
long long int N;
string S[100001];
cin >> N;
for (int i = 0; i < N; i++) cin >> S[i];
long long int cnt[5] = {0};
for (int i = 0; i < N; i++) {
if (S[i][0] == 'M')
cnt[0]++;
else if (S[i][0] == 'A')
cnt[1]++;
else if (S[i][0] == 'R')
cnt[2]++;
else if (S[i][0] == 'C')
cnt[3]++;
else if (S[i][0] == 'H')
cnt[4]++;
}
long long int ans = 1, c = 0;
for (int i = 0; i < 5; i++) {
if (cnt[i] != 0)
ans *= cnt[i];
else
c++;
}
if (2 < c)
cout << "0" << endl;
else {
int n;
n = 5 - c;
if (n < 4) {
cout << ans << endl;
} else {
ans *= nCk(n, 3);
for (int i = 0; i < 5; i++) {
if (cnt[i] != 0) ans -= (cnt[i] - 1);
}
cout << ans << endl;
}
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String s[] = new String[N];
Map<Character, Long> map = new HashMap<>();
map.put('M', 0L);
map.put('A', 0L);
map.put('R', 0L);
map.put('C', 0L);
map.put('H', 0L);
for (int i = 0; i < N; i++) {
char c = sc.next().charAt(0);
if (map.containsKey(c)) {
map.put(c, map.get(c)+1);
}
}
int cnt = 0;
int idx = 0;
ArrayList<Long> w = new ArrayList<>();
for (Entry<Character, Long> e : map.entrySet()) {
if (e.getValue()!=0) {
w.add(e.getValue());
cnt++;
idx++;
}
}
if (cnt<=2) {
System.out.println(0);
return;
}
long ans = 0;
if (cnt == 3) {
for (int i = 0; i < w.size(); i++) {
ans *= w.get(i);
}
System.out.println(ans);
return;
}
if (cnt == 4) {
long tmp = 1;
for (int i = 0; i < w.size(); i++) {
tmp *= w.get(i);
}
for (int i = 0; i < w.size(); i++) {
ans += tmp/w.get(i);
}
System.out.println(ans);
}
if (cnt == 5) {
long tmp = 1;
for (int i = 0; i < w.size(); i++) {
tmp *= w.get(i);
}
long d[] = new long[10];
int index = 0;
for (int i = 0; i < w.size(); i++) {
for (int j = 0; j < w.size(); j++) {
if (i<=j) {
break;
}
d[index] = w.get(i)*w.get(j);
index++;
}
}
for (int i = 0; i < d.length; i++) {
ans += tmp/d[i];
}
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, m = 0, a = 0, r = 0, c = 0, h = 0;
long long int ans = 0;
string S[1000000];
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 | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[7];
for (int i = 0; i <= 6; ++i) a[i] = 0;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
if (s[0] == 'M') a[1]++;
if (s[0] == 'A') a[2]++;
if (s[0] == 'R') a[3]++;
if (s[0] == 'C') a[4]++;
if (s[0] == 'H') a[5]++;
}
vector<pair<int, int> > v;
if (a[1]) v.push_back({1, a[1]});
if (a[2]) v.push_back({2, a[2]});
if (a[3]) v.push_back({3, a[3]});
if (a[4]) v.push_back({4, a[4]});
if (a[5]) v.push_back({5, a[5]});
long long ans = 0;
if ((int)v.size() < 3) {
cout << 0 << '\n';
return 0;
}
int perm = 0;
do {
++perm;
ans += ((1LL * v[0].second) * (1LL * v[1].second) * (1LL * v[2].second));
} while (next_permutation((v).begin(), (v).end()));
ans /= 6LL;
cout << ans << '\n';
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
int nf[5] = {0, 0, 0, 0, 0};
for (int i = 0, i_len = (N); i < i_len; ++i) {
string s;
cin >> s;
switch (s[0]) {
case 'M':
nf[0]++;
break;
case 'A':
nf[1]++;
break;
case 'R':
nf[2]++;
break;
case 'C':
nf[3]++;
break;
case 'H':
nf[4]++;
break;
default:;
}
}
long long int ans = 0;
for (int i = 0, i_len = (N - 2); i < i_len; ++i)
for (int j = (i + 1), j_len = (N - 1); j < j_len; ++j)
for (int k = (j + 1), k_len = (N); k < k_len; ++k) {
ans += (long long int)nf[i] * nf[j] * nf[k];
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string str("MRACH");
vector<string> name(N);
int countM = 0;
int countR = 0;
int countA = 0;
int countC = 0;
int countH = 0;
int all;
for (int i = 0; i < N; i++) {
cin >> name.at(i);
char I = name.at(i).at(0);
for (int j = 0; j < 5; j++) {
if (I == str.at(j)) {
countM++;
} else if (I == str.at(j)) {
countR++;
} else if (I == str.at(j)) {
countA++;
} else if (I == str.at(j)) {
countC++;
} else if (I == str.at(j)) {
countH++;
}
}
if (countM == 0) {
countM++;
} else if (countR == 0) {
countR++;
} else if (countA == 0) {
countA++;
} else if (countC == 0) {
countC++;
} else if (countH == 0) {
countH++;
}
}
if (countM + countR + countA + countC + countH <= 7) {
all = 0;
} else {
all = countM * countR * countA * countC * countH;
}
cout << all << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
vector<ll> let(5);
const char letter[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
string temp;
cin >> temp;
for (int j = 0; j < 5; j++) {
if (temp[0] == letter[j]) {
let[j]++;
}
}
}
ll res = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < N; k++) {
res += let[i] * let[j] * let[k];
}
}
}
cout << res << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int arr[5], cnt;
long long ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char name[1000];
scanf("%s", name);
if (name[0] == 'M')
arr[0]++;
else if (name[0] == 'A')
arr[1]++;
else if (name[0] == 'R')
arr[2]++;
else if (name[0] == 'C')
arr[3]++;
else if (name[0] == 'H')
arr[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 += arr[i] * arr[j] * arr[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, m, a, r, c, h;
int64_t ans;
cin >> n;
string tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
if (tmp[0] == 'M') ++m;
if (tmp[0] == 'A') ++a;
if (tmp[0] == 'R') ++r;
if (tmp[0] == 'C') ++c;
if (tmp[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 | UNKNOWN | # when initialize get stdin
class StdinGetter
# initialize
#
# @param [Boolean] has_header
def initialize(has_header=false)
@stdin = initialized_stdin(readlines)
@header = initialized_header(has_header)
@body = initialized_body(has_header)
end
# getter for header
#
# @return [String] header
def header()
@header
end
# getter for body
#
# @return [Array] body
def body()
@body
end
# get splited body
#
# @params [String] splitter
# @return [Array] body's array
def splited_body(splitter)
@body.map { |line| line.split(splitter) }
end
private
# initializer for stdin
#
# @param [Array] lines
# @return [Array]
def initialized_stdin(lines)
lines.nil? ? [] : lines.map{ |line| line.chomp }
end
# initializer for stdin header
#
# @param [Boolean] has_header
# @return [String]
def initialized_header(has_header)
has_header ? @stdin[0] : []
end
# initializer for stdin header
#
# @param [Boolean] has_header?
# @return [Array]
def initialized_body(has_header)
has_header ? @stdin.slice(1..-1) : @stdin
end
end
# March Class
class March
@@initial_chars = ["M", "A", "R", "C", "H"]
@@combination_number = 3
# initialize
#
# @params [Array] names
def initialize(names)
@names = names
end
# get all variation of having initial
#
# @return [Array]
def initials_variation()
@names.select { |name| @@initial_chars.include?(name[0]) }.combination(@@combination_number).to_a
end
# get variation without duplicate initials_variation
#
# @return [Array]
def not_duplicate_initial_variation()
initials_variation.map { |names| names.map { |name| name[0] }.uniq }.select { |variation| variation.length == @@combination_number }
end
# print how many valiation of march is exist
def print_march_count()
puts not_duplicate_initial_variation.length
end
end
# execute
stdin_getter = StdinGetter.new(true)
names = stdin_getter.body
march = March.new(names)
march.print_march_count |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, m;
char n[100000][10];
int i, j, k;
int d[5];
int h = 0;
cin >> x;
for (i = 0; i < x; i++) cin >> n[i];
for (i = 0; i < 5; i++) d[i] = 0;
for (i = 0; i < x; i++) {
if (n[i][0] == 'M') d[0]++;
if (n[i][0] == 'A') d[1]++;
if (n[i][0] == 'R') d[2]++;
if (n[i][0] == 'C') d[3]++;
if (n[i][0] == 'H') d[4]++;
}
for (i = 0; i < 5; i++)
if (d[i] > 0) h++;
int sum = 0;
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 5; j++) {
for (k = j + 1; k < 5; k++) {
sum += d[i] * d[j] * d[k];
}
}
}
cout << sum;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<string> s(n);
long long m;
long long a;
long long r;
long long c;
long long h;
for (int i = 0; i < (n); i++) {
cin >> s[i];
if (s[i].at(0) == 'M') m++;
if (s[i].at(0) == 'A') a++;
if (s[i].at(0) == 'R') r++;
if (s[i].at(0) == 'C') c++;
if (s[i].at(0) == 'H') h++;
}
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 | cpp | #include <bits/stdc++.h>
using namespace std;
long long int NAME(int M, int A, int R, int C, int H) {
int num[5];
num[0] = M;
num[1] = A;
num[2] = R;
num[3] = C;
num[4] = H;
long long int result = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
if (i != j && j != k && k != i) {
int temp = num[i] * num[j] * num[k];
result += temp;
}
}
}
}
result /= 6;
return result;
}
class ORDER {
public:
int N;
void MARCH() {
cin >> N;
string temp_st;
char temp_ch[1];
vector<char> S(N);
for (int i = 0; i < N; i++) {
cin >> temp_st;
temp_st.copy(temp_ch, 1);
S[i] = temp_ch[0];
}
int M = count(S.begin(), S.end(), 'M');
int A = count(S.begin(), S.end(), 'A');
int R = count(S.begin(), S.end(), 'R');
int C = count(S.begin(), S.end(), 'C');
int H = count(S.begin(), S.end(), 'H');
cout << NAME(M, A, R, C, H) << endl;
}
};
int main() {
ORDER x;
x.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 | cpp | #include <bits/stdc++.h>
using namespace std;
long long int ans;
int main() {
int n, f[10], i, g;
ans = g = 0;
char a[15];
memset(f, 0, sizeof(f));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", a);
if (a[0] == 'A')
f[1] += 1;
else if (a[0] == 'M')
f[2] += 1;
else if (a[0] == 'R')
f[3] += 1;
else if (a[0] == 'H')
f[4] += 1;
else if (a[0] == 'C')
f[0] += 1;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += f[i] * f[j] * f[k];
}
}
}
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
string s;
long long m, a, r, c, 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++;
}
long long ans = 0;
ans = ans + m * a * r;
ans = ans + m * a * c;
ans = ans + m * a * h;
ans = ans + m * r * c;
ans = ans + m * r * h;
ans = ans + m * c * h;
ans = ans + a * r * c;
ans = ans + a * c * h;
ans = ans + a * r * h;
ans = ans + r * c * h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
vector<pair<ll, int>> factorize(ll n) {
vector<pair<ll, int>> res;
for (ll i = 2; i * i <= n; ++i) {
if (n % i) continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1) res.emplace_back(n, 1);
return res;
}
int main() {
int N;
cin >> N;
vector<char> A(N);
for (int i = 0, i_len = (N); i < i_len; ++i) {
string S;
cin >> S;
A.at(i) = S.at(0);
}
vector<int> M(5, 0);
for (int i = 0, i_len = (N); i < i_len; ++i) {
if (A.at(i) == 'M') M.at(0)++;
if (A.at(i) == 'A') M.at(1)++;
if (A.at(i) == 'R') M.at(2)++;
if (A.at(i) == 'C') M.at(3)++;
if (A.at(i) == 'H') M.at(4)++;
}
ll ans = 0;
for (int i = 0, i_len = (5); i < i_len; ++i)
for (int j = 0, j_len = (i); j < j_len; ++j)
for (int k = 0, k_len = (j); k < k_len; ++k) {
ans += M.at(i) * M.at(j) * M.at(k);
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
string s = "MARCH";
int c[5] = {0};
for (int i = 0; i < (n); i++) {
string tmp;
cin >> tmp;
for (int j = 0; j < (5); j++) {
if (tmp[0] == s[j]) {
c[j]++;
}
}
}
long long anser = 0;
for (int i = 0; i < (3); i++) {
for (int j = i + 1; j < (5); j++) {
for (int k = j + 1; k < (5); k++) {
anser += c[i] * c[j] * c[k];
}
}
}
cout << anser << 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.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
Map<String,Integer> list = new HashMap<String,Integer>();
String object = "MARCH";
int num = sc.nextInt();
String a[] = {"M","A","R"};
String b[] = {"M","A","C"};
String c[] = {"M","A","H"};
String d[] = {"M","R","C"};
String e[] = {"M","R","H"};
String f[] = {"M","C","H"};
String g[] = {"A","R","C"};
String h[] = {"A","R","H"};
String j[] = {"A","C","H"};
String k[] = {"R","C","H"};
ArrayList<String[]> com = new ArrayList<String[]>();
com.add(a);
com.add(b);
com.add(c);
com.add(d);
com.add(e);
com.add(f);
com.add(g);
com.add(h);
com.add(j);
com.add(k);
for(int i=0;i<num;i++){
String value = sc.next();
String first = value.substring(0,1);
if(object.contains(first)){
if(!list.containsKey(first)){
list.put(first, 0);
}
list.put(first , list.get(first) + 1);
}
}
if(list.size() < 3){
System.out.println(0);
}else{
long comb = 0;
for(String[] obj : com){
long co = 1;
for(String ob : obj){
if(list.containsKey(ob)){
co = co * list.get(ob);
}else{
co = 0;
}
}
comb = comb + co;
}
}
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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 = 1000000007;
long long M = 0, A = 0, R = 0, C = 0, H = 0, ans;
string s;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
M++;
}
if (s[0] == 'A') {
A++;
}
if (s[0] == 'R') {
R++;
}
if (s[0] == 'C') {
C++;
}
if (s[0] == 'H') {
H++;
}
}
ans = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H +
A * R * C + A * R * H + A * C * H + R * C * H;
printf("%I64d\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 double pi = acos(-1);
const double eps = 1e-6;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
string s[n + 1];
long long M, A, R, C, H;
M = 0;
A = 0;
R = 0;
C = 0;
H = 0;
int i;
for (i = 1; i <= n; i++) {
cin >> s[i];
}
for (i = 1; 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 ans;
ans = 1;
if (M != 0) {
ans *= M;
}
if (A != 0) {
ans *= A;
}
if (R != 0) {
ans *= R;
}
if (C != 0) {
ans *= C;
}
if (H != 0) {
ans *= 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 main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
long long ans = 0;
int cnt[5] = {0};
for (int i = 0; i < n; i++) {
if (s[i][0] == 'M') {
cnt[0]++;
} else if (s[i][0] == 'A') {
cnt[1]++;
} else if (s[i][0] == 'R') {
cnt[2]++;
} else if (s[i][0] == 'C') {
cnt[3]++;
} else if (s[i][0] == 'H') {
cnt[4]++;
}
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j != 3; j++) {
for (int k = j + 1; k < 5; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from collections import Counter
import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
s = [input()[:1] for _ in range(n)]
s = Counter([i for i in s if i in ['M', 'A', 'R', 'C', 'H']])
if len(s)<3:
print(0)
exit()
ans = combinations_count(len(s), 3)
j = combinations_count((len(s)-1), 2)
for i in s.values():
ans += (i-1)*j
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>
int main() {
int n, m, a, r, c, h, i;
m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
scanf("%d", &n);
char name[100];
for (i = 0; i < n; i++) {
scanf("%s", name);
if (name[0] == 'M') {
m++;
} else {
if (name[0] == 'A') {
a++;
} else {
if (name[0] == 'R') {
r++;
} else {
if (name[0] == 'C') {
c++;
} else {
if (name[0] == 'H') {
h++;
}
}
}
}
}
}
long long int ans = 0;
ans += m * a * (r + c + h);
ans += m * r * (c + h);
ans += m * c * h;
ans += a * r * (c + h);
ans += a * c * h;
ans += r * c * h;
printf("%lld\n", ans);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;
int n;
string s;
int cnt[5];
ll ans;
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
ll g = gcd(x, y);
return x / g * y;
}
int main(){
lp(5)
cnt[i] = 0;
cin >> n;
lp(n) {
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]++;
}
ans = 0;
lp(3) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += ll(cnt[i] * cnt[j] * cnt[k]);
}
}
}
cout << ans << endl;
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.