akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}


int main()
{
	ll n,k,ans = 0;
	cin >> n >> k;
	vll h(n);
	rep(i,n)cin >> h[i];
	sort(all(h));
	rep(i,n-k)ans += h[i];
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
s = input()

# $ python rot_n.py s rot
import sys

def rot_n(c, n):
    if 'a' <= c and c <= 'z':
        return chr((ord(c) - ord('a') + int(n)) % 26 + ord('a'))
    
    if 'A' <= c and c <= 'Z':
        return chr((ord(c) - ord('A') + int(n)) % 26 + ord('A'))
    
    return c

def rot(s, n):
    c = (rot_n(c, n) for c in s)
    print( ''.join(c))

rot(s, n)

Measured memory_bytes: 40176
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, T;

int main() {
	scanf("%d%d", &N, &T);
	
	vector<pair<string, int>> result;
	char st_name[52], ar_name[52];
	int st_hh, st_mm, ar_hh, ar_mm;
	scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name);
	for (int i = 1; i < N; i++) {
		int pre = ar_hh * 60 + ar_mm;
		scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name);
		int cur = st_hh * 60 + st_mm;
		if (cur - pre >= T) {
			result.emplace_back(st_name, cur - pre);
		}
	}
	
	cout << result.size() << endl;
	for (auto r : result) {
		cout << r.first << ' ' << r.second << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

const int N = 200002;
ll f[N];

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x, mod-2);
}

ll C(int n, int r){
    ll ret = f[n];
    (ret *= mod_inv(f[r])) %= mod;
    (ret *= mod_inv(f[n-r])) %= mod;
    return ret;
}


int main(){
    f[0] = 1;
    rep(i,N-1) f[i+1] = f[i]*(i+1)%mod;

    int h,w,k;
    cin >>h >>w >>k;

    ll now = 0;
    rep(i,h)rep(j,w) (now += i+j) %= mod;

    ll s = 0;
    rep(i,h){
        ll tmp = now;
        rep(j,w){
            (s += now) %= mod;

            ll p = j+1, m = w-p;
            now = (now + (p-m)*h + mod)%mod;
        }

        now = tmp;
        ll p = i+1, m = h-p;
        now = (now + (p-m)*w + mod)%mod;
    }
    (s *= mod_inv(2)) %= mod;

    cout << s*C(h*w-2, k-2)%mod << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a);i<(n);++i)
#define per(i, a, n) for(int i=(a);i>(n);--i)
#define pb emplace_back
#define mp make_pair
#define lowbit(x) (x & -x)

typedef long long LL;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 2e5 + 10;
int n;
char s[100];

void decode(int &c2, int &c5){
	int len = strlen(s);
	LL a, b;
	bool flag = 0;
	int m = 0;
	rep(i, 0, len){
		if(s[i] == '.'){
			sscanf(s, "%lld.%lld", &a, &b);
			flag = 1;
			m = len - i - 1;
			break;
		}
	}
	if(!flag){
		sscanf(s, "%lld", &a);
		b = 0;
		m = 0;
	}

	rep(i, 0, m)	a = a * 10;
	a = a + b;

	rep(i, m, 9)	a = a * 10;

	c2=0, c5=0;

	while(a % 2 == 0){
		a >>= 1;
		++c2;
	}
	while(a % 5 == 0){
		a /= 5;
		++c5;
	}
}

map<pii, int> MP;

