akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, Q, t[1000000], w[1000000], x; string s; vector<int> leader, ls;
inline int query(int x1, int x2) {
	return lower_bound(w, w + N, x2) - lower_bound(w, w + N, x1);
}
inline int check(int v) {
	int ret = 0;
	for (int i = 1; i < ls.size(); i++) ret += query(max(ls[i - 1] + 1, ls[i] - v), ls[i] + 1);
	return ret + (ls.size() ? query(ls[0] - v, ls[0] + 1) : 0);
}
int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 0; i < N; i++) scanf("%d", &t[i]), w[i] = t[i];
	sort(w, w + N);
	for (int i = 0; i < Q; i++) {
		cin >> s >> x;
		if (s == "ADD") leader.push_back(x - 1);
		if (s == "REMOVE") {
			for (int j = 0; j < leader.size(); j++) {
				if (leader[j] == x - 1) leader.erase(leader.begin() + j);
			}
		}
		if (s == "CHECK") {
			int l = -1, r = 1000000001; ls.clear();
			for (int j = 0; j < leader.size(); j++) ls.push_back(t[leader[j]]);
			sort(ls.begin(), ls.end());
			while (r - l > 1) {
				int m = (r + l) / 2, u = check(m);
				if (u >= N - x) r = m;
				else l = m;
			}
			if (r == 1000000001) printf("NA\n");
			else printf("%d\n", r);
		}
	}
	return 0;
}

Measured memory_bytes: 11100
#include<bits/stdc++.h>
#define ll  long long  
#define pb push_back
#define fi first
#define se second
using namespace std;
//vector<ll> v[1000001];
void dfs(ll u,ll p)
{
	
}
bool comp(const pair<ll,ll>&a,const pair<ll,ll> &b)
{
	return (a.second < b.second);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll x=ceil(c*1.0/b);
	ll y=ceil(a*1.0/d);
	if(x<=y)
	cout<<"Yes";
	else
	cout<<"No";
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<functional>
using namespace std;

using ll = long long int;
const int N_MAX = 100005;
ll S[N_MAX];
vector<int> A, B;

int main(){
    ll n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        A.push_back(a);
        B.push_back(a);
    }
    sort(A.begin(), A.end(), greater<int>());
    sort(B.begin(), B.end());

    ll lb = 0;
    ll ub = 200005;
    while(ub - lb > 1){
        ll mid = (lb + ub)/2;
        ll count = 0;
        int j = 0;
        for(int i = 0; i < n; i++){
            while(j < n && B[i] + A[j] >= mid)j++;
            count += j;
        }
        if (count >= m)lb = mid;
        else ub = mid;
    }
    ll ans = 0;
    ll count = 0;
    S[0] = 0;
    for(int i = 1; i <= n; i++){
        S[i] = S[i-1] + A[i-1];
    }
    int j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && B[i] + A[j] > lb) j++;
        count += j;
        ans += (ll)B[i] * j + S[j];
    }
    ans += lb * (m - count);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
