Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | {-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad
import Data.IORef
import Data.Maybe
import qualified Data.Text as T
import qualified Data.Text.IO as T
import GHC.Base
import System.IO
import qualified Data.Array as A
import qualified Data.IntMap as I
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Vector as V
-- main
main :: IO ()
main = march
march :: IO ()
march = do
n :: Int <- readLn
ss :: V.Vector T.Text <- V.replicateM n T.getLine
let m = count (\s -> T.head s == 'M') ss
a = count (\s -> T.head s == 'A') ss
r = count (\s -> T.head s == 'R') ss
c = count (\s -> T.head s == 'C') ss
h = count (\s -> T.head s == 'H') ss
rc = r + c
ma = m + a
print $ m * a * (rc + h) + r * c * (ma + h) + h * rc * ma |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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][10];
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;
int N, m = 0, a = 0, r = 0, c = 0, h = 0;
string S;
int main() {
cin >> N;
long long ans = 0;
for (int i = 0; i < N; i++) {
cin >> S;
if (S[0] == 'M') m++;
if (S[0] == 'A') a++;
if (S[0] == 'R') r++;
if (S[0] == 'C') c++;
if (S[0] == 'H') h++;
}
ans = m * a * r + 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 | #pragma region template
// clang-format off
#ifdef ONLINE_JUDGE
#pragma GCC target("avx2")
#pragma GCC optimize("tree-vectorize")
#pragma GCC diagnostic ignored "-Wunused-result"
#define here
#define com(msg)
#define obs(...)
#define see(vec)
#define local(x)
#define alter(x,y) y
#else
#define here cerr<<__func__<<"/"<<__LINE__<<": reached\n"
#define com(msg) cerr<<"{ "<<msg<< " }\n"
#define obs(...) observe(#__VA_ARGS__, __VA_ARGS__)
#define see(vec) do{cerr<<#vec<<": ";printv(vec);}while(0)
#define local(x) x
#define alter(x,y) x
#endif
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define brep(i,a,b) for(int i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) for(int i=(n)-1,now=0;i>=0;i--,now++)
#define rbrep(i,a,b) for(int i=(a),i##_len=(b),now=0;i>=i##_len;i--,now++)
#define xrep(i,n) for(int i=1,i##_len=(n);i<=i##_len;i++)
#define yes(n) cout<<((n)?YES:NO)<<"\n"
#define cco(...) prints(__VA_ARGS__)
#define Sort(v) sort((v).begin(),(v).end())
#define rSort(v) sort((v).rbegin(),(v).rend())
#define Rev(v) reverse((v).begin(),(v).end())
#define Unique(v) (v).erase(unique((v).begin(),(v).end()),(v).end())
#define in_range(x,a,b) ((a)<=(x)&&(x)<(b))
#define in_area(x,y,a,b) (0<=(x)&&0<=(y)&&(x)<(a)&&(y)<(b))
using namespace std;
using ll = long long;
using ld = long double;
using pt = pair<int, int>;
using ull = unsigned long long;
using str = string;
using vbl = vector<bool>;
using dqbl = deque<bool>;
using vint = vector<int>;
using vll = vector<long long>;
using vdb = vector<double>;
using vld = vector<long double>;
using vpt = vector<pair<int, int>>;
using vstr = vector<string>;
using vvdb = vector<vector<double>>;
using vvbl = vector<vector<bool>>;
using vdqbl = vector<deque<bool>>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<long long>>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-9;
constexpr int dy[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dx[] = {0,1,0,-1,-1,1,1,-1};
// --- functions which take 1 argument --- //
template<class T> int sgn(const T &x){return (x>0)-(x<0);}
template<class S,class T=int> int digit(S x,const T &b=10){int r=1;while((x/=b)>=1)r++;return r;}
template<class T> double degToRad(const T &a){return a/180.0*M_PI;}
template<class T> double radToDeg(const T &a){return a/M_PI*180.0;}
template<class T> long long factorial(const T &n) {if(n==0)return 1;long long r=1;for(int i=2;i<=n;i++)r*=i;return r;}
template<class T> bool isPrime(const T &n){if(n<=1)return false;T i=2;while(i*i<=n){if(n%i==0&&n!=i)return false;i++;}return true;}
template<class T> map<T,T> factorize(T n){map<T,T>r;for(T i=2;i*i<=n;i++){while(n%i==0){r[i]++;n/=i;}}if(n!=1)r[n]=1;return r;}
template<class T> vector<T> divisor(const T &n){vector<T>r;for(T i=1;i*i<=n;i++){if(!(n%i)){r.emplace_back(i);if(i*i!=n)r.emplace_back(n/i);}}return r;}
// --- functions which take more than 1 argument --- //
template<class S,class T> [[maybe_unused]] bool chmax(S &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class S,class T> [[maybe_unused]] bool chmin(S &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class S,class T> bool near(const S &a, const T &b){return abs(a-b)<EPS;}
template<class S,class T> long long bpow(S m,T n){long long r=1;while(n>0){if(n&1)r*=m;m*=m;n/=2;}return r;}
template<class S,class T> typename common_type<S,T>::type min(const S &m,const T &n){return min((typename common_type<S,T>::type)m,(typename common_type<S,T>::type)n);}
template<class S,class T> typename common_type<S,T>::type max(const S &m,const T &n){return max((typename common_type<S,T>::type)m,(typename common_type<S,T>::type)n);}
template<class S,class T> long long nPr(const S &n,const T &k){if(n<k||n<0||k<0)return 0;long long r=1;for(int i=n-k+1;i<=n;i++)r*=i;return r;}
template<class S,class T> long long nCr(const S &n,T k){if(n<k||n<0||k<0)return 0;long long r=1;k=min(k,n-k);for(int i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> void prints(const T &v){cout<<v<<"\n";}
template<class S,class... T> void prints(const S &v,const T&... w){cout<<v<<" ";prints(w...);}
// --- functions which take vector/deque as argument --- //
template<class T> void printd(const vector<T> &v,string d){for(int i=0,i_len=(int)v.size()-1;i<i_len;i++)cout<<v[i]<<d;cout<<*v.rbegin()<<'\n';}
template<class T> void printd(const vector<vector<T>> &v,string d){for(const auto &x:v)printD(x,d);}
template<class T> bool in(const T &k,const vector<T> &v) {return find(v.begin(),v.end(),k)!=v.end();}
bool in(const int &k,const vector<long long> &v){return find(v.begin(),v.end(),k)!=v.end();}
bool in(const long long &k,const vector<int> &v){return find(v.begin(),v.end(),k)!=v.end();}
bool in(const char &k,const string &v) {return find(v.begin(),v.end(),k)!=v.end();}
bool in(const char* k,const vector<string> &v) {return find(v.begin(),v.end(),k)!=v.end();}
template<class T> double veclen(const vector<T> &v){return sqrt(reduce(v.begin(),v.end(),0.0,[](T s,T v){return s+=v*v;}));}
template<class T> T min(const vector<T> &v){return *min_element(v.begin(),v.end());}
template<class T> T max(const vector<T> &v){return *max_element(v.begin(),v.end());}
template<class T> T sum(const vector<T> &v){return reduce(v.begin(),v.end(),(T)0);}
template<class T> T gcd(const vector<T> &v){T r=v[0];for(int i=1,i_len=v.size();i<i_len;i++)r=gcd(r,v[i]);return r;}
template<class T> T lcm(const vector<T> &v){T r=v[0];for(int i=1,i_len=v.size();i<i_len;i++)r=lcm(r,v[i]);return r;}
template<class T> T vectorAdd(const T &u,const T &v) {T r(u.size());for(int i=0,i_len=u.size();i<i_len;i++)r[i]=u[i]+v[i];return r;}
template<class T> T vectorSubtract(const T &u,const T &v){T r(u.size());for(int i=0,i_len=u.size();i<i_len;i++)r[i]=u[i]-v[i];return r;}
template<class T> T vectorMultiply(const T &u,const T &v){T r(u.size());for(int i=0,i_len=u.size();i<i_len;i++)r[i]=u[i]*v[i];return r;}
template<class T> T vectorDivide(const T &u,const T &v) {T r(u.size());for(int i=0,i_len=u.size();i<i_len;i++)r[i]=u[i]/v[i];return r;}
template<class T> T dotProduct(const deque<bool> &u,const vector<T> &v){T r=0;for(int i=0,i_len=u.size();i<i_len;i++)if(u[i])r+=v[i];return r;}
template<class S,class T> typename common_type<S,T>::type dotProduct(const vector<S> &u,const vector<T> &v){typename common_type<S,T>::type r=0;for(int i=0,i_len=u.size();i<i_len;i++)r+=u[i]*v[i];return r;}
template<class S,class T> void sortBySecond(vector<pair<S,T>> &v){sort(v.begin(),v.end(),[](auto &L,auto &R){if(L.second==R.second)return L.first<R.first;return L.second<R.second;});}
// --- functions which take set/map as argument --- //
template<class T> T min(const set<T> &v){return *min_element(v.begin(),v.end());}
template<class T> T max(const set<T> &v){return *max_element(v.begin(),v.end());}
template<class T> T sum(const set<T> &v){return reduce(v.begin(),v.end(),(T)0);}
template<class T> T gcd(const set<T> &v){T r=0;for(const T &x:v)r=(r==0)?x:gcd(r,x);return r;}
template<class T> T lcm(const set<T> &v){T r=0;for(const T &x:v)r=(r==0)?x:lcm(r,x);return r;}
template<class T> bool in(const T &k,const set<T> &v){return find(v.begin(),v.end(),k)!=v.end();}
template<class S,class T> pair<S,T> min(const map<S,T> &m){pair<S,T> r=*m.begin();for(const pair<S,T> &p:m)if(r.second>p.second)r=p;return r;}
template<class S,class T> pair<S,T> max(const map<S,T> &m){pair<S,T> r=*m.begin();for(const pair<S,T> &p:m)if(r.second<p.second)r=p;return r;}
// --- operators --- //
template<class T> istream& operator>>(istream &i,vector<T> &v){for(T &x:v)i>>x;return i;}
template<class T> ostream& operator<<(ostream &o,vector<T> &v){for(T &x:v)o<<x<<"\n";return o;}
template<class S,class T> istream& operator>>(istream &i,pair<S,T> &p){i>>p.first>>p.second;return i;}
template<class S,class T> ostream& operator<<(ostream &o,pair<S,T> &p){o<<p.first<<" "<<p.second<<"\n";return o;}
template<class S,class T> pair<S,T> operator+(const pair<S,T> &p,const pair<S,T> &q){return pair<S,T>{p.first+q.first,p.second+q.second};}
template<class S,class T> pair<S,T> operator-(const pair<S,T> &p,const pair<S,T> &q){return pair<S,T>{p.first-q.first,p.second-q.second};}
template<class S,class T> pair<S,T> operator*(const pair<S,T> &p,const pair<S,T> &q){return pair<S,T>{p.first*q.first,p.second*q.second};}
template<class S,class T> pair<S,T> operator/(const pair<S,T> &p,const pair<S,T> &q){return pair<S,T>{p.first/q.first,p.second/q.second};}
template<class S,class T> [[maybe_unused]] pair<S,T> operator--(pair<S,T> &p){return pair<S,T>{--p.first,--p.second};}
template<class S,class T> [[maybe_unused]] pair<S,T> operator++(pair<S,T> &p){return pair<S,T>{++p.first,++p.second};}
template<class S,class T> [[maybe_unused]] pair<S,T> operator+=(pair<S,T> &p,const pair<S,T> &q){return p=p+q;}
template<class S,class T> [[maybe_unused]] pair<S,T> operator-=(pair<S,T> &p,const pair<S,T> &q){return p=p-q;}
template<class S,class T> [[maybe_unused]] pair<S,T> operator*=(pair<S,T> &p,const pair<S,T> &q){return p=p*q;}
template<class S,class T> [[maybe_unused]] pair<S,T> operator/=(pair<S,T> &p,const pair<S,T> &q){return p=p/q;}
// --- functions for debugging --- //
template<class T> void observe(const char *n,T &&v) {cerr<<n<<": "<<v<<"\n";}
template<class S,class... T> void observe(const char *n,S &&v,T&&... w){const char *c=strchr(n+1,',');cerr.write(n,c-n)<<": "<<v<<" |";observe(c+1,w...);}
template<class T> void printv(const vector<T> &v) {cerr<<"[ ";for(const T &x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class T> void printv(const deque<T> &v) {cerr<<"[ ";for(const T &x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class T> void printv(const set<T> &v) {cerr<<"[ ";for(const T &x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class P> void printv(const P &p) {cerr<<"{ "<<p.first<<" "<<p.second<<" } ";}
template<class T> void printv(const vector<vector<T>> &v){for(const vector<T> &x:v)printv<T>(x);}
template<class T> void printv(const vector<deque<T>> &v) {for(const deque<T> &x:v) printv<T>(x);}
template<class S,class T> void printv(const map<S,T> &m) {cerr<<"[ ";for(const pair<S,T> &p:m)cerr<<"{ "<<p.first<<", "<<p.second<<" } ";cerr<<"]\n";}
template<class S,class T> void printv(const vector<pair<S,T>> &v){cerr<<"[ ";for(const pair<S,T> &p:v)printv<pair<S,T>>(p);cerr<<"]\n";}
// clang-format on
#pragma endregion
void solve(int N, vector<string> S) {
map<char, int> mp;
const str B = "MARCH";
for (auto &&s : S) {
mp[s[0]]++;
}
long long ans = 0;
rep(i1, 5) {
brep(i2, i1 + 1, 4) {
brep(i3, i2 + 1, 4) {
ans += mp[B[i1]] * mp[B[i2]] * mp[B[i3]];
}
}
}
cout << (ans) << "\n";
}
int main() {
int N;
scanf("%d", &N);
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
}
solve(N, move(S));
exit(EXIT_SUCCESS);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
int n, cntt = 0, cnt[5] = {};
bool f[5];
for (int i = 0; i < 5; i++) {
f[i] = false;
}
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M') {
cnt[0]++;
f[0] = true;
} else if (s[0] == 'A') {
cnt[1]++;
f[1] = true;
} else if (s[0] == 'R') {
cnt[2]++;
f[2] = true;
} else if (s[0] == 'C') {
cnt[3]++;
f[3] = true;
} else if (s[0] == 'H') {
cnt[4]++;
f[4] = true;
}
}
for (int i = 0; i < 5; i++) {
if (f[i] == true) {
cntt++;
}
}
if (cntt < 3) {
cout << 0 << endl;
} else if (cntt == 3) {
long long tmp = cntt * (cntt - 1) * (cntt - 2) / 6;
for (int i = 0; i < 5; i++) {
if (cnt[i]) {
tmp *= cnt[i];
}
}
cout << tmp << endl;
} else if (cntt == 4) {
long long tmp = cntt * (cntt - 1) * (cntt - 2) / 6;
for (int i = 0; i < 5; i++) {
if (cnt[i]) {
tmp--;
tmp *= cnt[i];
tmp++;
}
}
cout << tmp << endl;
} else if (cntt == 5) {
long long tmp = cntt * (cntt - 1) * (cntt - 2) / 6;
for (int i = 0; i < 5; i++) {
if (cnt[i]) {
tmp -= 3;
tmp *= cnt[i];
tmp += 3;
}
}
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = [input() for i in range(N)]
U = []
n = [0,0,0,0,0]
result = 0
for i in range(N):
if S[i][0] == 'M' or S[i][0] == 'A' or S[i][0] == 'R' or S[i][0] == 'C' or S[i][0] == 'H':
U.append(S[i][0])
if S[i][0] == 'M':
n[0] += 1
if S[i][0] == 'A':
n[1] += 1
if S[i][0] == 'R':
n[2] += 1
if S[i][0] == 'C':
n[3] += 1
if S[i][0] == 'H':
n[4] += 1
un = len(set(U))
if un == 3:
result = 1
for i in range(5):
if n[i] != 0:
result = result + (n[i] - 1)
if un == 4:
result = 4
for i in range(5):
if n[i] != 0:
result = result + 3*(n[i] - 1)
if un == 5:
result = 10
for i in range(5):
if n[i] != 0:
result = result + 4* (n[i] - 1)
print(result)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
int p[5] = {0};
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == 'M')
p[0]++;
else if (s[0] == 'A')
p[1]++;
else if (s[0] == 'R')
p[2]++;
else if (s[0] == 'C')
p[3]++;
else if (s[0] == 'H')
p[4]++;
}
long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += p[i] * p[j] * p[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 | import numpy as np
N = int(input())
n = 0
for i in range(N):
st = str(input())
if {list(st)[0]} <= {'M','A','R','C','H'}:
n += 1
print(n)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int M = 0;
int A = 0;
int R = 0;
int C = 0;
int H = 0;
for (int i = 0; i < N; i++) {
string name;
cin >> name;
if (name.at(0) == 'M') {
M++;
}
if (name.at(0) == 'A') {
A++;
}
if (name.at(0) == 'R') {
R++;
}
if (name.at(0) == 'C') {
C++;
}
if (name.at(0) == 'H') {
H++;
}
}
int answer = 0;
answer += M * (A * (R + C + H) + R * (C + H) + C * H);
answer += A * (R * (C + H) + C * H);
answer += R * C * H;
cout << answer << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
N = int(input())
S = [input()[0] for _ in range(N)]
for i,s in enumerate(S):
if not s in ['M', 'A', 'R', 'C', 'H']:
S.pop(i)
count = 0
for i in itertools.combinations(S,3):
if i[0][0] != i[1][0] and i[0][0] != i[2][0] and i[1][0] != i[2][0]:
count += 1
print(count)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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]++;
}
}
long 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 | cpp | #include <bits/stdc++.h>
const char c[5] = {'M', 'A', 'R', 'C', 'H'};
using namespace std;
int main() {
int n;
cin >> n;
string s;
int cnt[5] = {0};
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == c[j]) cnt[j]++;
}
}
long long res = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
res += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python2 | # -*- coding: utf-8 -*-
import itertools
def filter_name(n):
return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"
def filter_ok(l):
dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in l:
dic[i[0:1]] += 1
if dic[i[0:1]] >= 2:
return False
return True
n = input()
a = []
for i in range(n):
b = raw_input()
if filter_name(b[0:1]):
a.append(b)
c = list(itertools.combinations(a, 3))
a = filter(filter_ok, c)
print len(a)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | //include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//typedef
//------------------------------------------
using LL = int64_t;
using VL = vector<LL>;
using VVL = vector<VL>;
using VS = vector<string>;
using PLL = pair<LL, LL>;
//container util
//------------------------------------------
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(x) ::std::begin(x), ::std::end(x)
#define RALL(x) ::std::rbegin(x), ::std::rend(x)
#define SORT(c) whole(sort, c)
#define RSORT(c) rwhole(sort, c)
//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
constexpr int MOD = 1000000007;
// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};
//debug
//--------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//IO accelerate
//--------------------------------------------
struct InitIO {
InitIO() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
} init_io;
//template
//--------------------------------------------
// declaretion
template<typename T> istream& operator >>(istream& is, vector<T>& vec);
template<typename T1, typename T2> ostream& operator <<(ostream& os, const pair<T1, T2>& p);
template<typename T> ostream& operator <<(ostream& os, const vector<T>& vec);
template<typename T> ostream& operator <<(ostream& os, const vector<vector<T>>& vv);
template<typename T> vector<T> make_v(size_t a);
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts);
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v);
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v);
// implementation
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
for(T& x: vec) is >> x;
return is;
}
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>& vec) {
for(int i=0; i<vec.size(); i++){
os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
}
return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
for (int i = 0; i < vv.size(); ++i) {
s << vv[i] << endl;
}
return s;
}
// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
for(auto &e:t) fill_v(e,v);
}
template<class T,class U> void chmax(T&a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T&a,U b){if(b<a)a=b;}
template<typename T> T gcd(T a, T b) { return b?gcd(b,a%b):a;}
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b;}
//main code
int main(int argc, char *argv[])
{
int n;
cin >> n;
VS s(n);
cin >> s;
map<char,int> mp;
for (int i = 0; i < n; i++) {
mp[s[i][0]]++;
}
LL ans = 0;
vector<char> vc = {'M','A','R','C','H'};
for (int i = 0; i < 5; i++) {
for (int j = i+1; j < 5; j++) {
for (int k = j+1; k < 5; k++) {
ans += mp[vc[i]] * mp[vc[j]] * mp[vc[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 spacename std;
int main() {
long long n, a[5]={0,0,0,0,0}, r = 0;
scanf("%ld", &n);
for (int i = 0; i < n; i++) {
char s[10];
scanf("%s", s);
if (s[0] == 'M'){
a[0]++;
}
else if (s[0] == 'A') {
a[1]++;
}
else if (s[0] == 'R') {
a[2]++;
}
else if (s[0] == 'C') {
a[3]++;
}
else if (s[0] == 'H') {
a[4]++;
}
}
int ans;
for ( int z = 0; z < 3; z++) {
for ( int c = z+1; c < 4; c++){
for ( int v = c+1; v < 5; v++){
a[z]*a[c]*z[v] = ans;}}}
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArCorder
{
class Program
{
class inner : IEquatable<inner>
{
string m_First;
string m_Second;
string m_Therd;
public inner (string first, string second, string therd)
{
m_First = first;
m_Second = second;
m_Therd = therd;
}
public Boolean IsTarget()
{
if (m_First.First() != m_Second.First() && m_First.First() != m_Therd.First() && m_Second.First() != m_Therd.First())
{
return true;
}
else
{
return false;
}
}
public bool Equals(inner obj)
{
return obj.GetHashCode() == this.GetHashCode();
}
public override int GetHashCode()
{
return this.m_First.GetHashCode() ^ this.m_Second.GetHashCode() ^ this.m_Therd.GetHashCode();
}
}
static void Main()
{
int max = int.Parse(Console.ReadLine());
List<string> names = new List<string>();
for (int i = 0; i < max; i++)
{
names.Add(Console.ReadLine());
}
List<string> targetNames = names.Where(x => x.StartsWith("M") ||
x.StartsWith("A") ||
x.StartsWith("R") ||
x.StartsWith("C") ||
x.StartsWith("H")).ToList();
List<inner> allPatern = new List<inner>();
foreach (string first in targetNames){
foreach(string second in targetNames.Where(x => !x.Equals(first)))
{
foreach (string therd in targetNames.Where(x => !x.Equals(first) && !x.Equals(second)))
{
allPatern.Add(new inner(first, second, therd));
}
}
}
Console.WriteLine(allPatern.Where(x => x.IsTarget()).Distinct().LongCount());
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
struct edge {
int from, to;
ll cost;
};
class Eratosthenes {
public:
vector<bool> prime;
Eratosthenes(int size) {
prime.resize(size + 1, 1);
prime[0] = 0;
prime[1] = 0;
for (ll i = 2; i <= (ll)size; ++i) {
if (prime[i]) {
for (int j = 2 * i; j <= size; j += i) {
prime[j] = 0;
}
}
}
}
};
class Combination {
vector<ll> fac;
vector<ll> ifac;
public:
Combination(ll size) {
fac.resize(size);
ifac.resize(size);
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < size; i++) {
fac[i + 1] = fac[i] * (i + 1) % MOD;
ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
}
}
ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1) ans = ans * x % MOD;
x = x * x % MOD;
n = n >> 1;
}
return ans;
}
ll comb(ll a, ll b) {
if (a == 0 && b == 0) return 1;
if (a < b || a < 0) return 0;
ll tmp = ifac[a - b] * ifac[b] % MOD;
return tmp * fac[a] % MOD;
}
};
ll GCD(ll a, ll b) {
if (b == 0) return a;
return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
ll gcd = GCD(a, b);
return a / gcd * b;
}
ll N;
int main() {
cin >> N;
vector<int> c(5);
for (int i = 0; i < N; ++i) {
string s;
cin >> s;
if (s[0] == 'M') c[0]++;
if (s[0] == 'A') c[1]++;
if (s[0] == 'R') c[2]++;
if (s[0] == 'C') c[3]++;
if (s[0] == 'H') c[4]++;
}
ll res = 0;
for (int i = 0; i < 5; ++i) {
for (ll j = i + 1; j <= (ll)5; ++j) {
for (ll k = j + 1; k <= (ll)5; ++k) {
res += c[i] * c[j] * c[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 | java | import java.util.*;
public class Main {
public static void main(String args[]) {
// 入力
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
String[] s = new String[n];
Arrays.setAll(s, i -> sc.next());
sc.close();
// 主処理
List<String> mList = new ArrayList<>();
List<String> aList = new ArrayList<>();
List<String> rList = new ArrayList<>();
List<String> cList = new ArrayList<>();
List<String> hList = new ArrayList<>();
for (String name : s) {
if (name.startsWith("M")) {
mList.add(name);
} else if (name.startsWith("A")) {
aList.add(name);
} else if (name.startsWith("R")) {
rList.add(name);
} else if (name.startsWith("C")) {
cList.add(name);
} else if (name.startsWith("H")) {
hList.add(name);
}
}
int sum = Math.min(1, mList.size()) + Math.min(1, aList.size()) + Math.min(1, rList.size())
+ Math.min(1, cList.size()) + Math.min(1, hList.size());
long result = 0;
long m = combination(sum - mList.size(), 3);
long a = combination(sum - aList.size(), 3);
long r = combination(sum - rList.size(), 3);
long c = combination(sum - cList.size(), 3);
long h = combination(sum - hList.size(), 3);
result = m + a + r + c + h;
// 出力
System.out.println(result);
}
public static long combination(int n, int m) {
if (n < m || m < 0) {
return 0;
}
long c = 1;
m = (n - m < m ? n - m : m);
for (int ns = n - m + 1, ms = 1; ms <= m; ns++, ms++) {
c *= ns;
c /= ms;
}
return c;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import std.stdio,
std.string,
std.conv;
void main() {
int N = to!int(readln.chomp);
int[char] hash;
for (int i = 0; i < N; i++) {
string s = readln.chomp;
if ("MARCH".count(s[0])) {
hash[s[0]]++;
}
}
int[] a = hash.values ~ [0, 0, 0, 0, 0];
long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += a[i] * a[j] * a[k];
}
}
}
writeln(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);
long 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;
constexpr long long MOD = (1e9 + 7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
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;
}
long long factorial(long long n, long long m = 2) {
m = max(2LL, m);
long long rtn = 1;
for (long long i = m; i <= n; i++) {
rtn = (rtn * i) % MOD;
}
return rtn;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
long long modpow(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> march(5);
int flag = 0;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
toupper(s[0]);
if (s[0] == 'M')
march[0]++;
else if (s[0] == 'A')
march[1]++;
else if (s[0] == 'R')
march[2]++;
else if (s[0] == 'C')
march[3]++;
else if (s[0] == 'H')
march[4]++;
else
flag++;
}
if (flag == n)
cout << 0 << endl;
else {
int cnt = 0;
for (int bit = 1; bit < (1 << 5); ++bit) {
int tmp = 1;
if (__builtin_popcount(bit) != 3) continue;
for (int i = 0; i < 5; ++i) {
if (bit & 1 << i) tmp *= march[i];
}
cnt += tmp;
}
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;
int main() {
int N, cnt[5] = {0}, ans = 0;
char str[16];
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%s", str);
switch (str[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
default:
break;
}
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << "\n";
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int N;
cin >> N;
int m, a, r, c, h;
long long ans;
m = a = r = c = h = 0;
int i;
for (i = 0; i < N; i++) {
cin >> str;
if (str[0] == 'M') {
m += 1;
}
if (str[0] == 'A') {
a += 1;
}
if (str[0] == 'R') {
r += 1;
}
if (str[0] == 'C') {
c += 1;
}
if (str[0] == 'H') {
h += 1;
}
}
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;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const int MAX = 10000;
static const long long INFTY = 1e12;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
long long conv3(long long x) { return x * (x - 1) * (x - 2) / (6); }
long long conv2(long long x) { return x * (x - 1) / (2); }
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};
cin >> N;
for (int i = 0; i < N; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
long long res = 0;
for (int d = 0; d < 10; d++) res += D[P[d]] * D[Q[d]] * D[R[d]];
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, Ans = 0;
;
cin >> N;
vector<long long int> A(5);
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]++;
}
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
Ans += A[i] * A[j] * A[k];
}
}
}
cout << Ans;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int cnt[5];
long long int ans;
long long int gcd(long long int x, long long int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
long long int g = gcd(x, y);
return x / g * y;
}
int main() {
for (int i = 0; i < 5; i++) cnt[i] = 0;
cin >> n;
for (int i = 0; i < n; i++) {
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;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, N;
string S;
int M = 0, A = 0, R = 0, C = 0, H = 0;
cin >> N;
for (i = 0; i < N; ++i) {
cin >> S;
if (S[0] == 'M')
++M;
else if (S[0] == 'A')
++A;
else if (S[0] == 'R')
++R;
else if (S[0] == 'C')
++C;
else if (S[0] == 'H')
++H;
}
long long int total;
total = 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 << 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;
using ll = long long;
int main() {
ll n;
cin >> n;
string s;
map<char, ll> mp;
ll cnt = 0;
ll ans = 1;
for (ll i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' ||
s[0] == 'H') {
mp[s[0]]++;
}
}
if (s['M'] != 0) {
cnt++;
ans *= s['M'];
}
if (s['A'] != 0) {
cnt++;
ans *= s['A'];
}
if (s['R'] != 0) {
cnt++;
ans *= s['R'];
}
if (s['C'] != 0) {
cnt++;
ans *= s['C'];
}
if (s['H'] != 0) {
cnt++;
ans *= s['H'];
}
if (cnt < 3)
ans = 0;
else if (cnt == 4) {
ans *= 4;
} else if (cnt == 5) {
ans *= 10;
}
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;
#define rep(i, n) for(int i = 0; i < (n); i++)
int int_len(int n) {
int s=0;
while(n!=0) s++, n/=10;
return s;
}
int int_sum(int n) {
int m=0,s=0,a=n;
while(a!=0) s++, a/=10;
for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
return m;
}
long long int gcd(long long int a,long long int b)
{
long long int r, tmp;
/* 自然数 a > b を確認・入替 */
if(a<b){
tmp = a;
a = b;
b = tmp;
}
/* ユークリッドの互除法 */
r = a % b;
while(r!=0){
a = b;
b = r;
r = a % b;
}
return b;
}
int fac(int n){
int m=1;
while(n>=1) m*=n,n--;
return m;
}
int vec_sum(vector<int> v){
int n=0;
for(int i=0;i<v.size();i++) n+=v[i];
return n;
}
///////////////////////////
int main() {
int n,ans=0,c[5];
cin>>n;
rep(i,n){
string s;
cin>>s;
if(s[0]=='M'){
c[0]++;
}else if(s[0]=='A'){
c[1]++;
}else if(s[0]=='R'){
c[2]++;
}else if(s[0]=='C'){
c[3]++;
}else if(s[0]=='H'){
c[4]++;
}
}
rep(i,5) if(c[i]>0) count++;
if(count<=2){
cout<<0<<endl;
return 0;
}
for(int p=0;p<3;p++){
for(int q=p+1;q<4;q++){
for(int r=q+1;r<5;r++){
ans+=c[p]*c[q]*c[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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string t = "MARCH";
int sum[5] = {0};
for (int i = (0); i < (n); i++) {
string s;
cin >> s;
for (int j = (0); j < (5); j++)
if (s[0] == t[j]) sum[j]++;
}
int ans = 0;
for (int i = (0); i < (3); i++) {
for (int j = (i + 1); j < (4); j++) {
for (int k = (j + 1); k < (5); k++) {
ans += sum[i] * sum[j] * sum[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;
char a[100010][100];
int n;
int an, b, c, d, e;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i][0] == 'M' && a[i][1] != 'M') an++;
if (a[i][0] == 'A' && a[i][1] != 'A') b++;
if (a[i][0] == 'R' && a[i][1] != 'R') c++;
if (a[i][0] == 'C' && a[i][1] != 'C') d++;
if (a[i][0] == 'H' && a[i][1] != 'H') e++;
}
int a1, b1, c1;
a1 = an * b * c + an * b * d + an * b * e + an * c * d + an * c * e +
an * d * e;
b1 = b * c * d + b * c * e + b * d * e;
c1 = c * d * e;
cout << a1 + b1 + c1 << endl;
system("pause");
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.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
static int mod=1000000007;
public static void main(String[]$) {
Scanner sc = new Scanner(in);
int n=sc.nextInt();
long m,a,r,c,h;
m=a=r=c=h=0;
for (int i = 0; i <n; i++) {
String s=sc.next();
switch (s.charAt(0)){
case 'M':m++;break;
case 'A':a++;break;
case 'R':r++;break;
case 'C':c++;break;
case 'H':h++;break;
default:break;
}
}
out.println(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);
}
static long power(long x,int n){
long mod=1000000007;
long ans=1;
while (n>0) {
if((n&1)==1){
ans=(ans*x)%mod;
}
x=(x*x)%mod;
n>>=1;
}
return ans;
}
//最大公約数
static int gcd (int a,int b) {
int temp;
while((temp = a%b)!=0) {
a = b;
b = temp;
}
return b;
}
//※最小公倍数はa*b/gcd(a,b)である
static class UF{
static int size=51;
static int[] par=new int[size];
//初期化
static void init(){
for (int i = 1; i <size ; i++) {
par[i]=i;
}
}
//根をたどる
static int root(int x){
if(par[x]==x){
return x;
}else{
return par[x]=root(par[x]);
}
}
//同じ根をもつか(同じ集合に属するか)判定
static boolean same(int x,int y){
return root(x)==root(y);
}
//合体
static void unite(int x,int y){
x=root(x);
y=root(y);
if(x==y)return;
par[x]=y;
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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;
string s;
long long na[5];
for (int i = 0; i < 5; i++) {
na[i] = 0;
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
na[0]++;
}
if (s[0] == 'A') {
na[1]++;
}
if (s[0] == 'R') {
na[2]++;
}
if (s[0] == 'C') {
na[3]++;
}
if (s[0] == 'H') {
na[4]++;
}
}
long long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans = ans + s[i] * s[j] * s[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
new Main().execute();
}
public void execute() {
Scanner sc = new Scanner(System.in);
final int N = sc.nextInt();
int[] march = new int[5];
for (int i = 0; i < N; i++) {
String si = sc.next();
switch (si.charAt(0)) {
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
default:
}
}
long patterns = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
patterns += march[i] * march[j] * march[k];
}
}
}
System.out.println(patterns);
sc.close();
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int Len(int n) {
int s = 0;
while (n != 0) s++, n /= 10;
return s;
}
int Sint(int n) {
int m = 0, s = 0, a = n;
while (a != 0) s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int Svec(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++) n += v[i];
return n;
}
int GCD(int a, int b) {
int r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
int LCM(int a, int b) {
int c = a, d = b, r, tmp;
if (a < b) {
tmp = a, a = b, b = tmp;
}
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
int Factorial(int n) {
int m = 1;
while (n >= 1) m *= n, n--;
return m;
}
int main() {
int n;
cin >> n;
vector<unsigned int> c(5);
for (int i = 0; i < (5); i++) c[i] = 0;
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
if (s[0] == 'M') {
c[0]++;
} else if (s[0] == 'A') {
c[1]++;
} else if (s[0] == 'R') {
c[2]++;
} else if (s[0] == 'C') {
c[3]++;
} else if (s[0] == 'H') {
c[4]++;
}
}
long long int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char t[6] = {'M', 'A', 'R', 'C', 'H'};
int main() {
int n;
int c[5] = {};
string s;
int ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[0] == t[j]) {
c[j]++;
}
}
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += c[i] * c[j] * c[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using unit = unsigned;
using vl = vector<ll>;
using ull = unsigned long long;
using vvi = vector<vi>;
using P = pair<int, int>;
using vvl = vector<vl>;
using vp = vector<P>;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
template <class T>
string join(const vector<T> &v) {
stringstream s;
for (int i = (int)(0); i < (int)(((int)(v).size())); ++i) s << ' ' << v[i];
return s.str().substr(1);
}
template <class T>
istream &operator>>(istream &i, vector<T> &v) {
for (auto &x : v) {
i >> v;
}
return i;
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (auto &x : v) o << x << ",";
o << "]";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const deque<T> &v) {
o << "deq[";
for (auto &x : v) o << x << ",";
o << "]";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T> &v) {
o << "{";
for (auto &x : v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_set<T> &v) {
o << "{";
for (auto &x : v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const multiset<T> &v) {
o << "{";
for (auto &x : v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_multiset<T> &v) {
o << "{";
for (auto &x : v) o << x << ",";
o << "}";
return o;
}
template <class T1, class T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
o << "(" << p.first << "," << p.second << ")";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const map<TK, TV> &m) {
o << "{";
for (auto &x : m) o << x.first << "=>" << x.second << ",";
o << "}";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const unordered_map<TK, TV> &m) {
o << "{";
for (auto &x : m) o << x.first << "=>" << x.second << ",";
o << "}";
return o;
}
template <class T>
void YES(T c) {
if (c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T>
void Yes(T c) {
if (c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T>
void POSS(T c) {
if (c)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
template <class T>
void Poss(T c) {
if (c)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
}
template <class T>
void chmax(T &a, const T &b) {
if (a < b) a = b;
}
template <class T>
void chmin(T &a, const T &b) {
if (b < a) a = b;
}
template <class T>
T gcd(T a, T b) {
return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
return a * (b / gcd(a, b));
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const ll INFL = 1LL << 60;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
void _main() {
string march = "MARCH";
int cnt[5] = {};
int N;
cin >> N;
for (int i = (int)(0); i < (int)(N); ++i) {
string s;
cin >> s;
for (int j = (int)(0); j < (int)(5); ++j)
if (s[0] == march[j]) ++cnt[j];
}
ll ans = 0;
for (int i = (int)(0); i < (int)(5); ++i)
for (int j = (int)(i + 1); j < (int)(5); ++j)
for (int k = (int)(j + 1); k < (int)(5); ++k) {
ans += cnt[i] * cnt[j] * cnt[k];
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
long long INF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
int n;
int ar[5] = {};
long long ans = 0;
cin >> n;
vector<string> vi(n);
for (int i = (0); i < (n); ++i) cin >> vi[i];
for (int i = (0); i < (n); ++i) {
if (vi[i][0] == 'M') ++ar[0];
if (vi[i][0] == 'A') ++ar[1];
if (vi[i][0] == 'R') ++ar[2];
if (vi[i][0] == 'C') ++ar[3];
if (vi[i][0] == 'H') ++ar[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 += ar[i] * ar[j] * ar[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
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;
int used[5][5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
used[i][j][k] = 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 {
if (used[i][j][m] == 0) {
ans += cou[i] * cou[j] * cou[m];
used[i][j][m] = 1;
used[j][i][m] = 1;
used[i][m][j] = 1;
used[j][m][i] = 1;
used[m][i][j] = 1;
used[m][j][i] = 1;
}
}
}
}
}
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 | def convert(input_lis):
return [i[0] for i in input_lis]
lis = [i for i in [input() for i in range(int(input()))]
if i[0] == 'M' or i[0] == 'A'or i[0] == 'R'or i[0] == 'C'or i[0] == 'H']
import itertools
ans_list = []
for i in [sorted(i) for i in [i for i in filter(lambda x: len(list(set(convert(x)))) == len(convert(x)),
itertools.combinations(lis, 3))]]:
if sorted(i) not in ans_list:
ans_list.append(i)
print(len(ans_list)) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | <?php
$n = trim(fgets(STDIN));
$count = [];
$t = 0;
$march=["M","A","R","C","H"];
for($i=0; $i<$n; $i++){
$s = trim(fgets(STDIN));
if(in_array($s[0],$march)){
$count[$s[0]]++;
$t++;
}
}
// print_r($count);
$c = count($count);
if($c == 3){
$ans = 0;
}else if($c < 3){
echo "0";
exit;
}else{
$ans = $c;
}
foreach ($count as $d){
if($d > 1){
$ans += ($d-1)*($t-$d);
}
}
echo $ans; |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int num[26] = {0}, c = 0;
char pr[5] = {'A', 'C', 'H', 'M', 'R'};
string s;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
num[s[0] - 'A']++;
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
c += num[pr[i] - 'A'] * num[pr[j] - 'A'] * num[pr[k] - 'A'];
}
}
}
cout << c;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N=int(input())
m=0
a=0
r=0
c=0
h=0
for _ in range(N):
s=input()
if s[0]=="M":
m+=1
elif s[0]=="A":
a+=1
elif s[0]=="R":
r+=1
elif s[0]=="C":
c+=1
elif s[0]=="H":
h+=1
ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=a*r*c
ans+=a*r*h
ans+=r*c*h
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<string> m, a, r, c, h;
string s;
for (int i = 0; i < (n); i++) {
cin >> s;
if (s[0] == 'M')
m.insert(s);
else if (s[0] == 'A')
a.insert(s);
else if (s[0] == 'R')
r.insert(s);
else if (s[0] == 'C')
c.insert(s);
else if (s[0] == 'H')
h.insert(s);
}
long long ans = 0;
ans += m.size() * a.size() * r.size();
ans += m.size() * a.size() * c.size();
ans += m.size() * a.size() * h.size();
ans += m.size() * r.size() * c.size();
ans += m.size() * r.size() * h.size();
ans += a.size() * r.size() * c.size();
ans += a.size() * r.size() * h.size();
ans += a.size() * c.size() * h.size();
ans += r.size() * c.size() * h.size();
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 n;
int a[300];
int main() {
while (1) {
scanf("%d", &n);
a['M'] = 0;
a['A'] = 0;
a['R'] = 0;
a['C'] = 0;
a['H'] = 0;
char s[100];
char c;
for (int i = 0; i < n; i++) {
scanf("%s", s);
c = s[0];
a[c]++;
}
int ans = 0;
ans += a['M'] * (a['A'] * (a['R'] + a['C'] + a['H']) +
a['R'] * (a['C'] + a['H']) + a['C'] * a['H']) +
a['A'] * a['R'] * (a['C'] + a['H']) +
(a['R'] + a['A']) * a['C'] * a['H'];
printf("%d\n", ans);
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | N = int(input())
S = [input()[0] for i in range(N)]
li = [S.count("M"),S.count("A"),S.count("R"),S.count("C"),S.count("H")]
li = list(filter(lambda x:x>0, li))
ans = 1
for i in li:
ans *= i
print(0 if sum(li) < 3 else ans if len(li)==3 else ans*4 if len(li)==4 else ans*10) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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 MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
void get_combination(vvl& C, const ll N) {
C = vvl(N + 1, vl(N + 1, 0));
for (int i = int(0); i < int(N); ++i) {
C[i][0] = 1;
C[i][i] = 1;
}
for (int i = int(1); i < int(N); ++i) {
for (int j = int(1); j < int(i); ++j) {
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vs S(N);
for (int i = int(0); i < int(N); ++i) cin >> S[i];
string ptn = "MARCH";
map<char, int> mp;
for (string s : S) {
if (ptn.find(s[0]) != string::npos) mp[s[0]]++;
}
ll M = 0;
for (char c : ptn) {
M += mp[c];
}
ll ans = 0;
if (M >= 3) {
vvl C;
get_combination(C, M);
ll total = C[M][3];
for (char c : ptn) {
int n = mp[c];
if (n >= 3) total -= C[n][3];
if (n >= 2) total -= C[n][2] * C[M - n][1];
}
ans = total;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
int a[300];
int main() {
while (1) {
memset(a, 0, sizeof(a));
cin >> n;
string s;
char c;
for (int i = 0; i < n; i++) {
cin >> s;
c = s[0];
a[c]++;
}
cout << a['M'] * a['A'] * (a['R'] + a['C'] + a['H']) +
a['M'] * a['R'] * (a['C'] + a['H']) + a['M'] * a['C'] * a['H'] +
a['A'] * a['R'] * (a['C'] + a['H']) + a['A'] * a['C'] * a['H'] +
a['R'] * a['C'] * a['H'];
cout << "\n";
}
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String s[] = new String[n];
int mCount = 0;
int aCount = 0;
int rCount = 0;
int cCount = 0;
int hCount = 0;
for(int i=0;i<n;i++){
s[i] = scanner.next();
switch(s[i].charAt(0)){
case 'M':
mCount++;
break;
case 'A':
aCount++;
break;
case 'R':
rCount++;
break;
case 'C':
cCount++;
break;
case 'H':
hCount++;
break;
}
}
int allCount = 0;
allCount += mCount * aCount * rCount;
allCount += mCount * aCount * cCount;
allCount += mCount * aCount * hCount;
allCount += mCount * rCount * cCount;
allCount += mCount * rCount * hCount;
allCount += mCount * cCount * hCount;
allCount += aCount * rCount * cCount;
allCount += aCount * rCount * hCount;
allCount += aCount * cCount * hCount;
allCount += rCount * cCount * hCount;
System.out.println(allCount);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\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 | hash = {}
%w|M A R C H|.each{ |c| hash[c] = 0 }
gets.to_i.times do
char = gets.chars[0]
if %w|M A R C H|.include?(char)
hash[char] += 1
end
end
m, a, r, c, h = hash["M"], hash["A"], hash["R"], hash["C"], hash["H"]
puts m * a * (r + c + h) + (m + a) * (r * c + r * h + c * h) + r * c * h
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-9;
long long cnt = 0;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
int n;
cin >> n;
vector<string> name(n);
vector<int> fi(5);
long long ans = 0;
for (int(i) = 0; (i) < (int)(n); i++) {
cin >> name.at(i);
if (name.at(i).at(0) == 'M') {
fi.at(0)++;
} else if (name.at(i).at(0) == 'A') {
fi.at(1)++;
} else if (name.at(i).at(0) == 'R') {
fi.at(2)++;
} else if (name.at(i).at(0) == 'C') {
fi.at(3)++;
} else if (name.at(i).at(0) == 'H') {
fi.at(4)++;
}
}
for (int(i) = 0; (i) < (int)(3); i++) {
for (int(j) = i + 1; (j) < (int)4; j++) {
for (int(k) = j + 1; (k) < (int)5; k++) {
ans += fi.at(i) * fi.at(j) * fi.at(k);
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | int main() {
long long n, a[5]={0,0,0,0,0}, r = 0;
scanf("%ld", &n);
for (int i = 0; i < n; i++) {
char s[10];
scanf("%s", s);
if (s[0] == 'M'){
a[0]++;
}
else if (s[0] == 'A') {
a[1]++;
}
else if (s[0] == 'R') {
a[2]++;
}
else if (s[0] == 'C') {
a[3]++;
}
else if (s[0] == 'H') {
a[4]++;
}
}
int ans;
for ( int z = 0; z < 3; z++) {
for ( int c = z+1; x < 4; x++){
for ( int v = c+1; v < 5; v++){
a[z]*a[c]*z[v] = ans;}}}}
cout<<ans<<endl;
return 0;
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N;
vector<string> S;
void input() {
cin >> N;
S = vector<string>(N);
for (int i = 0; i < (int)(N); i++) cin >> S[i];
}
long long comb3(long long n) {
long long ret = n * (n - 1) * (n - 2) / 6;
return ret;
}
long long comb2(long long n) { return n * (n - 1) / 2; }
int main() {
input();
set<char> s{'M', 'A', 'R', 'C', 'H'};
map<char, int> m;
int n = 0;
for (int i = 0; i < (int)(N); i++) {
if (s.count(S[i][0])) {
m[S[i][0]]++;
n++;
}
}
long long ans = comb3(n);
for (auto p : m) {
int v = p.second;
ans -= comb2(v) * (n - 2);
ans -= comb3(v);
}
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;
string s;
int m, a, r, c, h;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s[0] == 'M') m++;
if (s[0] == 'A') a++;
if (s[0] == 'R') r++;
if (s[0] == 'C') c++;
if (s[0] == 'H') h++;
}
cout << m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 |
n = int(input())
group = []
for i in range(n):
group.append(input()[0])
work = set([x for x in group if x == "M" or x == "A" or x == "R" or x == "C" or x == "H"])
print((len(group)-len(work))) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"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() {
size_t N;
scanf("%zu", &N);
intmax_t a[26] = {};
int b[26] = {};
for (size_t i = 0; i < N; ++i) {
char ch;
scanf(" %c%*s", &ch);
++a[ch - 'A'];
b[ch - 'A'] = 1;
}
if (b['M' - 'A'] + b['A' - 'A'] + b['R' - 'A'] + b['C' - 'A'] + b['H' - 'A'] <
3)
return !printf("0\n");
intmax_t res = 0;
int ind[] = {'M' - 'A', 'A' - 'A', 'R' - 'A', 'C' - 'A', 'H' - 'A'};
std::sort(ind, ind + 5);
do {
res += a[ind[0]] * a[ind[1]] * a[ind[2]];
} while (std::next_permutation(ind, ind + 5));
printf("%jd\n", res / 12);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, mm;
cin >> n;
long long m[5] = {0};
mm = n;
while (n--) {
string s;
cin >> s;
if (s[0] == 'M') {
m[0]++;
} else if (s[0] == 'A') {
m[1]++;
} else if (s[0] == 'R') {
m[2]++;
} else if (s[0] == 'C') {
m[3]++;
} else if (s[0] == 'H') {
m[4]++;
}
}
long long cnt = 0;
for (int i = 0; i < mm; i++) {
for (int j = i + 1; j < mm; j++) {
for (int k = j + 1; k < mm; k++) {
cnt += (m[i] * m[j] * m[k]);
}
}
}
cout << cnt << "\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 <iostream>
using namespace std;
int main(){
int n;
cin >> n;
string a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
long long int m,a,r,c,h;
for(int i=0;i<n;i++){
if(a[i].at(0)=='M'){
m++;
}
else if(a[i].at(0)=='A'){
a++;
}
else if(a[i].at(0)=='R'){
r++;
}
else if(a[i].at(0)=='C'){
c++;
}
else if(a[i].at(0)=='H'){
h++;
}
}
long long int ans;
ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import itertools
n = int(input())
ary = []
for i in range(n):
s = input()[0]
if s == "M" or s == "A" or s =="R" or s =="C" or s == "H":
ary.append(s)
print(len([ i for i in itertools.combinations(ary,3) if len(set(i)) == 3])) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < (n); i++) {
cin >> s[i];
}
int march[5] = {};
for (int i = 0; i < (n); i++) {
if (s[i][0] == 'M') {
march[0]++;
} else if (s[i][0] == 'A') {
march[1]++;
} else if (s[i][0] == 'R') {
march[2]++;
} else if (s[i][0] == 'C') {
march[3]++;
} else if (s[i][0] == 'H') {
march[4]++;
}
}
long long ans = 0;
long long res;
for (int i = 0; i < (3); i++) {
for (int j = (i + 1); j < (4); j++) {
for (int k = (j + 1); k < (5); k++) {
res = march[i] * march[j] * march[k];
ans += res;
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n = int(input())
s = [input() for i in range(n)]
order = "MARCH"
initial_arary = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]
ans = 0
for i in range(0, 5):
for j in range(i+1, 5):
for k in range(j+1, 5):
ans += nums[i] * nums[j] * nums[k]
print(ans)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
vector<int> vec(5);
cin >> n;
for (int i = 0; i < (int)(n); i++) {
string s;
cin >> s;
if (s.at(0) == 'M') {
vec.at(0) += 1;
} else if (s.at(0) == 'A') {
vec.at(1) += 1;
} else if (s.at(0) == 'R') {
vec.at(2) += 1;
} else if (s.at(0) == 'C') {
vec.at(3) += 1;
} else if (s.at(0) == 'H') {
vec.at(4) += 1;
}
}
for (int i = 0; i < (int)(3); i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += vec.at(i) * vec.at(j) * vec.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;
int dy[4] = {0, 0, 1, -1};
int dx[4] = {1, -1, 0, 0};
unsigned long long c[100000];
int main() {
long long x[5] = {0, 0, 0, 0, 0};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == 'M') x[0]++;
if (s[0] == 'A') x[1]++;
if (s[0] == 'R') x[2]++;
if (s[0] == 'C') x[3]++;
if (s[0] == 'H') x[4]++;
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
for (int k = j + 1; k < 5; k++) {
ans += (x[i] * x[j]) * x[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;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
int mp[5] = {};
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s[0] == 'M')
mp[0]++;
else if (s[0] == 'A')
mp[1]++;
else if (s[0] == 'R')
mp[2]++;
if (s[0] == 'C') mp[3]++;
if (s[0] == 'H') mp[4]++;
}
int cnt = 0;
for (int i = 0; i < 5; ++i)
if (mp[i] > 0) cnt++;
ll ans = 0;
if (cnt >= 3) {
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
for (int k = j + 1; k < 5; ++k) {
ans += (mp[i] * mp[j] * mp[k]);
}
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vc(5);
string s;
string march = "MARCH";
for (int i = 0; i < (n); i++) {
cin >> s;
for (int i = 0; i < (march.size()); i++) {
if (s[0] == march[i]) {
vc[i]++;
break;
}
}
}
long long int ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += vc[i] * vc[j] * vc[k];
}
}
}
cout << ans << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
}
int M, A, R, C, H;
M = 0;
A = 0;
R = 0;
C = 0;
H = 0;
for (int i = 0; i < N; i++) {
switch (S[i][0]) {
case 'M':
M++;
break;
case 'A':
A++;
break;
case 'R':
R++;
break;
case 'C':
C++;
break;
case 'H':
H++;
break;
}
}
long long int count = 0;
count += M * A * R;
count += M * A * C;
count += M * A * H;
count += M * R * C;
count += M * R * H;
count += M * C * H;
count += A * R * C;
count += A * R * H;
count += A * C * H;
count += R * C * H;
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;
bool check(int a, int b) { return a > b; }
int main() {
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt[5] = {};
for (int i = 0; i < n; i++) {
if (a[i][0] == 'M') cnt[0]++;
if (a[i][0] == 'A') cnt[1]++;
if (a[i][0] == 'R') cnt[2]++;
if (a[i][0] == 'C') cnt[3]++;
if (a[i][0] == 'H') cnt[4]++;
}
int ans = 0;
int tmp;
for (int i = 0; i < 10; i++) {
tmp = 1;
if (0 <= i && i <= 5) {
tmp *= cnt[0];
}
if (0 <= i && i <= 2 || 6 <= i && i <= 8) {
tmp *= cnt[1];
}
if (i == 0 || i == 3 || i == 4 || i == 6 || i == 7 || i == 9) {
tmp *= cnt[2];
}
if (i == 1 || i == 3 || i == 5 || i == 6 || i == 8 || i == 9) {
tmp *= cnt[3];
}
if (i == 2 || i == 4 || i == 5 || 7 <= i && i <= 9) {
tmp *= cnt[4];
}
ans += tmp;
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
int[] count ={0,0,0,0,0};// m a r c h
String s;
char ini;
for (int i = 0;i < n;++i){
s=scan.nextLine();
ini = s.charAt(0);
switch (ini) {
case 'M':++count[0];
break;
case 'A':++count[1];
break;
case 'R':++count[2];
break;
case 'C':++count[3];
break;
case 'H':++count[4];
break;
}
}
long ans=0;
for (int i = 0;i<5;++i){
for(int k = i+1;k<5;++k){
for(int j =k+1;j<5;++j){
ans+=count[i]*count[k]*count[j];
}
}
}
System.out.print(ans);
}
}
//end |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline string uppercase(string s) {
int n = (int)s.size();
for (int i = 0; i < n; i++)
if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
return s;
}
inline string lowercase(string s) {
int n = (int)s.size();
for (int i = 0; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
return s;
}
int main() {
long long n, ans = 0, x = 0;
cin >> n;
vector<string> s(n);
string str;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] != 'M' && str[0] != 'A' && str[0] != 'R' && str[0] != 'C' &&
str[0] != 'H')
x++;
else
s[i] = str;
}
n -= x;
sort((s).begin(), (s).end());
for (int i = 0; i < n; i++)
for (int i = 0; i < n; i++) {
for (int j = (i + 1); j < (n); j++) {
if (s[i][0] == s[j][0]) {
break;
for (int k = (j + 1); k < (n); k++) {
if (i == j || i == k)
continue;
else {
}
if (s[i][0] != s[k][0] && s[j][0] != s[k][0]) {
ans++;
}
}
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string a[1005000];
int b[7];
int u, o, cou, alld;
int ccc(int n, int r) {
if (r == 0 || r == n)
return (1);
else if (r == 1)
return (n);
return (ccc(n - 1, r - 1) + ccc(n - 1, r));
}
int main() {
cin >> o;
for (int i = 0; i < o; i++) {
cin >> a[i];
if (a[i][0] == 'M') {
if (b[1] == 0) {
cou++;
}
b[1]++;
}
if (a[i][0] == 'A') {
if (b[2] == 0) {
cou++;
}
b[2]++;
}
if (a[i][0] == 'R') {
if (b[3] == 0) {
cou++;
}
b[3]++;
}
if (a[i][0] == 'C') {
if (b[4] == 0) {
cou++;
}
b[4]++;
}
if (a[i][0] == 'H') {
if (b[5] == 0) {
cou++;
}
b[5]++;
}
}
if (cou < 3) {
cout << "0" << endl;
return 0;
}
if (1) alld += b[1] * b[2] * b[3];
if (2) alld += b[1] * b[2] * b[4];
if (3) alld += b[1] * b[2] * b[5];
if (4) alld += b[1] * b[3] * b[4];
if (5) alld += b[1] * b[3] * b[5];
if (6) alld += b[1] * b[4] * b[5];
if (7) alld += b[2] * b[3] * b[4];
if (8) alld += b[2] * b[3] * b[5];
if (9) alld += b[2] * b[4] * b[5];
if (10) alld += b[3] * b[4] * b[5];
cout << alld << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> CC(5);
for (int i = 0; i < (N); ++i) {
string S;
cin >> S;
switch (S[0]) {
case 'M':
CC[0]++;
break;
case 'A':
CC[1]++;
break;
case 'R':
CC[2]++;
break;
case 'C':
CC[3]++;
break;
case 'H':
CC[4]++;
break;
default:
break;
}
}
long long ans = 0;
for (int i = 0; i < (5); ++i) {
for (int j = i + 1; j < (5); ++j) {
for (int k = j + 1; k < (5); ++k) {
ans += CC[i] * CC[j] * CC[k];
}
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int m = 0;
int a = 0;
int r = 0;
int c = 0;
int h = 0;
for (int i = 0; i < N; i++) {
String s = sc.next();
if (s.charAt(0) == 'M') m++;
if (s.charAt(0) == 'A') a++;
if (s.charAt(0) == 'R') r++;
if (s.charAt(0) == 'C') c++;
if (s.charAt(0) == 'H') h++;
}
long ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
System.out.println(ans);
}
} |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s[N];
bool f = false;
for (int i = 0; i < N; i++) {
cin >> s[i];
if (s[i] == "Y") {
f = true;
}
}
if (f) {
cout << "Four" << endl;
} else {
cout << "Three" << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
d={'M':0,'A':0,'R':0,'C':0,'H':0}
n=int(input())
for i in range(n):
word=input()
if word[0] in d: d[word[0]]+=1
m = sum(d.values())
max = combinations_count(m,3)
if m<3:
print(0)
exit()
sub = 0
for i in d.values():
if i>=3: sub += combinations_count(i, 3)
if i>=2: sub += combinations_count(i, 2) * (m-2)
print(max - sub)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\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 double PI = 3.1415926;
const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
int main() {
int n;
scanf("%d", &n);
int m, a, r, c, h;
m = a = r = c = h = 0;
while (n--) {
char s[15];
scanf("%s", 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 = m * a * c + m * a * r + m * a * h + a * r * c + a * r * h +
r * c * h + a * c * h + m * r * c + m * r * h + m * 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 | python3 |
member = []
count = 0
name_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
N = int(input())
for i in range(N):
name = input()
member.append(name)
for i in range(N):
if member[i][0] in name_count:
name_count[member[i][0]] += 1
count += name_count['M'] * name_count['A'] * name_count['R']
count += name_count['M'] * name_count['A'] * name_count['C']
count += name_count['M'] * name_count['A'] * name_count['H']
count += name_count['M'] * name_count['R'] * name_count['C']
count += name_count['M'] * name_count['R'] * name_count['H']
count += name_count['M'] * name_count['C'] * name_count['H']
count += name_count['A'] * name_count['C'] * name_count['R']
count += name_count['A'] * name_count['H'] * name_count['R']
count += name_count['H'] * name_count['C'] * name_count['R']
print(count)
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
long long ans = 1;
int march[5] = {0};
int n, sum = 0, el = 0;
scanf("%d", &n);
char s[15];
for (int i = 0; i < n; i++) {
scanf("%s", s);
switch (s[0]) {
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
default:
break;
}
}
for (int i = 0; i < 5; i++) {
if (march[i] != 0) {
sum++;
ans *= march[i];
} else
el = i;
}
if (sum < 3)
ans = 0;
else if (sum == 4) {
ans = 0;
march[el] = march[4];
for (int i = 0; i < 2; i++) {
for (int j = i + 1; j < 3; j++) {
for (int k = j + 1; k < 4; k++) {
ans += march[i] * march[j] * march[k];
}
}
}
} else if (sum == 5) {
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];
}
}
}
}
printf("%lld", ans);
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
long long n;
cin >> n;
vector<long long> march(5, 0);
string s;
for (long long i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'M') {
march[0] += 1;
} else if (s[0] == 'A') {
march[1] += 1;
} else if (s[0] == 'R') {
march[2] += 1;
} else if (s[0] == 'C') {
march[3] += 1;
} else if (s[0] == 'H') {
march[4] += 1;
}
}
long long count = 0;
for (long long i = 0; i < n; i++) {
if (march[i] > 0) {
count += 1;
}
}
long long res = 0;
if (count <= 2) {
cout << 0 << endl;
return 0;
} else {
for (long long i = 0; i < 5; i++) {
for (long long j = 0; j < 5; j++) {
for (long long k = 0; k < 5; k++) {
if (i < j && j < k) {
res += (long long)march[i] * march[j] * march[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 | python3 | n = int(input())
tmp = [0] * 5
for i in range(n):
s = input()
if s[0] == 'M':
tmp[0] += 1
elif s[0] == 'A':
tmp[1] += 1
elif s[0] == 'R':
tmp[2] += 1
elif s[0] == 'C':
tmp[3] =+ 1
elif s[0] == 'H':
tmp[4] += 1
ans = 0
for i in range(3):
for j in range(i+1, 4):
for k in range(j+1, 5):
ans += tmp[i]*tmp[j]*tmp[k]
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | url = "https://atcoder.jp/contests/abc089/tasks/abc089_c"
import itertools
import math
def main():
mojiretu = ('M', 'A', 'R', 'C', 'H')
t = input()
ttt = []
for i in range(int(t)):
tmp = input()
if tmp[0] in mojiretu:
ttt.append(tmp)
if len(ttt) < 3:
print(0)
exit()
li = list(itertools.combinations([v[0] for v in ttt], 3))
count = 0
for s in li:
if len(set(s)) == 3:
count += 1
print(count)
if __name__ == '__main__':
main()
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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 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 main() {
long long N, countm = 0, counta = 0, countr = 0, countc = 0, counth = 0;
long long ans = 0;
string people;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> people;
if (people[0] == 'M') countm++;
if (people[0] == 'A') counta++;
if (people[0] == 'R') countr++;
if (people[0] == 'C') countc++;
if (people[0] == 'H') counth++;
}
ans = countm * counta * countr + countm * counta * countc +
countm * counta * counth + countm * countr * countc +
countm * countr * counth + countm * countc * counth +
counta * countr * countc + counta * countr * counth +
countr * countc * counth;
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<int, int>;
using ull = unsigned long long;
int gcd(int x, int y);
int fac(ll n, vector<int> num);
const int INF = 1001001001;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
ll n;
cin >> n;
vector<int> ch('Z' + 1);
ll flag = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
ch[s[0]]++;
}
ll ans = 0;
ans += ch['M'] * ch['A'] * ch['R'];
ans += ch['M'] * ch['A'] * ch['C'];
ans += ch['M'] * ch['A'] * ch['H'];
ans += ch['M'] * ch['R'] * ch['C'];
ans += ch['M'] * ch['R'] * ch['H'];
ans += ch['M'] * ch['C'] * ch['H'];
ans += ch['A'] * ch['R'] * ch['C'];
ans += ch['A'] * ch['R'] * ch['H'];
ans += ch['A'] * ch['C'] * ch['H'];
ans += ch['R'] * ch['C'] * ch['H'];
cout << ans << endl;
return 0;
}
int gcd(int x, int y) {
int num[3];
num[0] = (x > y) ? x : y;
num[1] = (x <= y) ? x : y;
num[2] = num[0] % num[1];
while (num[2]) {
num[0] = num[1];
num[1] = num[2];
num[2] = num[0] % num[1];
}
return num[1];
}
int fac(ll n, vector<int> num) {
ll kazu = n;
for (int i = 2; i <= sqrt(n); i++) {
while (1) {
if (kazu % i != 0) break;
kazu /= i;
num[i]++;
}
}
if (kazu == n && n != 1) return 1;
int ans = 0;
if (kazu != 1) ans++;
for (int i = 2; i <= sqrt(n); i++) {
for (int j = 1; j <= num[i]; j++) {
num[i] -= j;
ans++;
}
}
return 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() {
long long int N, count = 0;
vector<long long int> f(5, 0);
long long int ans = 0, sum = 1;
string name;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> name;
if (name[0] == 'M') {
f[0]++;
} else if (name[0] == 'A') {
f[1]++;
} else if (name[0] == 'R') {
f[2]++;
} else if (name[0] == 'C') {
f[3]++;
} else if (name[0] == 'H') {
f[4]++;
}
}
for (int i = 0; i < 5; i++) {
if (0 < f[i]) {
count++;
sum *= f[i];
}
}
if (count < 3) {
cout << 0 << endl;
} else if (count == 3) {
cout << sum << endl;
} else if (count == 4) {
for (int i = 0; i < 5; i++) {
if (f[i] != 0) {
ans += sum / f[i];
}
}
cout << ans << endl;
} else {
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
ans += sum / f[i] / f[j];
}
}
cout << ans << endl;
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
return a = (a > b) ? b : a;
}
long long const INF = 1LL << 60;
long long const MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
;
long long N;
cin >> N;
vector<string> S(N);
for (long long i = 0; i < (N); i++) cin >> S[i];
vector<long long> cnt(5, 0);
for (long long 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 total = 0;
for (long long i = 0; i < (N); i++) {
if (cnt[i] > 0) {
total++;
}
}
if (total < 3) {
cout << 0 << endl;
return 0;
}
long long ans = 0;
for (long long i = 0; i < (5); i++) {
for (long long j = (i + 1); j < (5); j++) {
for (long long 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() {
set<char> s;
string t;
map<char, int> m;
int n;
cin >> n;
string march = "MARCH";
for (int i = 0; i < n; i++) {
cin >> t;
if (march.find(t[0]) == string::npos) continue;
if (s.find(t[0]) == s.end()) {
s.insert(t[0]);
m[t[0]] = 1;
} else {
m[t[0]] = m[t[0]] + 1;
}
}
vector<char> v(m.size());
int sum = 0;
if (m.size() < 3) {
cout << 0;
} else {
for (int i = m.size() - 1; i > int(m.size()) - 4; i--) {
v[i] = 1;
}
vector<int> vec(s.begin(), s.end());
do {
int tmp = 1;
for (int i = 0; i < v.size(); i++) {
if (v[i] == 0) continue;
char c = vec[i];
if (m[c] <= 0) continue;
int mc = m[c];
tmp *= mc;
}
sum += tmp;
} while (next_permutation(v.begin(), v.end()));
cout << sum;
}
cout << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n=int(input())
s=[input() for i in range(n)]
dic={}
for i in s:
if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
if i[0] in dic:
dic[i[0]]+=1
else:
dic[i[0]]=1
if len(dic)<3:
ans=0
else:
if len(dic)==3:
ans = 1
for i in dic.values():
ans *=i
elif len(dic)==4:
ans = 4
for i in dic.values():
ans += 3*(i-1)
else:
ans = 10
for i in dic.values():
ans += 6*(i-1)
print(ans) |
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> A(n);
vector<int> count(5);
for (int i = 0; i < (n); ++i) {
cin >> A[i];
if (A[i][0] == 'M') {
count[0]++;
} else if (A[i][0] == 'A') {
count[1]++;
} else if (A[i][0] == 'R') {
count[2]++;
} else if (A[i][0] == 'C') {
count[3]++;
} else if (A[i][0] == 'H') {
count[4]++;
}
}
int ans = 0;
for (int i = 0; i < (1 << 5) - 1; i++) {
int a = 1;
int b = 0;
for (int j = 0; j < 5; j++) {
if ((i >> j) & 1 == 1) {
a *= count[j];
b++;
}
}
if (b == 3) {
ans += a;
}
}
cout << ans << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5;
long long v[max_n];
int n;
void solve() {
long long sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
sum += v[i] * v[j] * v[k];
}
}
}
cout << sum << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
char s[10];
scanf("%s", 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]++;
}
solve();
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> name;
vector<int> count(5, 0);
for (int i = 0; i < n; i++) {
string tmp;
cin >> tmp;
name.push_back(tmp);
if (name[i][0] == 'M') {
count[0]++;
} else if (name[i][0] == 'A') {
count[1]++;
} else if (name[i][0] == 'R') {
count[2]++;
} else if (name[i][0] == 'C') {
count[3]++;
} else if (name[i][0] == 'H') {
count[4]++;
}
}
long long res = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
res += (count[i] * count[j] * count[k]);
}
}
}
cout << res << endl;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
int n;
cin >> n;
int ans = 0, cntm, cnta, cntr, cntc, cnth;
string S;
int C[5] = {0};
for (int i = 0; i < n; i++) {
cin >> S;
if (S[0] == 'M')
cntm++;
else if (S[0] == 'A')
cnta++;
else if (S[0] == 'R')
cntr++;
else if (S[0] == 'C')
cntc++;
else if (S[0] == 'H')
cnth++;
}
C[0] = cntm;
C[1] = cnta;
C[2] = cntr;
C[3] = cntc;
C[4] = cnth;
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;
cout << endl;
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class BidirectionalIterator>
bool next_combination(BidirectionalIterator first1, BidirectionalIterator last1,
BidirectionalIterator first2,
BidirectionalIterator last2) {
if ((first1 == last1) || (first2 == last2)) {
return false;
}
BidirectionalIterator m1 = last1;
BidirectionalIterator m2 = last2;
--m2;
while (--m1 != first1 && !(*m1 < *m2)) {
}
bool result = (m1 == first1) && !(*first1 < *m2);
if (!result) {
while (first2 != m2 && !(*m1 < *first2)) {
++first2;
}
first1 = m1;
iter_swap(first1, first2);
++first1;
++first2;
}
if ((first1 != last1) && (first2 != last2)) {
m1 = last1;
m2 = first2;
while ((m1 != first1) && (m2 != last2)) {
iter_swap(--m1, m2);
++m2;
}
reverse(first1, m1);
reverse(first1, last1);
reverse(m2, last2);
reverse(first2, last2);
}
return !result;
}
template <class BidirectionalIterator>
bool next_combination(BidirectionalIterator first, BidirectionalIterator middle,
BidirectionalIterator last) {
return next_combination(first, middle, middle, last);
}
template <class BidirectionalIterator>
inline bool prev_combination(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last) {
return next_combination(middle, last, first, middle);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, sum = 0;
string s;
cin >> n;
int cnt[5] = {0};
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]++;
}
const int N = 5;
const int K = 3;
array<int, N> ar;
iota(ar.begin(), ar.end(), 0);
do {
int tmp = 1;
for (int i = 0; i < K; i++) {
tmp *= cnt[ar[i]];
}
sum += tmp;
} while (next_combination(ar.begin(), ar.begin() + K, ar.end()));
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 | UNKNOWN | #include <bits/stdc++.h>
long long int compare(const void* a, const void* b) {
return *(long long int*)b - *(long long int*)a;
}
int main(void) {
int n;
scanf("%d", &n);
char s[100000][20];
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
long int e[26];
for (int i = 0; i < 26; i++) {
e[i] = 0;
}
for (int i = 0; i < n; i++) {
e[(int)s[i][0] - 65]++;
}
long long int d = e[0] + e[2] + e[82 - 65] + e[72 - 65] + e[77 - 65];
if (d == 0) {
printf("0");
return 0;
}
long long int l = d;
l = d * (d - 1) * (d - 2) / 6 - (d - 2);
printf("%lld\n", l);
return 0;
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Linq;
class Program
{
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] l = new int[5] {0,0,0,0,0};
for(int i = 0; i < n; i ++) {
string s = Console.ReadLine();
if(s[0]=='M') l[0] ++;
if(s[0]=='A') l[1] ++;
if(s[0]=='R') l[2] ++;
if(s[0]=='C') l[3] ++;
if(s[0]=='H') l[4] ++;
}
Console.WriteLine(solve(l));
}
static long solve(int[] l) {
long count = 0;
count += l[0] * l[1] * (l[2]+l[3]+l[4]);
count += l[0] * l[2] * (l[3]+l[4]);
count += l[0] * l[3] * l[4];
count += l[1] * l[2] * (l[3]+l[4]);
count += l[1] * l[3] * l[4];
count += l[2] * l[3] * l[4];
return 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;
long long int ans;
int main() {
int n, f[10], i, g;
ans = g = 0;
char a[100001][10];
memset(f, 0, sizeof(f));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", &a[i]);
if (a[i][0] == 'A')
f[1] += 1;
else if (a[i][0] == 'M')
f[2] += 1;
else if (a[i][0] == 'R')
f[3] += 1;
else if (a[i][0] == 'H')
f[4] += 1;
else if (a[i][0] == 'C')
f[5] += 1;
}
ans += f[1] * f[2] * f[3];
ans += f[1] * f[2] * f[4];
ans += f[1] * f[2] * f[5];
ans += f[2] * f[3] * f[4];
ans += f[2] * f[3] * f[5];
ans += f[1] * f[3] * f[4];
ans += f[1] * f[3] * f[5];
ans += f[1] * f[4] * f[5];
ans += f[2] * f[4] * f[5];
ans += f[3] * f[4] * f[5];
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;
long long C[30][30];
void Comb(long long a) {
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
}
}
int main() {
long long n;
cin >> n;
long long cm = 0, ca = 0, cr = 0, cc = 0, ch = 0;
bool fm = false, fa = false, fr = false, fc = false, fh = false;
for (long long i = 0; i < n; i++) {
string x;
cin >> x;
char c = x.at(0);
if (c == 'M') {
cm++;
fm = true;
} else if (c == 'A') {
ca++;
fa = true;
} else if (c == 'R') {
cr++;
fr = true;
} else if (c == 'C') {
cc++;
fc = true;
} else if (c == 'H') {
ch++;
fh = true;
}
}
long long z = 0, base = cm + ca + cr + cc + ch, minus = 0;
Comb(base + 1);
if (cm > 1) {
if (fa) z++;
if (fr) z++;
if (fc) z++;
if (fh) z++;
minus += z * C[cm][2];
}
if (ca > 1) {
z = 0;
if (fm) z++;
if (fr) z++;
if (fc) z++;
if (fh) z++;
minus += z * C[ca][2];
}
if (cr > 1) {
z = 0;
if (fm) z++;
if (fa) z++;
if (fc) z++;
if (fh) z++;
minus += z * C[cr][2];
}
if (cc > 1) {
z = 0;
if (fm) z++;
if (fr) z++;
if (fa) z++;
if (fh) z++;
minus += z * C[cc][2];
}
if (ch > 1) {
z = 0;
if (fm) z++;
if (fr) z++;
if (fc) z++;
if (fa) z++;
minus += z * C[ch][2];
}
cout << C[base][3] - minus << 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;
int m = 0, a = 0, r = 0, c = 0, h = 0;
string str;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str;
if (str[0] == 'M')
m++;
else if (str[0] == 'A')
a++;
else if (str[0] == 'R')
r++;
else if (str[0] == 'C')
c++;
else if (str[0] == 'H')
h++;
}
unsigned long long int ans = m * a * (r + c + h) +
m * (r * c + r * h + c * h) + a * r * (c + 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 | UNKNOWN | using System;
namespace abc089_c
{
class program
{
static void Main(string[] args)
{
ChangeLocalDebugInput();
int N = int.Parse(Console.ReadLine());
int[] march = new int[5];
for (int i = 0; i < N; i++)
{
string input = Console.ReadLine();
if (input[0] == 'M') {
march[0]++;
} else if (input[0] == 'A')
{
march[1]++;
}
else if (input[0] == 'R')
{
march[2]++;
}
else if (input[0] == 'C')
{
march[3]++;
}
else if (input[0] == 'H')
{
march[4]++;
}
}
long answer = march[0] * march[1] * march[2] + march[0] * march[1] * march[3] +
march[0] * march[1] * march[4] + march[0] * march[2] * march[3] + march[0] * march[2] * march[4] +
march[0] * march[3] * march[4] + march[1] * march[2] * march[3] +
march[1] * march[2] * march[4] + march[1] * march[3] * march[4] + march[2] * march[3] * march[4];
Console.WriteLine(answer);
}
[System.Diagnostics.Conditional("LOCAL_DEBUG")]
static void ChangeLocalDebugInput()
{
Console.SetIn(new System.IO.StreamReader("../../stdin.txt"));
}
}
}
|
p03425 AtCoder Beginner Contest 089 - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
* The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.
* There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.
Constraints
* 1 \leq N \leq 10^5
* S_i consists of uppercase English letters.
* 1 \leq |S_i| \leq 10
* S_i \neq S_j (i \neq j)
Input
Input is given from Standard Input in the following format:
N
S_1
:
S_N
Output
If there are x ways to choose three people so that the given conditions are met, print x.
Examples
Input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
Output
2
Input
4
ZZ
ZZZ
Z
ZZZZZZZZZZ
Output
0
Input
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
Output
7 | {
"input": [
"5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI",
"5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO",
"4\nZZ\nZZZ\nZ\nZZZZZZZZZZ"
],
"output": [
"2",
"7",
"0"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | from itertools import*;print(sum(p*q*r for p,q,r in list(combinations([len(list(v))for k,v in groupby(sorted(s[0]for s in open(0).readlines()[1:]))],3)))) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.