int main(){
	scanf("%d", &n);

	int c2, c5;

	LL ans = 0;

	rep(i, 0, n){
		scanf("%s", s);
		decode(c2, c5);
		
		MP[mp(c2, c5)]++;
	}

	for(auto it : MP){
		for(auto it1 : MP){
			c2 = it.first.first + it1.first.first;
			c5 = it.first.second + it1.first.second;
			if(min(c2, c5) >= 18){
				if(it.first < it1.first){
					ans += 1LL * it.second * it1.second;
				} else if(it.first == it1.first){
					ans += 1LL * it.second * (it1.second - 1) / 2;
				}
			}
		}
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	reverse(A,A+N);
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p-1,A+p+c-1);

 }
 cout << A[0] << endl;
 }
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    if(a<=8 & b<=8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            double r = (double)(N - N / 2) / N;

            Console.WriteLine(r);

        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N;
        cin >> N;
        map<ll, int> mp;
        mp[0]++;
        ll val = 0;

        for (int i = 0; i < N; ++i) {
            ll tmp;
            cin >> tmp;
            val += tmp;
            mp[val]++;
        }

        ll ans = 0;
        for (auto e : mp) {
            ll tmp = e.second;
            ans += (tmp - 1) * tmp / 2;
        }
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 12800
N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
xy_xmin = sorted(xy,key=lambda x:x[0])
ans = float("INF")
for i in range(N):
    for j in range(i+K-1,N):
        X = xy_xmin[j][0] - xy_xmin[i][0]
        xy_ymin = sorted(xy_xmin[i:j+1],key=lambda x:x[1])
        Y = float("INF")
        for k in range(0,j-i-K+2):
            Y = min(Y,xy_ymin[k+K-1][1]-xy_ymin[k][1])
        ans = min(ans,X*Y)
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;


const int MAX_N = 100005;

int n,m,dp[MAX_N];
vector<int> adjl[MAX_N];

int f(int i)
{
	if (dp[i]!=-1)
		return dp[i];
	int r=0;
	for (int x : adjl[i])
		r=max(r,1+f(x));
	return dp[i]=r;
}

int main()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++)
		dp[i]=-1;
	while (m--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		adjl[a].push_back(b);
	}
	int ans=0;
	for (int i=1; i<=n; i++)
		ans=max(ans,f(i));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8192
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    String s=in.next();
    if(s.compareTo("Sunny")==0)
    {
      System.out.println("Cloudy");
    }
    else if(s.compareTo("Cloudy")==0)
    {
      System.out.println("Rainy");
    }
    else
    {
      System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 35492
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
    ll x;
    cin >> x;
    unordered_map<ll,int> mp;

    for(int i=1000;;i--){
        ll c = 1;
        for(int j=0;j<5;++j) c*=i;
        if(mp[c+x])
            return cout << mp[c+x] << " " << i << endl,0;
        
        if(mp[x-c]) 
            return cout << mp[x-c] << " " << -i << endl,0;
        mp[c] = i;
    }
    
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        int n, m, k, ans = 0;
        char a[7][7];
        cin >> n >> m >> k;
        for(int i = 1; i <= n; ++i)
                for(int j = 1; j <= m; ++j)
                        cin >> a[i][j];
        for(int r = 0; r < (1 << n); ++r)
                for(int c = 0; c < (1 << m); ++c) {
                        char b[7][7];
                        for(int i = 1; i <= n; ++i)
                                for(int j = 1; j <= m; ++j)
                                        b[i][j] = a[i][j];
                        for(int x = 0; x < 8; ++x) {
                                if((r >> x) & 1)
                                        for(int j = 1; j <= m; ++j) b[x + 1][j] = 'R';
                                if((c >> x) & 1)
                                        for(int i = 1; i <= n; ++i) b[i][x + 1] = 'R';
                        }
                        int cnt = 0;
                        for(int i = 1; i <= n; ++i)
                                for(int j = 1; j <= m; ++j)
                                        if(b[i][j] == '#') ++cnt;
                        if(cnt == k) ++ans;
                }

        cout << ans;

        return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  long N; cin >> N;
  long A[100010];
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A, A+N, greater<>());
  
  long ans = 0;
  int A_first = -1;
  for (int i = 0; i < N - 3; i++) {
    if (A[i] == A[i+1]) {
      A_first = i;
      break;
    }
  }
  int A_second = -1;
  for (int j = 2; j < N - 1; j++) {
    if (A[j] == A[j+1] && j != A_first && j != A_first + 1) {
      A_second = j;
      break;
    }
  }
  
  if (A_first != -1 && A_second != -1)
    ans = A[A_first] * A[A_second];
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
using namespace std;
using LLI = long long int;