template<typename T>inline bool chkmin(T &x,const T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,const T y){return (y>x)?(x=y,1):0;}
const int maxn=2e5+10;
int p[20],pre[maxn],a[maxn];
int main(){
	int n=read(),tmp=0;
	ll ans=0;
	REP(i,1,n){
		a[i]=read();
		REP(j,0,19) if(a[i]&(1<<j)){
			chkmax(pre[i],p[j]);
			p[j]=i;
		}
		chkmax(tmp,pre[i]);
		ans+=(i-tmp);
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, ma, mb;
  cin >> n >> ma >> mb;
  int d[n][3];
  for (int i = 0; i < n; ++i) {
    cin >> d[i][0] >> d[i][1] >> d[i][2];
  }
  int value[401][401];
  for (int i = 0; i < 401; ++i) {
    for (int j = 0; j < 401; ++j) {
      value[i][j] = 5000;
    }
  }
  value[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i*10; j >= 0; --j) {
      for (int k = i*10; k >= 0; --k) {
        if (value[j][k] == 5000) {
          continue;
        }
        value[j+d[i][0]][k+d[i][1]] = min(value[j][k] + d[i][2], value[j+d[i][0]][k+d[i][1]]);
      }
    }
  }
  int pow = 1;
  int best = 5000;
  while (pow*ma <= 400 && pow*mb <= 400) {
    best = min(value[pow*ma][pow*mb], best);
    pow++;
  }
  if (best == 5000) {
    cout << -1 << endl;
  } else {
    cout << best << endl;
  }
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    int sum=0;
    while(sum<N){
        sum+=1000;
    }
    cout << sum -N << endl;
    return 0;
    
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
const ll MOD=998244353;
const double pi=3.1415926;
ll n,c[MAXN];
vector<pair<ll,ll> >G[MAXN];
void dfs(ll u,ll pre)
{
    for(ll i=0;i<G[u].size();i++)
    {
        ll v=G[u][i].first;
        ll w=G[u][i].second;
        if(v==pre)
        {
            continue;
        }
        if(w&1)
        {
            c[v]=c[u]^1;
        }
        else
        {
            c[v]=c[u];
        }
        dfs(v,u);
    }
}
void solve()
{
    dfs(1,0);
    for(ll i=1;i<=n;i++)
    {
        printf("%lld\n",c[i]);
    }
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);

    while(~scanf("%lld",&n))
    {
        for(ll i=1;i<n;i++)
        {
            ll u,v,w;
            scanf("%lld %lld %lld",&u,&v,&w);
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
        solve();
    }
}
/*
100
3
1 1
1
4
1 1 1
1 1
1
*/


Measured memory_bytes: 10240
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

int main(){

	string s;
	cin>>s;

	long long z[26]={};
	for(int i=0;i<s.size();i++) z[s[i]-'a']++;

	long long n=s.size();
	long long cnt=(1+n)*n/2;
	for(int c=0;c<26;c++) cnt-=(1+z[c])*z[c]/2;

	long long res=cnt+1;
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ls x<<1,l,mid
#define rs x<<1|1,mid+1,r
#define N 500005
#define M 2000005
using namespace std;
int n;
int head[N],ver[M],nxt[M],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int low[N],in[N],top,st[N],dfn[N],be[N],num,tim;
void trjan(int x)
{
    low[x]=dfn[x]=++tim;
    st[++top]=x;
    in[x]=1;
    for(int i=head[x];i;i=nxt[i])
    {
        if(!dfn[ver[i]])
        {
            trjan(ver[i]);
            low[x]=min(low[x],low[ver[i]]);
        }
        else if(in[ver[i]])low[x]=min(low[x],dfn[ver[i]]);
    }
    if(low[x]==dfn[x])
    {
        int y;num++;
        do
        {
            y=st[top--];
            in[y]=0;
            be[y]=num;
        }while(y!=x);
    }
    return ;
}
struct nd
{
    int x,id;
    friend bool operator < (const nd &aa,const nd &bb)
    {
        return aa.x<bb.x;
    }
}a[N];
int tt,mx;
int fan[N];
void build(int x,int l,int r)
{
    mx=max(mx,x);
    if(l==r)
    {
        add(x+tt,fan[a[l].id]);
        return ;
    }
    int mid=(l+r)>>1;
    add(x+tt,x*2+tt);
    add(x+tt,x*2+1+tt);
    build(ls);build(rs);
}
void add(int x,int l,int r,int ll,int rr,int ps)
{
    if(l>=ll&&r<=rr)
    {
        add(ps,x+tt);
        return ;
    }
    int mid=(l+r)>>1;
    if(ll<=mid)add(ls,ll,rr,ps);
    if(rr>mid)add(rs,ll,rr,ps);
}
bool pan(int x)
{
    memset(dfn,0,sizeof(dfn));
    memset(head,0,sizeof(head));
    tot=tim=num=0;
    build(1,1,tt);
    int l=1,r=1;
    for(int i=1;i<=tt;i++)
    {
        while(l<i&&a[i].x-a[l].x>=x)l++;
        while(r<=tt&&a[r+1].x-a[i].x<x)r++;
        //cout<<l<<' '<<r<<endl;
        if(l!=i)add(1,1,tt,l,i-1,a[i].id);
        if(r!=i)add(1,1,tt,i+1,r,a[i].id);
    }
    for(int i=1;i<=tt+mx;i++)if(!dfn[i])trjan(i);
    for(int i=1;i<=tt;i++)if(be[i]==be[fan[i]])return 0;
    return 1;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int t1,t2;cin>>t1>>t2;
        a[++tt].x=t1;a[tt].id=tt;
        a[++tt].x=t2;a[tt].id=tt;
        fan[tt-1]=tt;fan[tt]=tt-1;
    }
    sort(a+1,a+tt+1);
    int l=0,r=1000000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(pan(mid))l=mid+1;
        else r=mid-1;
    }
    //cout<<pan(0);
    printf("%d\n",r);
    return 0;
}


Measured memory_bytes: 26752
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[110];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans=0;
	for(int i=1;2*i<=n;++i)
		if(s[i]!=s[n+1-i])++ans;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}
lint f[105];
int main(){
lint A,B,C,D,E,F;
cin>>A>>B>>C>>D>>E>>F;
vector<tuple<lint,lint,lint,lint>> x;
//(double)100*(k*C+l*D)/(i*100*A+j*100*B+k*C+l*D)<=(double)E/(100+E)
rep(i,30){
    rep(j,15){
        rep(k,1500){
          rep(l,750){
              if((i*100*A+j*100*B+C*k+l*D)==0)continue;
              if(i*100*A+j*100*B+C*k+l*D<=F)x.push_back(make_tuple(i*100*A,j*100*B,k*C,l*D));
              else break;
          }  
        }
    }
}
double ans1=0,ans2=0,tmp=0;
rep(i,x.size()){
lint a,b,c,d;
tie(a,b,c,d)=x[i];
      double r=a+b+c+d;
      double t=(c+d);
      double k=t/r;
      if(k<=(double)E/(100+E)){
             if(k>tmp){
                 ans1=r;
                 ans2=t;
                 tmp=k;
             }
      }
        }
        if(tmp==0){
            cout<<100*A<<" "<<0;
        }else 
        cout<<ans1<<" "<<ans2;
}




Measured memory_bytes: 67296
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string a,b; cin>>a>>b;
    string ans;
    if(a.size()>b.size()){
        ans="GREATER";
    }
    else if(a.size()<b.size()){
        ans="LESS";
    }
    else{
        if(a>b) ans="GREATER";
        else if(a<b) ans="LESS";
        else ans="EQUAL";
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import math
import itertools

h, w, k = map(int, input().split(" "))
cL = [input() for _ in range(h)]

blackCount = 0
for c in cL:
    for item in c:
        if item == "#":
            blackCount += 1

ans = 0
for x in range(w + 1):
    for y in range(h + 1):
        for x2 in itertools.combinations(range(w), x):
            for y2 in itertools.combinations(range(h), y):
                yCnt = 0
                xCnt = 0
                for y4 in y2:
                    # 該当のそれぞれのコマ数
                    xCnt += cL[y4].count("#")
                for x4 in x2:
                    for y3 in range(h):
                        if cL[y3][x4] == "#":
                            yCnt += 1
                th = 0
                for xa in x2:
                    for ya in y2:
                        if cL[ya][xa] == "#":
                            th += 1
                _sum = blackCount - yCnt - xCnt + th
                if k == _sum:
                    ans += 1

print(ans)

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

int main()
{
	long long n, d, ans = 0;
	cin >> n >> d;

	for (int i=0; i<n; i++)
	{
		long long x, y;
		cin >> x >> y;
		if ( ( x*x+y*y ) <= d*d ) {
			ans++;
		}
	}
	
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
    #include <algorithm>
    #include <string>
    using namespace std;
    #define endl '\n'
     
     
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	
    	string s;
     
    	while (cin >> s)
    	{
    		if (s.find("7") != string::npos)
    			cout << "Yes" << endl;
    		else
    			cout << "No" << endl;
    	}
    	
    	return 0;
    }

Measured memory_bytes: 3636
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String ans = "No";
    for(int i = 0; i < s.length() - 1; i++) {
      if((s.charAt(i) == 'A') && (s.charAt(i + 1) == 'C')) ans = "Yes";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

int McxiTen (char *c) {
	
	//cout << "/*" << c << endl;
	int i = 0; //strlen(c);
	int n = 0;
	
	while(i < strlen(c)) {
		int tmp = 1;
		
		//cout << "." << c[i];
		if(isdigit(c[i])) {
			tmp = c[i] - '0';
			//cout << "->" << tmp << endl;
			i++;
		} else {
		}
		
		switch(c[i]) {
			case 'i' : n += tmp; break;
			case 'x' : n += tmp * 10; break;
			case 'c' : n += tmp * 100; break;
			case 'm' : n += tmp * 1000; break;
			default : break;
		}
		//cout << " " << n << endl;
		i++;
	}
	
	//cout << endl << n << endl << "*/" << endl;
	
	return n;
}

void TenMcxi (int n, char *c) {
	int ns[4];
	
	ns[0] = n / 1000;
	n = n % 1000;
	ns[1] = n / 100;
	n = n % 100;
	ns[2] = n / 10;
	n = n % 10;
	ns[3] = n;
	
	int j = 0;
	for(int i = 0; i < 4; i++) {
		if(ns[i] != 0) {
			if(ns[i] != 1) {
				c[j++] = (char)(ns[i] + '0');
				//cout << c << endl;
			}
			switch(i) {
				case 0 : c[j++] = 'm'; break;
				case 1 : c[j++] = 'c'; break;
				case 2 : c[j++] = 'x'; break;
				case 3 : c[j++] = 'i'; break;
			}
			
			//cout << c << endl;
		}
	}
	c[j] = '\0';
	
	return;
}


int main(void) {
	char a[1000], b[1000];
	int n;
	
	cin >> n;
	while(cin >> a >> b) {
		char c[9999];
		//cout << "s: " << a << ", " << b << endl;
		//cout << McxiTen(a) << ", " << McxiTen(b) << endl;
		
		int sum = McxiTen(a) + McxiTen(b);
		//cout << sum << endl;
		TenMcxi(sum, c);
		cout << c << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1168
//API???????????????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
 public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Card[] CardA = new Card[n];
		for(int i = 0; i < n; i++){
			CardA[i] = new Card();
			String[] str = br.readLine().split(" ");
			CardA[i].sort = str[0];
			CardA[i].num = Integer.parseInt(str[1]);
			CardA[i].index = i;
		}
		QuickSort(CardA, 0, n - 1);
		boolean stable = true;
		stable = isStable(CardA, n);
		
		if(stable) System.out.println("Stable");
		else System.out.println("Not stable");

		for(int i = 0; i < n; i++){
			System.out.println(CardA[i].sort + " " + CardA[i].num);
		}
	}

	public static void QuickSort(Card[] A, int l, int r){
		if(l >= r) return;
		int p = Partition(A, l, r);
		QuickSort(A, l, p - 1);
		QuickSort(A, p + 1, r);
	}

	public static int Partition(Card[] A, int l, int r){
		int threshold = A[r].num;
		int i = l - 1;
		for(int j = l; j < r; j++){
			if(A[j].num <= threshold){
				i++;
				exchange(A, i, j);
			}
		}
		i++;
		exchange(A, i, r);

		return i;
	}

	public static void exchange(Card[] A, int i, int j){
		Card tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	static boolean isStable(Card[] A, int n){
		boolean flag = true;
		int cnt;
		int[] Sort = new int[4]; 
		for(int i = 0; i < n; i+= cnt){
			Sort[0] = A[i].index;
			cnt = 1;
			for(;i + cnt < n && A[i].num == A[i + cnt].num; cnt++){
				Sort[cnt] = A[i + cnt].index;
			}
			if(cnt != 1){
				for(int j = 0; j < cnt - 1; j++){
					for(int k = j + 1; k < cnt; k++){
						if(Sort[j] > Sort[k]){
							flag = false;
							break;
						}
					}
					if(!flag) break;
				}
			}
			if(!flag) break;
		}
		return flag;
	}
}

class Card{
	int num;
	String sort;
	int index;
}

Measured memory_bytes: 79440
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-11
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007
const int N = 501031;

int next_entry[N][29];
int dp[N];
string st;
vector<char> ans;

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>st;
	for (int i=0;i<26;i++)
	{
		next_entry[st.size()][i]=st.size();
	}

	for (int i=st.size()-1;i>=0;--i)
	{
		for (int j=0;j<26;j++)
		{
			next_entry[i][j]=next_entry[i+1][j];
		}
		next_entry[i][st[i]-'a']=i;
	}

	for (int i=st.size()-1;i>=0;--i)
	{
		dp[i]=1e9;
		for (int j=0;j<26;j++)
		{
			int ps=next_entry[i][j];
			if (ps==st.size())
				dp[i]=0;
			else
			{
				dp[i]=min(dp[i],dp[ps+1]+1);
			}
		}
	}

	int ps=0;
	while (ps<st.size())
	{
		int next_move=-1;
		for (int i=0;i<26;i++)
		{
			int to=next_entry[ps][i];
			if (dp[to+1]!=dp[ps]-1&&to<st.size())
				continue;
			next_move=i;
			ps=to+1;
			break;
		}
		ans.push_back(char(next_move+'a'));
	}

	for (int i=0;i<ans.size();i++)
	{
		cout<<ans[i];
	}
	cout<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 25988
import math
N=int(input())
def num2alpha(num):
    if num<=26:
        return str.lower(chr(64+num))
    elif num%26==0:
        return str.lower(num2alpha(num//26-1)+chr(90))
    else:
        return str.lower(num2alpha(num//26)+chr(64+num%26))


print(num2alpha(N))


Measured memory_bytes: 61900
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int m = 0; m <= c; m++){
                if(x == i * 500 + j * 100 + m * 50) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
from math import factorial
N = int(input())
S = list(input())
MOD = 10 ** 9 + 7

S_fin = ''
for i, s in enumerate(S):
    if i % 2 == 1:
        S_fin += s
        continue

    if s == 'W':
        S_fin += 'B'
    else:
        S_fin += 'W'


ans = 1
W_cnt = 0
for s in S_fin:
    if s == 'W':
        W_cnt += 1
    else:
        ans *= W_cnt
        ans %= MOD

        W_cnt -= 1

if W_cnt > 0:
    print(0)
else:
    print(ans * factorial(N) % MOD)


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

int s;
int a[1000001];
vector<pair<int, int> > pd;
long long answer;

int main(){
  cin >> s;
  for(int i = 1; i < 1000001; ++i){
    if(i == 1){
      a[i] = s;
    }else if(a[i - 1] % 2 == 0){
      a[i] = a[i - 1] / 2;
    }else{
      a[i] = a[i - 1] * 3 + 1;
    }
    //gg[i] = 1000003;
    //pd.push_back(make_pair(a[i], i));
  }
  //sort(pd.begin(), pd.end());
  
  //a[1] = 0;
  //int cnt = 0;
  
  for(int i = 1; i < 1000001; ++i){
    for(int j = i + 1; j < 1000001; ++j){
      if(a[j] == a[i]){
        cout << j << endl;
        return 0;
      }
    }
    
  }
  
  
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,n) for(int i = a; i < n; i++)

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

struct edge{
  int to, d, c;
};

edge makeEdge(int to, int d, int c){
  edge e;
  e.to = to;
  e.d = d;
  e.c = c;
  return e;
}

int n,m;
int s,g;
typedef tuple<double, int, int,int> State;
const double INF = 1e15;


void dijkstra(vector<vector<edge> > &edges){
  double dist[n][n][31];
  rep(i,n)rep(j,n)rep(k,31) dist[i][j][k] = INF;
  rep(i,n) dist[s][i][0] = 0;
  priority_queue< State, vector<State>, greater<State>> que;
  for(edge e :edges[s]){
    if(1 <= e.c && dist[e.to][s][1] > (double)e.d ){
      dist[e.to][s][1] = (double)e.d;
      que.push(State((double)e.d, 1 ,e.to ,s));
    }
  }

  while(que.empty() == false){
    State s = que.top(); que.pop();
    double ctime  = get<0>(s);
    int cspeed    = get<1>(s);
    int current   = get<2>(s);
    int prev      = get<3>(s);

    if(dist[current][prev][cspeed] < ctime) continue;
    for(edge e :edges[current]){
      if(e.to == prev) continue;
      for(int v = -1; v <= 1; v++){
        if( cspeed + v > 0 &&
            cspeed + v <= e.c &&
            dist[e.to][current][cspeed + v] > (ctime + (double)e.d / (double)(cspeed + v) ) ) {

          dist[e.to][current][ cspeed + v ] = ctime + (double)e.d/(double)(cspeed + v);
          que.push(State(
                    ctime + (double)( e.d / (double)(cspeed + v) ),
                    cspeed + v ,
                    e.to ,
                    current));
        }
      }
    }

  }
  double ans = INF;
  rep(i,n) ans = min(ans,dist[g][i][1]);
  if(ans == INF) cout << "unreachable" << endl;
  else printf("%0.10lf\n",ans);
}

int main(){
  while(true){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    cin >> s >> g;
    s--,g--;
    vector<vector<edge>> edges(n);

    rep(i,m){
      int x,y,d,c;
      cin >> x >> y >> d >> c;
      x--,y--;
      edges[x].push_back(makeEdge(y,d,c));
      edges[y].push_back(makeEdge(x,d,c));
    }
    dijkstra(edges);
  }

}



Measured memory_bytes: 3876
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

signed main() {
	int n;
	scanf("%d", &n);
	vector<ll> s(n),ssum(n+1);
	REP(i,n){
		scnaf("%lld", &s[i]);
	}
	sort(ALL(s));
	
	int ans = 0;
	REP(i,n){
		ssum[i] += s[i];
		ssum[i+1] += ssum[i];
	}
	REP(i,n){
		ll cs = s[i];
		REP(j,32){
			int pos = --upper_bound(ALL(s), cs*2) - s.begin();
			cs = ssum[pos];
			if(pos == n-1){
				ans++;
				break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1792
def gcd(a,b):
    while b % a:
        a,b = b, a % b
    return a
#(a >= b )

N ,X = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
abs_xlist = list(map(lambda x:abs(X - x), xlist))
abs_xlist.sort()
ans = abs_xlist[0]

for i in range(N):
    if abs_xlist[i] % ans != 0:
        num = gcd(abs_xlist[i],ans)
        ans = min(num,ans)
print(ans)


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    OP(n * (n + 1) / 2);
    return 0;
}

Measured memory_bytes: 256
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))

n,k = mp()
okasi = [0]*n
for i in range(k):
    d = int(input())
    a = lmp()
    for j in a:
        okasi[j-1] += 1
print(okasi.count(0))




Measured memory_bytes: 67544
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
string S,T;
vector<string> ans;

int main(){
  cin>>S>>T;
  for(int start=0;start<S.size()-T.size()+1;start++){
    int check=1;
    string tmp=S;
    for(int i=0;i<T.size();i++){
      if(S[start+i]!='?'&&S[start+i]!=T[i]){
        check=0;
        break;
      }
      tmp[start+i]=T[i];
    }
    if(check){
      for(int i=0;i<tmp.size();i++){
        if(tmp[i]=='?') tmp[i]='a';
      }
      ans.push_back(tmp);
    }
  }
  if(ans.empty()){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  sort(ans.begin(),ans.end());
  cout<<ans[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
//Bellman_Ford法
//ABC061D

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long


struct edge {
  int to;
  LINT cost;  // 辺の接続先頂点, 辺の重み
  edge(int to, LINT cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
                // graph[v][i]は頂点vから出るi番目の辺edge

const LINT INF = 1000000000000000;

vector<LINT> dist; // 最短距離

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
  dist = vector<LINT>(n, INF);
  dist[s] = 0; // 開始点の距離は0
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        edge e = graph[v][k];
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }
  return false;
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;

  graph = AdjList(n);

  for (int i = 0; i < m; i++) {
    int from, to;
    LINT cost;
    cin >> from >> to >> cost;
    graph[from].push_back(edge(to, cost));
  }

  bool closedloop = bellman_ford(n, r);
  if(closedloop) cout << "NEGATIVE CYCLE" << endl;
  else
  REP(i, n) {
    if(dist[i] == INF) cout << "INF" << endl;
    else cout << dist[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int x,y,a,b,c;
	cin >> x>>y>>a>>b>>c;
	vector<int>p(a);
	vector<int>q(b);
	vector<int>r(c);
	rep(i,a)cin >> p[i];
	rep(i,b)cin >> q[i];
	rep(i,c)cin >> r[i];

	sort(p.begin(), p.end(),greater<int>());
	sort(q.begin(), q.end(),greater<int>());

	rep(i,x)r.push_back(p[i]);
	rep(i,y)r.push_back(q[i]);

	sort(r.begin(),r.end(),greater<int>());
	ll sum =0;
	rep(i,x+y) sum+= r[i];

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 2552
n=int(input())
ans="".join(sorted(input()))
for i in range(n-1):
  s=sorted(input())
  si=0
  ansi=0
  newans=""
  while si<len(s) and ansi<len(ans):
    if ans[ansi]==s[si]:
      newans+=ans[ansi]
      ansi+=1
      si+=1
    elif ans[ansi]>s[si]:
      si+=1
    else:
      ansi+=1
  ans=newans
print(ans)

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var INF = (long)1e9 + 7;
            long power = 1;

            for(long i = 2; i <= n; i++)
            {
                power = power * i % INF;
            }
            Console.WriteLine(power);
        }
    }
}


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

typedef long long LL;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VVVI> VVVVI;

typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

typedef vector<double> VD;
typedef vector<VD> VDD;

typedef vector<string> VS;
typedef vector<VS> VVS;

typedef vector<bool> VB;
typedef vector<VB> VVB;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define RANGE(x, y, maxX, maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && y < (maxY))
#define REP(i, init, N) for (int i = (init); i < (int)(N); i++)

const int INF = 0x3f3f3f3f;
const int DX[] = {-1,0,1,-1,0,1,-1,0,1};
const int DY[] = {1,1,1,0,0,0,-1,-1,-1};

string qs;

bool ok(int l, int r) {
    int lx = DX[l];
    int rx = DX[r];
    return lx <= rx;
}

PII move(int l, int r, bool is_l, int q) {
    int nl = is_l ? (q - 1) : l;
    int nr = is_l ? r : (q - 1);
    return MP(nl, nr);
}

int solve() {
    int N = qs.size();

    // dp[step][l][r][before_is_l] = min_invalid_step
    VVVVI dp(2, VVVI(9, VVI(9, VI(2, INF))));
    dp[0][0][8][0] = 0;
    dp[0][0][8][1] = 0;

    REP(n, 0, N) {
        dp[(n + 1) % 2] = VVVI(9, VVI(9, VI(2, INF)));
        REP(l, 0, 9) REP(r, 0, 9) REP(b_is_l, 0, 2) {
            if (dp[n % 2][l][r][b_is_l] == INF) continue;
            int cnt = dp[n % 2][l][r][b_is_l];
            int q = qs[n] - '0';

            REP(is_l, 0, 2) {
                PII nt = move(l, r, is_l, q);
                if (!ok(nt.fst, nt.snd)) continue;

                dp[(n + 1) % 2][nt.fst][nt.snd][is_l] = min(
                        dp[(n + 1) % 2][nt.fst][nt.snd][is_l],
                        cnt + (b_is_l == is_l));
            }
        }
    }

    int ans = INF;
    REP(l, 0, 9) REP(r, 0, 9) REP(is_l, 0, 2) {
        ans = min(ans, dp[N % 2][l][r][is_l]);
    }

    return ans;
}

int main(void) {
    while (cin >> qs, qs != "#") {
        cout << solve() << endl;
    }

    return 0;
}

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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"

vector<array<int,4>> quad;
int ans= 0;
vector<int> s;
int n,m,q;
void search(int index,int b){
    if(index==n){
        int score=0;
        for(int i=0;i<q;i++){
            if(s[quad[i][1]-1]-s[quad[i][0]-1]==quad[i][2]){
                score+= quad[i][3];
            }
        }
        ans = max(ans,score);
        return ;
    }
    s[index]=m-b+1;
    for(int i=0;i<=b;i++){
        search(index+1,b-i);
    }
}
void solve(){
    cin>>n>>m>>q;
    int a,b,c,d;
    s.resize(n);
    for(int i=0;i<q;i++){
        cin>>a>>b>>c>>d;
        quad.push_back({a,b,c,d});
    }
    search(0,m-1);
    cout<<ans<<"\n";
}
int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
        solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

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

int main(int argc, char *argv[])
{
    int n;
    cin >> n;

    vector<vector<int>> A(n, vector<int>(n));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j) 
            cin >> A[i][j];


    long long result = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = i + 1; j < n; ++j)
        {
            bool important = true;
            for(int k = 0; k < n; ++k)
            {
                if(k == i || k == j) continue;

                if(A[i][k] + A[k][j] == A[i][j]) 
                {
                    important = false;
                    break;
                }
                else if(A[i][k] + A[k][j] < A[i][j])
                {
                    cout << -1 << endl;
                    return 0;
                }
            }

            if(important) result += A[i][j];
        }
    }

    cout << result << endl;
}


Measured memory_bytes: 768
import java.util.*;
import java.math.BigDecimal;

class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		double x1 = stdIn.nextDouble();
		double y1 = stdIn.nextDouble();
		double x2 = stdIn.nextDouble();
		double y2 = stdIn.nextDouble();
		int q = stdIn.nextInt();
		for(int i=0;i<q;i++){
			double xp = stdIn.nextDouble();
			double yp = stdIn.nextDouble();
			Vector vec1 = new Vector(x1,y1,x2,y2);
			Vector vec2 = new Vector(x1,y1,xp,yp);
			Vector vec3 = vec1.reflection(vec2);
			System.out.println((2*vec3.x+xp)+" "+(2*vec3.y+yp));
		}

	}	
}

class Vector{
	public final double EPS = Math.pow(10,-8);
	public double x,y;
	final int cutoff = 9;

	Vector( double x1 , double y1 , double x2 , double y2 ){
		this.x = x2 - x1;
		this.y = y2 - y1;
	}

	double dot( Vector a ){	
		return rounding(this.x * a.x + this.y * a.y);
	}
	double cross( Vector a ){	
		return rounding(this.x * a.y - this.y * a.x);
	}

	void add( Vector a ){
		this.x = rounding(this.x + a.x);
		this.y = rounding(this.y + a.y);
	}
	void sub( Vector a ){
		this.x = rounding(this.x - a.x);
		this.y = rounding(this.y - a.y);
	}
	void mul( double z ){
		this.x = rounding(this.x * z);
		this.y = rounding(this.y * z);
	}
	void div( double z ){
		this.x = rounding(this.x / z);
		this.y = rounding(this.y / z);
	}

	double abs(){
		return Math.sqrt(norm());
	}
	double norm(){
		return rounding(this.x * this.x + this.y * this.y);
	}

	void projection( Vector a ){
		if(judge(a.norm())){
			this.x = 0;
			this.y = 0;
		}
		else{
			double cos = dot(a)/(abs() * a.abs());
			double frac = a.abs() * cos/abs();
			mul(frac);
		}
	}
	Vector reflection( Vector a ){
		projection(a);
		return new Vector(a.x,a.y,this.x,this.y);
	}

	boolean judgeisOrthogonal( Vector a ){	
		return judge(dot(a)) ? true : false;
	}  
	boolean judgeisParallel( Vector a ){	
		return judge(cross(a)) ? true : false;
	}

	boolean judge( double a ){		
		return Math.abs(a)<EPS ? true : false;
	}
	double rounding(double a){
		BigDecimal bi = new BigDecimal(String.valueOf(a));
		return bi.setScale(cutoff,BigDecimal.ROUND_HALF_UP).doubleValue();
	}
} 

Measured memory_bytes: 44780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public string S;

        public void Run()
        {
            {
                N = Input.ReadInt();
                S = Console.ReadLine();
            }

            var E = new int[N];
            var W = new int[N];
            for (int i = 0; i < N; i++)
            {
                int e = S[i] == 'E' ? 1 : 0;
                int w = S[i] == 'W' ? 1 : 0;
                E[i] = i == 0 ? e : E[i - 1] + e;
                W[i] = i == 0 ? w : W[i - 1] + w;
            }

            int ret = int.MaxValue;

            for (int i = 0; i < N; i++)
            {
                int left = i == 0 ? 0 : W[i - 1]; 
                int right = E[N - 1] - E[i];
                int r = left + right;
                ret = Math.Min(ret, r);
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main()
{
int x,y;
cin >> x >> y;
int a=x/y;
int b=x%y;
double c=(double)x/y;
cout << a << " " << b << " ";
cout << fixed << setprecision(5) << c << endl;
}


Measured memory_bytes: 3280
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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 SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class C {
	int count[26];
	int n;
public:
	C()
	{
		memset(count, 0, sizeof count);
		cin >> n;
		string name;
		REP(i, n)
		{
			cin >> name;
			++count[name[0] - 'A'];
		}

	}
	void solve()
	{
		ll ans{ 0 };
		
		const int idx[5]{ 'M' - 'A', 'A' - 'A' ,'R' - 'A' ,'C' - 'A' ,'H' - 'A' };

		for (int i{ 0 }; i < 3; i++)
			for (int j{ i + 1 }; j < 4; j++)
				for (int k{ j + 1 }; k < 5; k++)
					ans += (ll)count[idx[i]] * count[idx[j]] * count[idx[k]];

		cout << ans << endl;
		

	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

int main() {
  ll n,h,w;
  cin >> n >> h >> w;
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ll x,y;
    cin >> x >> y;
    if(x>=h&&y>=w) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define REP(i, x, y) for (int i = x;i < y; i++)

const int8_t  INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF  = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  int a;
  cin>>a;
  cout<<"Christmas";
  for(int i=25;i!=a;i--)cout<<" Eve";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
#define all(x) (x).begin(), (x).end()
#define pi 3.1415926536

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;

    TreeNode(int x): val(x), left(NULL), right(NULL){}
};

struct ListNode {
    int val;
    ListNode* next;

    ListNode(int x): val(x), next(NULL){}
};

int nxt(){
    int x;
    cin>>x;
    return x;
}

ll nxtLong(){
    ll x;
    cin>>x;
    return x;
}

string nxtStr(){
    string x;
    cin>>x;
    return x;
}

char nxtChar(){
    char x;
    cin>>x;
    return x;
}

double nxtDouble(){
    double x;
    cin>>x;
    return x;
}

ld nxtLDouble(){
    ld x;
    cin>>x;
    return x;
}

TreeNode* makeTree(int n){
    queue<TreeNode*> tree_nodes;
    TreeNode* root;
    if(n){
        root = new TreeNode(nxt());
        tree_nodes.push(root);
    }else{
        return NULL;
    }
    while(!tree_nodes.empty()){
        TreeNode* node = tree_nodes.front();
        tree_nodes.pop();
        bool left;
        cin>>left;
        if(left){
            node->left = new TreeNode(nxt());
            tree_nodes.push(node->left);
        }
        bool right;
        cin>>right;
        if(right){
            node->right = new TreeNode(nxt());
            tree_nodes.push(node->right);
        }
    }
    return root;
}

ListNode* makeLinkedList(int n){
    ListNode* list = new ListNode(0);
    ListNode* dummy = list;

    for(int i=0;i<n;++i){
        list->next = new ListNode(nxt());
        list = list->next;
    }

    return dummy->next;
}

void solve(){
    ll n = nxt();

    ll sum = 0;

    for(ll i=1;i<=n;++i){
        ll y = n/i;
        sum += (y*(y+1)*i)/2;
    }
    cout<<sum<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<fixed<<setprecision(9);
    //ll t;
    //cin>>t;
    //while(t--){
    //    solve();
    //}
    solve();
    return 0;
}


Measured memory_bytes: 3652
// https://atcoder.jp/contests/abc144/tasks/abc144_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << "-1\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll K;
    cin >> K;
    ll now = 0;
    loop(i, 10000000)
    {
        now *= 10;
        now += 7;
        now %= K;
        if (now % K == 0)
        {
            putout(i + 1);
            return 0;
        }
        if (i >= 2 * K)
        {
            putout(-1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3504
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll cnt[225816];

int main(void){
	int n,i,a;
	ll ans = 0ll;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a;
		if(i-a>=0){
			ans += cnt[i-a];
		}
		if(i+a<n){
			++cnt[i+a];
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 5156
import bisect

def binum(num):
	number_len = len(bin(num))-2
	f = 2**number_len -1
	return (num^f)+1

N = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = 0

while len(A) > 0:
	k = A.pop()
	if len(A) == 0:
		break
	if int(k) != k:
		continue
	x = binum(k)
	if x > A[-1]:
		continue
	if A[bisect.bisect_left(A,x)] == x:
		A[bisect.bisect_left(A,x)] -= 0.5
		cnt += 1

print(cnt)


Measured memory_bytes: 25708