int main(int argc, char *argv[])
{
    vector<int> v(3);
    for (int i=0; i<3; i++) {
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    int S = v[0] * v[1] / 2;

    cout << S;    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  char s[15];
  scanf("%d %d %s",&a,&b,s);

  bool flag=true;
  for (int i=0; i<a+b+2; i++) {
    if (i == a) {
      if (s[i] != '-') {
	flag = false;
      }
    }
    else if (i == a+b+1) {
      if (s[i] != '\0') {
	flag = false;
      }
    }
    else {
      if (s[i]<'0'||'9'<s[i]) {
	flag = false;
      }
    }
  }

  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

bool isSquared(int num){
    for(int i = 1; i <= num; ++i){
        if(i*i == num) return true;
    }
    return false;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for (int i = 0; i < n; ++i){
        for (int j = 0; j < d; ++j) cin >> x[i][j];
    }
    
    int res = 0;
    for (int i = 0; i < n-1; ++i){
        for (int j = i+1; j < n; ++j){
            int distance_sq = 0;
            for (int dim = 0; dim < d; ++dim){
                distance_sq += abs(x[i][dim]-x[j][dim]) * abs(x[i][dim]-x[j][dim]);
            }
            
            if(isSquared(distance_sq)) res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll X,Y;cin>>X>>Y;
    REP(i,X+1){
        REP(j,X+1){
            if(i+j!=X)continue;
            if(i*2+j*4==Y){
                cout<<"Yes"<<"\n";
                exit(0);
            }
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int count = 0;
    for (int i = 0; i < len; i++){
        if (!(S.at(i) >= 'a' && S.at(i) <= 'z')){
            count--;
        }
    }
    if (S.at(0) == 'A'){
        count += 10;
    }
    for (int i = 2; i < len - 1; i++){
        if (S.at(i) == 'C'){
            count += 100;
        }
    }
    if (count == 108){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int sum;
  while(cin >> str && str!="0"){
    sum = 0;
    for(int i=0,l=str.size();i<l;i++) sum += str[i]-'0';
    cout << sum << endl;
  }
}


Measured memory_bytes: 3196
def gcd(a, b):
  if a < b:
    a, b = b, a
  while a % b:
    a, b = b, a % b
  return b
N = int(input())
A = list(map(int, input().split()))
d = A[0]
for i in range(N):
  d = gcd(d, A[i])
print(d)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	ll n, k;
	cin >> n >> k;
	ll ans = 0ll;
	REPN(b, k + 1, n) {
		ans += n / b * (b - k);
		if (n % b != 0 && n % b >= k) {
			ans += n % b - k;
			if (k > 0) {
				ans++;
			}
		}
		//cout << b << " " << ans << endl;
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int red=0, blue=0;
    for(int i = 0; i < n; i++)
    {
        if (s[i] == 'R') {
            red++;
        }
        else
        {
            blue++;
        }
    }
    if (red > blue) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
N = int(input())
ba = b = a = ans = 0
for i in range(N):
    s = input()
    ans += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B':
        b += 1
    elif s[-1] == 'A':
        a += 1

if ba == 0:
    ans += min(a, b)
else:
    if a + b > 0:
        ans += ba + min(a, b)
    else:
        ans += ba - 1

print(ans)

Measured memory_bytes: 3188
$stdin.read.split(?\n)[1..-1].map { |ta| ta.split.map(&:to_i) }.tap do |(t, a), *rest|
  rest.each do |nt, na|
    if (tx = (t+nt-1)/nt) > (ax = (a+na-1)/na)
      t = nt * tx
      a = na * tx
    else
      t = nt * ax
      a = na * ax
    end
  end

  puts t + a
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define f(a, n) for (int a=0; a<n; a++)
#define F(a, n) for (int a=1; a<=n; a++)
#define ll long long
using namespace std;
const ll MOD = 1000000007;
unordered_map<ll, ll> gmp;
ll pairit(ll a, ll b){
	return (a<<32) + b;	
}
ll g(ll a, ll b){
	if (a==0) return 0;
	if (a==1) return 1;
	ll tmp=pairit(a,b);
	if (gmp.count(tmp)) return gmp[tmp];	
	if (b==0) gmp[tmp] = (g(a-1, 0) + g(a-1, 1) ) %MOD;
	else gmp[tmp] = (g(a, b-1) + g(a-1, b+1)) % MOD;
	return gmp[tmp];
}
ll powa(ll a, ll b){
	if (b<=0) return 1;
	else if (b%2) return (powa((a*a)%MOD,b/2) * a) % MOD;
	return powa((a*a)%MOD,b/2);
}
ll N, K;
int main(){
	ios::sync_with_stdio(false);
	cin>>N>>K;
	cout<<( (g(K, N-K) - g(K-1, N-K+1) + MOD)* powa(2, N-K-1) ) % MOD << endl; 
	return 0;
}


Measured memory_bytes: 79568
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


    


n=l()[0]
A=l()
B=[]
for i in range(n):
    if(i+1==A[i]):
        B.append(1)
    else:
        B.append(0)
ans=0
for i in range(n):
    if(i!=n-1 and B[i]==1):
        B[i]=0
        B[i+1]=0
        ans+=1
    if(i==n-1 and B[i]==1):
        ans+=1
print(ans)



Measured memory_bytes: 15936
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var b = new int[n];
        for (int i = 0; i < n; i++) b[i] = a[i] - (i + 1);
        Array.Sort(b);
        var med = b[n / 2];
        Console.WriteLine(getSum(a, med));
    }
    public static long getSum(int[] a, int b)
    {
        var n = a.Length;
        var ret = 0L;
        for (int i = 0; i < n; i++)
            ret += Math.Abs(a[i] - b - i - 1);
        return ret;
    }
}

Measured memory_bytes: 28636
#include <cstdio>
char s[26];
int a[26];
int main() {
	scanf("%s", s);
	for(int i = 0; s[i] != '\0'; i++) {
		if(!a[s[i]-'a']) 
			a[s[i]-'a']++;
		else {
			printf("no\n");
			return 0;
		}
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int i, j;
    int cnt = 0;
    int res = 0;
    for (i = 1; i <= n; i++)
    {
        if (i % 2 != 0)
        {
            cnt = 0;
            for (j = 1; j <= i; j++) {
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 8) {
                res++;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
a = gets.chomp.to_i
b = gets.chomp.split(" ").map(&:to_i)

cnt = a/2
upsor = b.sort
dwsor = b.sort {|a, b| b <=> a }

max = upsor.slice(cnt-1)
min = dwsor.slice(cnt-1)

puts (min-max)

Measured memory_bytes: 10992
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h1, m1, h2, m2, K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;
    ll ans = h2 * 60 + m2 - h1 *  60 - m1 - K;
    cout << ans << endl;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_044
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] ps = ReadInts();

            bool[,] left = new bool[n, n];
            int[,] costs = new int[n, n];
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    costs[i, j] = Min(Min(i, (n - i - 1)), Min(j, n - j - 1));
                }
            }

            int res = 0;
            int[] dx = new int[4] { 1, -1, 0, 0 };
            int[] dy = new int[4] { 0, 0, 1, -1 };
            for (int i = 0; i < n * n; i++)
            {
                int pos = ps[i] - 1;
                res += costs[pos / n, pos % n];
                left[pos / n, pos % n] = true;

                Queue<int> que = new Queue<int>();
                que.Enqueue(pos);
                while (que.Count > 0)
                {
                    int now = que.Dequeue();

                    int nextCost = costs[now / n, now % n];
                    if (!left[now / n, now % n])
                    {
                        nextCost++;
                    }
                    for (int j = 0; j < 4; j++)
                    {
                        int nextY = now / n + dy[j];
                        int nextX = now % n + dx[j];
                        if (nextY < 0 || nextY >= n || nextX < 0 || nextX >= n
                            || costs[nextY, nextX] <= nextCost)
                        {
                            continue;
                        }

                        costs[nextY, nextX] = nextCost;
                        que.Enqueue(nextY * n + nextX);
                    }
                }
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 64044
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    graph[l-1].append((r-1, d))
    graph[r-1].append((l-1, -d))
seen = [False]*n
dist = [None]*n
for i in range(n):
    if seen[i]:
        continue
    q = deque([i])
    dist[i] = 0
    while q:
        node = q.popleft()
        if seen[node]:
            continue
        seen[node] = True
        for c_node, d in graph[node]:
            if dist[c_node] is None:
                dist[c_node] = dist[node] + d
            elif dist[c_node] != dist[node] + d:
                print('No')
                exit(0)
            if not seen[c_node]:
                q.append(c_node)
print('Yes')

Measured memory_bytes: 71208
#include<bits/stdc++.h>
using namespace std;
struct Edge{int to;int cost;Edge(int t,int c):to(t),cost(c){}};
typedef pair<int,int>P;
int main(){
  int N,M,r;cin>>N>>M>>r;
  vector<int>R(r);for(int i=0;i<r;i++){cin>>R[i];R[i]--;}
  vector<vector<Edge>>A(N);
  for(int i=0;i<M;i++){
    int a,b,c;cin>>a>>b>>c;
    A[a-1].push_back(Edge(b-1,c));
    A[b-1].push_back(Edge(a-1,c));
  }
  vector<vector<int>>D(N,vector<int>(N,INT_MAX));
  
  for(auto s:R){//開始点ごとにdijkstra法
    priority_queue<P,vector<P>,greater<P>>q;q.push(P(0,s));D[s][s]=0;
    while(q.size()){
      P f=q.top();q.pop();
      int v=f.second;
      if(f.first>D[s][v])continue;
      for(auto n:A[v]){
        if(D[s][n.to]>D[s][v]+n.cost){
          D[s][n.to]=D[s][v]+n.cost;
          q.push(P(D[s][n.to],n.to));
        }
      }
    }
  }
  
  int ans=INT_MAX;
  sort(R.begin(),R.end());
  do{
    int s=0;
    for(int i=1;i<r;i++)s+=D[R[i-1]][R[i]];
    ans=min(ans,s);
  }while(next_permutation(R.begin(),R.end()));
  cout<<ans;
  
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)

int main() {
  string s;
  cin >> s;
  int start = -1, end;
  rep(i, 0, s.length()) {
    if (s[i] == 'A' && start == -1) start = i;
    if (s[i] == 'Z') end = i;
  }
  cout << end - start + 1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long A,B,C,D,ans=0,LCM,tmp,r,a,b,x;
  cin >> C >> D >> A >> B;
  a=A;
  b=B;
  x=A*B;
  if(A<B){
    tmp=A;
    A=B;
    B=tmp;
  }
  r=A%B;
  while(r!=0){
    A=B;
    B=r;
    r=A%B;
  }
  LCM=x/B;
  ans=D-C+1;
  ans-=D/a;
  ans-=D/b;
  ans+=(C-1)/a;
  ans+=(C-1)/b;
  ans-=(C-1)/LCM;
  ans+=D/LCM;
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var items = E.Range(100, 6).ToArray();
        var xx = int.Parse(Console.ReadLine());

        var dp = new bool[xx + 1];
        dp[0] = true;
        for (int i = 0; i < dp.Length; ++i)
        {
            if (!dp[i])
            {
                continue;
            }
            for (int j = 0; j < items.Length; ++j)
            {
                var t = i + items[j];
                if (t >= dp.Length)
                {
                    break;
                }
                dp[i + items[j]] = dp[i];
            }
        }

        Console.WriteLine(dp[xx] ? 1 : 0);
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
uint64_t gcd(uint64_t a, uint64_t b);
uint64_t lcm(uint64_t a, uint64_t b);

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint32_t N, K, S;
  cin >> N >> K >> S;
  for (uint32_t i = 0; i < K; ++i) {
    cout << S << " ";
  }
  for (uint32_t i = K; i < N; ++i) {
    if (S == 1000000000)
      cout << 1 << " ";
    else
      cout << S + 1 << " ";
  }
  cout << endl;
  return 0;
}

uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

uint64_t lcm(uint64_t a, uint64_t b) { return a * b / gcd(a, b); }

Measured memory_bytes: 1280
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])


Measured memory_bytes: 21084
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, H) cin >> a[i];

    rep(i, W + 2) { cout << "#"; }
    cout << endl;
    rep(i, H) { cout << "#" << a[i] << "#" << endl; }
    rep(i, W + 2) { cout << "#"; }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n; cin >> n;
    int ans = 0,num = 0;
    for(int i=1;i<=n;i++){
        if(i%2==1){
            for(int j=1;j*j<=i;j++){
                if(i%j==0){
                    num++;
                    if(j*j!=i) num++;
                }
            }
            if(num==8) ans++;
            num = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import copy
N = int(input())
X  = list(map(int,input().split()))
X2 = copy.copy(X)
X2.sort()
#print(X2)
mp =  X2[- (N ) // 2]
mp2 =  X2[- (N + 2) // 2]
for Xi in X:
    if Xi >= mp:
        print(mp2)
    else:
        print(mp)

Measured memory_bytes: 26068
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, As = 0, Bs = 0, csn, turn = -1, max;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  for (int i = 0; i < N; i++) {
    max = 0;
    turn *= -1;
    csn = 0;
    if (turn == 1) {
      for (int j = 0; j < N; j++) {
        if (max < a.at(j)) {
          max = a.at(j);
          csn = j;
        }
      }
      As += max;
      a.at(csn) = 0;
    }
    else {
      for (int j = 0; j < N; j++) {
        if (max < a.at(j)) {
          max = a.at(j);
          csn = j;
        }
      }
      Bs += max;
      a.at(csn) = 0;
    }
  }
  cout << As - Bs << endl;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7

n = int(input())

if n == 1:
    print(1)
    exit()

dp = [0] * (n)
dp[0] = 1
dp[1] = 1
dpsum = 2
for l in range(2, n):
    dp[l] = dpsum
    dp[l] -= dp[l-2]
    dp[l] %= MOD
    dpsum += dp[l]
    dpsum %= MOD

ans = 1 + (dpsum - dp[-1]) * (n-1) # end with "1..."
ans %= MOD
for l in range(n-1):
    ans += dp[l] * (n - 1) ** 2
    ans %= MOD

ans += dp[n-1] * (n - 1)
ans %= MOD

print(ans)

Measured memory_bytes: 81496
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> n;
  u64 odd = 0;
  for (u64 i = 0; i < n; ++i) {
    u64 a;
    cin >> a;
    if (a%2==1) odd++;
  }
  cout << (odd%2==0 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
double kitai(double x){
    return  (x+1)/2;
}
int main(){
    int N,K;    cin>>N>>K;
    vector<double> p(N,0);
    vector<double> dp(N+1,0);
    for(int i=0;i<N;i++){
        cin>>p[i];
        p[i]=kitai(p[i]);
    }
    for(int i=1;i<N+1;i++){
        dp[i]=dp[i-1]+p[i-1];
    }
    double maximum=0;
    for(int i=K;i<N+1;i++){
        maximum=max(maximum,dp[i]-dp[i-K]);
    }
    printf("%10lf",maximum);
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
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;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}


int F(int n) {
	int x = 0;
	while (n) {
		x += n % 10;
		n /= 10;
	}
	return x;
}


int main() {
	int n, k;
	cin >> n >> k;
	ll ans = k;
	rep(i, 0, n - 1) {
		ans *= (k - 1);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    int p, q, r;
    cin >> p >> q >> r;

    if (p >= q && p >= r){
        cout << q + r << endl;
    }
    else if (q >= p && q >= r){
        cout << p + r << endl;
    }
    else{
        cout << p + q << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  
  int i;
  vector<int> x(n);
  for(i = 0; i < n; i++){
    cin >> x.at(i);
  }
  
  int ans = 0;
  for(i = 0; i < n; i++){
    ans += 2 * min(x.at(i), abs(k - x.at(i)));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll l, r, ans=INF;
    cin >> l >> r;
    r = min(r, l+4038);
    for(ll i=l;i<=r;i++)for(ll j=i+1;j<=r;j++){
        ll tmp = ((i%2019)*(j%2019))%2019;
        ans = min(ans, tmp);
        ans %= 2019;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
# ABC140b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

manzoku = 0

manzoku += b[a[0] - 1]

#print('eat:' + str(a[0]))
# print(manzoku)
for i in range(1, n):
    #print('eat:' + str(a[i]))
    manzoku += b[a[i]-1]
    if a[i] - a[i - 1] == 1:
        # print('hi:'+str(c[a[i-1]-1]))
        manzoku += c[a[i-1]-1]
    # print(manzoku)

print(manzoku)


Measured memory_bytes: 3064
from itertools import combinations
import collections
N = int(input())
S = [input() for i in range(N)]
table = collections.defaultdict(int)

for x in S:
    table[x[0]] += 1

tmp = ["M", "A", "R", "C", "H"]


ans = 0
for x in combinations(tmp, 3):
    ans += table[x[0]]*table[x[1]]*table[x[2]]
print(ans)


Measured memory_bytes: 10112
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b;

    cin >> a >> b;

    if (a <= 0 && 0 <= b)
        cout << "Zero\n";
    else if (0 < a)
        cout << "Positive\n";
    else if ((b - a + 1) % 2 != 0)
        cout << "Negative\n";
    else
        cout << "Positive\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr lint MOD = 1000000007;
lint dp[101][8];

lint patt[8];

int main()
{
    memset(dp, 0, sizeof(dp));

    patt[0] = patt[1] = 1;
    FOR(i, 2, 8) patt[i] = patt[i - 1] + patt[i - 2];

    int H, W, K;
    cin >> H >> W >> K;

    dp[0][0] = 1;

    REP(h, H) REP(w, W)
    {
        dp[h + 1][w] = dp[h][w] * patt[w] * patt[W - 1 - w] % MOD;
        if (w > 0) (dp[h + 1][w] += dp[h][w - 1] * patt[w - 1] * patt[W - 1 - w]) %= MOD;
        if (w < W - 1) (dp[h + 1][w] += dp[h][w + 1] * patt[w] * patt[W - 1 - w - 1]) %= MOD;
    }
    cout << dp[H][K - 1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long long int k, a, b;
	cin >> k >> a >> b;
	if(a + 2 >= b){
		cout << (k + 1) << endl;
		return 0;
	}
	cout << (a - 1) + ((k - a + 1) / 2) * (b - a) + k - (a - 1) - ((k - a + 1) / 2 * 2) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

typedef long int lint;
typedef long long int llint;

#define INF 1073741824
#define LINF 4611686018000000000
#define MOD 1000000007

int main() {
    int a;
    cin >> a;
    string ans = a >= 30 ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

int dx[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };

int N, W;
ll v[101], w[101];

ll dp[101][100001];


//i番目までの品物でj以下の重さの価値の最大値


int main() {
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if (i == 0) dp[0][j] = 0;
			else {
				if (w[i - 1] > j) {
					dp[i][j] = dp[i - 1][j];
				}
				else {
					dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
				}
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}



Measured memory_bytes: 79104
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

signed main() {
  int n, k, q;
  cin >> n >> k >> q;

  vector<int> cnt(n);
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    cnt[t - 1]++;
  }

  for (int i = 0; i < n; i++) {
    if (k - q + cnt[i] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    map<ll, ll> m;
    rep(i, 0, N)
    {
        ll A;
        cin >> A;
        ++m[A];
    }

    vector<pair<ll, ll>> A;
    for (const auto& p : m)
    {
        A.push_back(p);
    }

    vector<ll> twos;
    ll two = 1;
    while (two <= 2000000000LL)
    {
        twos.push_back(two);
        two *= 2;
    }

    ll ans = 0;
    int i = A.size() - 1;
    while (i >= 0)
    {
        ll prevAns = ans;

        const ll a = A[i].first;
        const ll num = A[i].second;

        if (num <= 0)
        {
            --i;
            continue;
        }

        for (const ll two : twos)
        {
            const ll b = two - a;
            if (b <= 0) continue;

            ll ng = -1;
            ll ok = A.size();
            while (abs(ng - ok) > 1)
            {
                const ll mid = (ng + ok) / 2;
                if (A[mid].first >= b) ok = mid;
                else ng = mid;
            }

            if (ok == A.size()) continue;
            if (A[ok].first != b) continue;
            if (a != b && A[ok].second <= 0) continue;
            if (a == b && A[ok].second <= 1) continue;

            --A[i].second;
            --A[ok].second;
            ++ans;
            // cout << a << " + " << b << " = " << two << endl;
            break;
        }

        if (prevAns == ans)
        {
            --i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 18800