akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <queue>
#include <vector>

using namespace std;

int main() {
    int inf = 1000000001;

    int N, M, L;
    cin >> N >> M >> L;

    vector <vector <int > > distance(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            distance[i].push_back(i == j ? 0 : inf);
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c <= L) {
            distance[a - 1][b - 1] = c;
            distance[b - 1][a - 1] = c;
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                distance[i][j] = min(distance[i][j],
                                     distance[i][k] + distance[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) {
                distance[i][j] = 0;
            } else if (distance[i][j] <= L) {
                distance[i][j] = 1;
            } else {
                distance[i][j] = inf;
            }
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                distance[i][j] = min(distance[i][j],
                                     distance[i][k] + distance[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        int a = distance[s - 1][t - 1];
        cout << (a < inf ? a - 1 : -1) << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int a, b;
  CIN(a >> b);
  if (10 <= a || 10 <= b) {
    COUT(-1);
  } else {
    COUT(a * b);
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  
  int i,j,k,l,v,N;
  int A[100];

  scanf("%d",&N);
  
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1)printf(" ");  
  }
  
  
  printf("\n");
  
  for(i=1;i<N;i++){
    v = A[i];
    j = i-1;
    
    while(j >=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }   
    for(k=0;k<N;k++){
      printf("%d",A[k]);
    if(k != N-1) printf(" ");   
    }  
    
    
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int N,i,j,ans=0;
cin>>N;
vector<int> a(N);
for(i=0;i<N;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
i=0;
while(i<N){
j=i;
while(a[i]==a[j]){
i++;
if(i==N-1){i++;break;}
}
if((i-j)>=a[j])ans+=(i-j-a[j]);
else if((i-j)<a[j])ans+=(i-j);
}
cout<<ans<<endl;
return 0;



}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int q, n, m, p[1200], prev[610][610], dp[610][610];
int root(int x){
	if(p[x] == x) return x;
	return p[x] = root(p[x]);
}
void merge(int a, int b){
	a = root(a); b = root(b);
	if(a != b) p[b] = a;
}

int main(){
	while(cin >> q >> n >> m, q + n + m){
		rep(i, 2 * (n + m)) p[i] = i;
		rep(i, q){
			string c;
			int a, b;
			cin >> a >> b >> c;
			a--; b--;
			if(c == "yes") rep(j, 2) merge(2 * a + j, 2 * b + j);
			else rep(j, 2) merge(2 * a + j, 2 * b + 1 - j);
		}
		map<int, vi> s;
		vector<vi> ys, ns;
		vector<pi> v;
		vi ans; int p;
		bool use[1200] = {};
		
		rep(i, 2 * (n + m)) s[root(i)].pb(i);
		rep(i, 2 * (n + m)){
			int t = 0, l = 0, r = root(i);
			if(use[r / 2]) continue;
			use[r / 2] = 1;
			vi a, b;
			each(j, s[r]){
				if(*j % 2) l++, b.pb(*j / 2);
				else t++, a.pb(*j / 2);
			}
			v.pb(mp(t, l));
			ys.pb(a); ns.pb(b);
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		rep(i, v.size()) for(int j = n + m; j >= 0; j--) if(dp[i][j]){
			dp[i][j] = min(dp[i][j], 100);
			if(j + v[i].first <= n + m) dp[i + 1][j + v[i].first] += dp[i][j], prev[i + 1][j + v[i].first] = 0;
			if(j + v[i].second<= n + m) dp[i + 1][j + v[i].second]+= dp[i][j], prev[i + 1][j + v[i].second]= 1;
		}
		p = v.size() - 1;
		if(dp[p + 1][n] != 1){
			cout << "no" << endl;
			goto END;
		}
		while(p >= 0){
			if(prev[p + 1][n]) rep(j, ns[p].size()) ans.pb(ns[p][j]);
			else rep(j, ys[p].size()) ans.pb(ys[p][j]);
			n -= prev[p + 1][n] ? ns[p].size() : ys[p].size();
			p--;
		}
		sort(all(ans));
		rep(i, ans.size()) cout << ans[i] + 1 << endl;
		cout << "end" << endl;
		END:;
	}
	return 0;
}

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

using namespace std;

int main(){
    int H,W,K;
    cin >> H >> W >> K;

    vector<vector<char>> field(H, vector<char>(W));
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++)cin >> field.at(h).at(w);
    }

    int res = 0;
    for(int bit=0; bit<(1<<(H+W)); bit++){
        vector<vector<char>> tmpField(H, vector<char>(W));
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++)tmpField.at(h).at(w) = field.at(h).at(w);
        }

        for(int h=0; h<H; h++){
            if((1<<h) & bit){
                for(int w=0; w<W; w++)tmpField.at(h).at(w) = '.';
            }
        }

        for(int w=0; w<W; w++){
            if((1<<(w+H)) & bit){
                for(int h=0; h<H; h++)tmpField.at(h).at(w) = '.';
            }
        }

        // show field
        // for(int h=0; h<H; h++){
        //     for(int w=0; w<W; w++)cout << tmpField.at(h).at(w);
        //     cout << endl;
        // }

        int count = 0;
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                if(tmpField.at(h).at(w) == '#')count++;
            }
        }
        if(count == K)res++;
    }

    cout << res << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  if(t.find(s)==0&&(s.length()+1)==t.length()){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3596
def dense(w, s):
	if s + w == 0:
		return 0
	return s / (w + s) * 100

def resolve():
	A, B, C, D, E, F = map(int, input().split())
	waters = set()
	sugars = set()

	for i in range(31):
		for j in range(31):
			v = A*i*100 + B*j*100
			if v > F:
				continue
			waters.add(v)
	for i in range(101):
		for j in range(101):
			v = i*C + j*D
			if v > F:
				continue
			sugars.add(v)
	ans_w, ans_s = 0, 0
	for w in waters:
		for s in sugars:
			if w + s > F or s > w//100*E or s + w == 0:
				continue
			if dense(w, s) >= dense(ans_w, ans_s):
				ans_w, ans_s = w, s
	print(ans_w + ans_s, ans_s)
resolve()

Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m, a, b;
  in2(n, m);
  vector<ll> c(m);
  rep(i, n){
    in(a);
    rep(j, a){
      in(b);
        c[b - 1]++;
    }
  }
  a = 0;
  rep(i, m){
    if(c[i] == n)
      a++;
  }
  out(a);
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  int L=A+B;
  int R=C+D;
  
  if(L>R){
    cout<<"Left"<<endl;
  }else if(L<R){
    cout<<"Right"<<endl;
  }else if(L==R){
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		ArrayList<Integer>[] edges = new ArrayList[N + 1];
		for (int i = 1; i < N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			put(edges, a, b);
			put(edges, b, a);
		}
		int[] counter = new int[N + 1];
		for (int i = 0; i < Q; i++) {
			int p = sc.nextInt();
			int x = sc.nextInt();
			counter[p] += x;
		}
		dfs(counter, edges, 1, 0, 0);
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= N; i++) {
			if (i > 1) {
				sb.append(" ");
			}
			sb.append(counter[i]);
		}
		System.out.println(sb.toString());
	}

	static void put(ArrayList<Integer>[] edges, int a, int b) {
		if (edges[a] == null) {
			edges[a] = new ArrayList<>();
		}
		edges[a].add(b);
	}

	static void dfs(int[] counter, ArrayList<Integer>[] edges, int pos, int parent, int sum) {
		counter[pos] += sum;
		if (edges[pos] != null) {
			int sum2 = counter[pos];
			for (int child : edges[pos]) {
				if (child == parent) continue;
				dfs(counter, edges, child, pos, sum2);
			}
		}
	}
}


Measured memory_bytes: 220828
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1; 
        x = (x*x);
    }
    return res; 
}


int main()
{
    fastio;
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    f(i,2,n){
        if(s[i]=='C' && s[i-1]=='B' && s[i-2]=='A')ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
import heapq

n=int(input())
*a,=map(int,input().split())

lq=[]
lsum=0
for i in range(n):
    heapq.heappush(lq,a[i])
    lsum+=a[i]

l=[0]*(3*n)
l[n-1]=lsum
for i in range(n,2*n):
    lsum+=a[i]
    heapq.heappush(lq,a[i])
    lsum-=heapq.heappop(lq)
    l[i]=lsum

rq=[]
rsum=0
for i in range(3*n-1,2*n-1,-1):
    heapq.heappush(rq,-a[i])
    rsum+=a[i]

r=[0]*(3*n)
r[2*n]=rsum
for i in range(2*n-1,n-1,-1):
    rsum+=a[i]
    heapq.heappush(rq,-a[i])
    rsum+=heapq.heappop(rq)
    r[i]=rsum

ans=-10**15

for i in range(n-1,2*n):
    ans=max(ans,l[i]-r[i+1])

print(ans)

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

int main(){
  string a,b; cin >> a >> b; 
  int as=a.size(),bs=b.size();
  if(as>bs){
    cout<<"GREATER"<<endl;
  }
  else if(as<bs){
    cout<<"LESS"<<endl;;
  }
  else{
    if (a == b) {
			cout << "EQUAL";
		}
		else if (a < b) {
			cout << "LESS";
		}
		else {
			cout << "GREATER";
		}
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d;

  cin >> d;

  if(d == 22){
	cout << "Christmas Eve Eve Eve" << endl;
  }else if(d == 23){
	cout << "Christmas Eve Eve" << endl;
  }else if(d == 24){
	cout << "Christmas Eve" << endl;
  }else{
	cout << "Christmas" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////



	
int main() {
	string s;
	cin >> s;
	ll N, K;
	N = s.size();
	cin >> K;

	string sub[10000];
	
	rep(i, N) sub[i] = s.substr(i);

	sort(sub, sub + N);

	ll k = K;

	rep(i, N) {
		ll c = 0;

		if (i >= 1) {
			rep(j, sub[i - 1].size()) {
				if (sub[i - 1][j] == sub[i][j]) { c++; }
				else { break; }
			}
		}

		
		if (k > sub[i].size() - c) { k -= sub[i].size() - c; }
		else { cout << sub[i].substr(0, c + k); break; }

	}
	



	system("PAUSE");
}

Measured memory_bytes: 16376
#include <stdio.h>
#include <string.h>
 
int main(void) {
	const char hitachi[3] = { "hi" };
	char input[11];
	int ii;
	int not_hitachi = 1;
 
	memset(input, 0x00, sizeof(input));
 
	scanf("%s", input);
	for (ii = 0; input[ii] != 0 && ii<10;) {
		if (!(memcmp(&input[ii], hitachi, sizeof(char)*2))) {
			not_hitachi = 0;
            ii=ii+2;
			continue;
		}
		else {
			not_hitachi = 1;
			break;
		}
	}
 
	if (not_hitachi == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
 
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<=(b);++(i))
#define rep(i, n)  FOR(i,0,n-1)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define ll long long
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<ll, ll> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

vector<P> goen[maxn],gosn[maxn];
ll ryoen[maxn],ryosn[maxn];
ll dist[maxn];
ll ans[maxn];


void diken(ll start,ll n)
{
	priority_queue< P,vector<P>,greater<P> > que;
	que.push(mp(0,start));
	rep(i,maxn-1) dist[i] = INF;
	dist[start] = 0;

	while(!que.empty())
	{
		ll nown = que.top().second;
		ll nowc = que.top().first;
		que.pop();

		rep(i,goen[nown].size())
		{
			ll nxtn = goen[nown][i].first;
			ll nxtc = nowc + goen[nown][i].second;
			if(dist[nxtn] <= nxtc) continue;
			dist[nxtn] = nxtc;
			que.push(mp(nxtc,nxtn));
		}
	}
	
	rep(i,n) ryoen[i] = dist[i];
}

void diksn(ll start,ll n)
{
	priority_queue< P,vector<P>,greater<P> > que;
	que.push(mp(0,start));
	rep(i,maxn-1) dist[i] = INF;
	dist[start] = 0;

	while(!que.empty())
	{
		ll nown = que.top().second;
		ll nowc = que.top().first;
		que.pop();

		rep(i,gosn[nown].size())
		{
			ll nxtn = gosn[nown][i].first;
			ll nxtc = nowc + gosn[nown][i].second;
			if(dist[nxtn] <= nxtc) continue;
			dist[nxtn] = nxtc;
			que.push(mp(nxtc,nxtn));
		}
	}
	rep(i,n) ryosn[i] = dist[i];
}



int main() {
	
	ll n,m,s,t;cin>>n>>m>>s>>t;
	s--,t--;
	rep(i,m)
	{
		int u,v,a,b;cin>>u>>v>>a>>b;
		u--,v--;
		goen[u].pb(mp(v,a));
		goen[v].pb(mp(u,a));
		gosn[u].pb(mp(v,b));
		gosn[v].pb(mp(u,b));
	}

	diken(s,n);
	diksn(t,n);

	ans[n-1]=ryoen[n-1]+ryosn[n-1];
	for(int i=n-2;i>=0;i--)	ans[i] = min(ans[i+1],ryoen[i]+ryosn[i]);

	rep(i,n) cout << 1000000000000000 - ans[i] << endl;

	return 0;
}

Measured memory_bytes: 19964
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) {
    return a.first < b.first;
  }
  if (a.first == 0) {
    if (a.second >= 0) {
      return true;
    }
    return a.first < b.first;
  }
  if (b.first == 0) {
    if (b.second >= 0) {
      return false;
    }
    return a.first < b.first;
  }
  return a.second * b.first < a.first * b.second;
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}


/* -------- <templates end> -------- */


void solve() {
  int n, k; cin >> n >> k;
  vi arr(n);
  rep(i,n) cin >> arr[i];
  rep(i,n) --arr[i];

  unordered_map<int, vi> rem;
  rem[0].push_back(-1);
  int sum = 0;
  rep(i,n) {
    (sum += arr[i]) %= k;
    rem[sum].push_back(i);
  }

  ll ans = 0;
  for (auto &p : rem) {
    auto &vec = p.second;
    for (auto itr=vec.begin(); itr!=vec.end(); ++itr) {
      ans += (lower_bound(ALL(vec), (*itr)+k) - itr) - 1;
    }
  }
  cout << ans << endl;
}


/* -------- <programs end> -------- */


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 18632
#!/usr/bin/env python3

def main():
    S = input()

    N = len(S)

    AC = [0] * N
    CC = [0] * N
    QCA = [0] * N
    QCD = [0] * N

    a = 0
    q = 0
    for i in range(N):
        if S[i] == 'A':
            a += 1
        elif S[i] == '?':
            q += 1
        AC[i] = a
        QCA[i] = q

    c = 0
    q = 0
    for i in range(N - 1, -1, -1):
        if S[i] == 'C':
            c += 1
        elif S[i] == '?':
            q += 1
        CC[i] = c
        QCD[i] = q

    qc = q

    t = 0
    tt = 0
    m = 10 ** 9 + 7

    for i in range(1, N - 1):
        if S[i] == 'B':
            t += AC[i - 1] * CC[i + 1]
            t %= m

    if 1 <= qc:
        t *= 3
        t %= m
        for i in range(1, N - 1):
            if S[i] == 'B':
                t += QCA[i - 1] * CC[i + 1]
                t %= m
                t += AC[i - 1] * QCD[i + 1]
                t %= m
            elif S[i] == '?':
                t += AC[i - 1] * CC[i + 1]
                t %= m

    if 2 <= qc:
        t *= 3
        t %= m
        for i in range(1, N - 1):
            if S[i] == 'B':
                t += QCA[i - 1] * QCD[i + 1]
                t %= m
            elif S[i] == '?':
                t += QCA[i - 1] * CC[i + 1]
                t %= m
                t += AC[i - 1] * QCD[i + 1]
                t %= m

    if 3 <= qc:
        t *= 3
        t %= m
        for i in range(1, N - 1):
            if S[i] == '?':
                t += QCA[i - 1] * QCD[i + 1]
                t %= m

    for i in range(3, qc):
        t *= 3
        t %= m


    print(t)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14836
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,sa[1<<20],r[1<<20],tmp[1<<20];
char s[1<<20];
int k;
bool comp(int i,int j)
{
	if(r[i]!=r[j])return r[i]<r[j];
	else
	{
		int ri=i+k<=n?r[i+k]:-1;
		int rj=j+k<=n?r[j+k]:-1;
		return ri<rj;
	}
}
void construct()
{
	n=strlen(s);
	for(int i=0;i<=n;i++)
	{
		sa[i]=i;
		r[i]=i<n?s[i]:-1;
	}
	for(k=1;k<=n;k*=2)
	{
		sort(sa,sa+n+1,comp);
		tmp[sa[0]]=0;
		for(int i=1;i<=n;i++)
		{
			tmp[sa[i]]=tmp[sa[i-1]]+comp(sa[i-1],sa[i]);
		}
		for(int i=0;i<=n;i++)r[i]=tmp[i];
	}
}
char t[1010];
int T;
int c(int i)
{
	int j=0;
	for(;j<T&&s[i+j]==t[j];j++);
	return j<T?t[j]-s[i+j]:0;
}
bool func()
{
	int f=0,l=n+1;
	while(l-f>1)
	{
		int m=(f+l)/2;
		if(c(sa[m])<0)l=m;
		else f=m;
	}
	return c(sa[f])==0;
}
main()
{
	int p;scanf("%s\n%d\n",s,&p);
	construct();
	for(;~scanf("%s\n",t);)
	{
		T=strlen(t);
		puts(func()?"1":"0");
	}
}



Measured memory_bytes: 15856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=1000;

ll N,pn;

map<ll,ll> mp;

void solve_mp(ll pn){
  for(ll i=2;i<=ceil(sqrt(pn));i++){
    while(pn%i==0){
      mp[i]++;
      pn/=i;
    }
  }
  if(pn!=1)mp[pn]++;
}

int main(){
  cin>>N;
  bool fl=false;
  ll tmp;
  for(ll i=0;i<N;i++){
    cin>>tmp;
    if(tmp%2==1){
      fl=true;
      break;
    }
  }
  if(fl)cout<<"first"<<endl;
  else cout<<"second"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N, i;
	scanf("%d%d", &N, &i);

	printf("%d", (N-1)*(i-1));

}

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

class BinaryTree {
public:
    struct Node { int parent = -1, left = -1, right = -1; };

    BinaryTree(int n) : node_num(n) {

        nodes = std::vector<std::unique_ptr<Node>>(node_num);
        for (int i = 0; i < node_num; i++) {
            nodes[i] = std::make_unique<Node>();
        }

        preorder = std::vector<int>(node_num);
        inorder = std::vector<int>(node_num);
        for (int i = 0; i < node_num; i++) {
            std::cin >> preorder[i];
        }
        for (int i = 0; i < node_num; i++) {
            std::cin >> inorder[i];
        }

        root = preorder[0];
    }
    
    void reconstructTree(int n, int start, int end) {
        int pos =
            std::find(inorder.begin() + start, inorder.begin() + end, preorder[n]) - (inorder.begin() + start);

        if (pos + start > start) {
            nodes[preorder[n] - 1]->left = preorder[n + 1];
            nodes[preorder[n + 1] - 1]->parent = preorder[n];
            reconstructTree(n + 1, start, start + pos);
        }
        if (pos + start < end - 1) {
            nodes[preorder[n] - 1]->right = preorder[n + pos + 1];
            nodes[preorder[n + pos + 1] - 1]->parent = preorder[n];
            reconstructTree(n + pos + 1, start + pos + 1, end);
        }
    }

    void linePostOrder(int i) {
        if (i == -1) return;

        linePostOrder(nodes[i - 1]->left);
        linePostOrder(nodes[i - 1]->right);

        postorder.push_back(i);
    }

    void print() {
        int i = 0;
        for (; i < node_num - 1; i++) {
            std::cout << postorder[i] << " ";
        }
        std::cout << postorder[i] << std::endl;
    }

    int node_num, root;
    std::vector<int> preorder, inorder, postorder;
    std::vector<std::unique_ptr<Node>> nodes;
};

int main() {
    int n;
    std::cin >> n;
    
    BinaryTree tree(n);
    tree.reconstructTree(0, 0, n);
    tree.linePostOrder(tree.root);
    tree.print();
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  cout << (a + b)/2 + ((a + b) %2 != 0) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int h, w;
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    int ans = min(h, w);
    Rep(i, 1, h)
    {
        int s1 = i * w, s2 = (h - i) * (w / 2), s3 = (h - i) * (w - w / 2);
        int d1 = s1 - s2, d2 = s2 - s3, d3 = s3 - s1;
        if (d1 < 0)
            d1 *= -1;
        if (d2 < 0)
            d2 *= -1;
        if (d3 < 0)
            d3 *= -1;
        int tmp = max(d1, max(d2, d3));
        ans = min(ans, tmp);
    }
    Rep(i, 1, w)
    {
        int s1 = i * h, s2 = (w - i) * (h / 2), s3 = (w - i) * (h - h / 2);
        int d1 = s1 - s2, d2 = s2 - s3, d3 = s3 - s1;
        if (d1 < 0)
            d1 *= -1;
        if (d2 < 0)
            d2 *= -1;
        if (d3 < 0)
            d3 *= -1;
        int tmp = max(d1, max(d2, d3));
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

typedef long long lint;

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

	lint num = sqrt(n);

	for(lint i=num;i>0;i--){
		if(n%i == 0){
			lint j = n/i;
			lint sum = (i-1) + (j-1);
			printf("%lld",sum);
			return 0;
		}
	}

	return 0;


}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <int,int> cnt;
    int a,b,ans=1; 
    cin>>a>>b; 
    for (int i=2;i*i<=a;i++){
        if (a%i==0){
            while (a%i==0){
                a/=i;
            }
            cnt[i]=1;
        }
    }
    if (a>1) cnt[a]=1;
    for (int i=2;i*i<=b;i++){
        if (b%i==0){
            while (b%i==0){
                b/=i;
            }
            if (cnt[i]) cnt[i]=2;
        }
    }
    if (b>1 and cnt[b]) cnt[b]=2;
    for (auto &it: cnt)
        if (it.ss==2) ans++; 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3528
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	final int INF = 1<<28;
	
	int solve(final int s, final int e, final int[][] map, final int n){
		boolean[] used = new boolean[n];
		int d[] = new int[n];
		Arrays.fill(d, INF);
		
		d[s] = 0;
		while(true){
			int u=-1;
			for(int v=0; v<n; ++v){
				if(!used[v] && (u==-1 || d[v] < d[u])){
					u=v;
				}
			}
			if(u==-1)break;
			used[u] = true;
			for(int v=0; v<n; ++v){
				if(d[v] > d[u] + map[u][v]){
					d[v] = d[u] + map[u][v];
				}
			}
		}
		
		return d[e];
	}
	
	void io(){
		Scanner sc = new Scanner(System.in);
		while(true){
			final int n = sc.nextInt();  final int m = sc.nextInt();
			if(n==0 && m==0)break;
			
			int[][] map_cost = new int[m][m];
			int[][] map_time = new int[m][m];
			
			for(int i=0; i<m; ++i){
				for(int j=0; j<m; ++j){
					map_cost[i][j] = map_time[i][j] = i==j ? 0 : INF;
				}
			}
			
			for(int i=0; i<n; ++i){
				final int a = sc.nextInt() -1;
				final int b = sc.nextInt() -1;
				final int cost = sc.nextInt();
				final int time = sc.nextInt();
				
				map_cost[a][b] = map_cost[b][a] = cost;
				map_time[a][b] = map_time[b][a] = time;
			}
			
			final int k = sc.nextInt();
			for(int i=0; i<k; ++i){
				final int p = sc.nextInt()-1; final int q = sc.nextInt()-1;
				final int r = sc.nextInt();
				
				System.out.println(solve(p, q, r==0 ? map_cost : map_time, m));
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().io();
	}

}

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

int main(){
    char text[101], text2[201]={'\0'}, target[101];
    scanf("%s", text);
    strcpy(text2, text);
    strcat(text2, text);
    scanf("%s", target);
    bool result = !!(strstr(text2, target));
    printf("%s\n", (result?"Yes":"No"));
    return 0;
}



Measured memory_bytes: 3140
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
max_num = 0
for i in range(1, n+1):
  tmp_sum = 0
  for j in range(i):
    tmp_sum += a1[j]
  for j in range(i-1, n):
    tmp_sum += a2[j]
  max_num = max(max_num, tmp_sum)
print(max_num)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
int main() {
	int a = 0;
	std::vector<int> v(0);
	while (true)
	{
		++a;
		v.resize(a);
		std::cin >> v[a-1];
		if (v[a-1] == 0) { break; }
	}
	for (int i = 0; i<a-1; ++i) {
		std::cout << "Case " << i + 1 << ": " << v[i] << std::endl;
	}
	return 0;
}

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

using namespace std;
 
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;
 
const int MAX_N = 1000000;
int n,q;
string s;
 
int main()
{
  cin >> n >> s >> q;
 
  int k;
  while (q--) {
    cin >> k;
    i64 r = 0, dc = 0, mc = 0, mdc = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'D') {
        dc++;
      } else if (s[i] == 'M') {
        mc++;
        mdc += dc;
      } else if (s[i] == 'C') {
        r += mdc;
      }
 
      if (i >= k-1) {
        if (s[i-k+1] == 'D') {
          dc--;
          mdc -= mc;
        } else if (s[i-k+1] == 'M') {
          mc--;
        }
      }
    }
    cout << r << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1412
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
/*
 
 
 
 */

public class Main {

    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int t=1;
        //t = sc.ni();
        while(t-->0) {
        	solve(pw,sc);
        }
       
        pw.close();
    }
   
    private static void solve(PrintWriter pw, FastScanner sc) {
    	int x = sc.ni();
    	pw.print(1-x);
	}
    

	static <T> void deb(T x,int o){
       System.out.print(x);
       if(o==0) {
    	   System.out.println();
    	   
       }
    }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String ne() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String ne(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int ni() {
			return Integer.parseInt(ne());
		}
		
		long nl() {
			return Long.parseLong(ne());
		}
		
		double nd() {
			return Double.parseDouble(ne());
		}
		
	    
	}
   
}

Measured memory_bytes: 32732
/* A */

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int a, b;
    cin >> a >> b;
	if(a <= 5) cout << 0 << endl;
	else if( a <= 12) cout << b/2 << endl;
	else cout << b << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

num = {}
for v in a:
  if v in num:
    num[v] = num[v] + 1
  else:
    num[v] = 1
m = int(input())
t = [int(x) for x in input().split()]

ok = True
for v in t:
  if v not in num:
    ok = False
  elif num[v] <= 0:
    ok = False
  else:
    num[v] = num[v] - 1

if ok:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 52000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		long N = GetLong();
		long P = GetLong();
		long numEven = 0;
		long numOdd = 0;
		for(long i = 0; i < N; i++)
		{
			if(GetLong() % 2 == 0)
				numEven++;
			else
				numOdd++;
		}

		long combOdd = 0;
		for(long i = P; i <= numOdd; i += 2)
			combOdd += combination(numOdd, i);
		Console.WriteLine(combOdd * (1L << (int)numEven));
	}

	private static long combination(long n, long k) 
	{
		long r = 1;
		for(long d = 1; d <= k; d++) 
		{
			r *= n--;
			r /= d;
		}
		return r;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 11092
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>

//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }

const ll    BIGP = 1000000007;
const ll    INF_I = std::numeric_limits<ll>::max();
const float INF_F = std::numeric_limits<float>::infinity();
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    vector<ll> h;
    cin >> N >> K;
    rep(i, N)
    {
        ll t;
        cin >> t;
        h.push_back(t);
    }
    vector<ll> dp(N,INF_I);
    dp[0] = 0;
    rep(i, N)
    {
        rep(j, K)
        {
            ll t = i - j - 1;
            if (t >= 0)
            {
                chmin(dp[i], dp[t] + abs(h[i] - h[t]));
            }
        }
    }
    cout << dp.back();
}

Measured memory_bytes: 4600
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500 * a + 100 * b + 50 * c == X:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define maxn 1000000005
using namespace std;
char id[maxn];
int h;
int main()
{
    int a;
    cin>>a;
    cin>>id;
    int m=0;
    for(int i=0;i<a;i++)
    {
        if(id[i]=='I')
        {
            h++;
        }
        else if(id[i]=='D')
        {
            h--;
        }
        m=max(m,h);
    }
    cout<<m<<endl;
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> a(5, 0);
    rep(i, N){
        string s; cin >> s;
        if(s[0] == 'M') a[0]++;
        if(s[0] == 'A') a[1]++;
        if(s[0] == 'R') a[2]++;
        if(s[0] == 'C') a[3]++;
        if(s[0] == 'H') a[4]++;
    }
    ll res = 0;
    rep(i, 5){
        Rep(j, i+1, 5){
            Rep(k, j+1, 5){
                res += a[i]*a[j]*a[k];
            }
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main()
{
	int a,c,d,e,sum=0;
	string s;
	cin>>s;
    vector<int> temp(2);
	int be;
	d=s[0]-'0';
    e=s[1]-'0';
    temp[0]=d*10+e;
    d=s[2]-'0';
    e=s[3]-'0';
    temp[1]=d*10+e;
    if(temp[0]>12||temp[0]<1)
        if(temp[1]>12||temp[1]<1)
        {
            cout<<"NA";
            return 0;
        }
        else
        {
            cout<<"YYMM";
            return 0;
        }
    else if(temp[0]<=12 && temp[0]>0 && temp[1]<=12 && temp[1]>0)  
    {
        cout<<"AMBIGUOUS";
        return 0;
    }
    else
    {
        cout<<"MMYY";
    }
    
	
	return 0;
}
	

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

int main() {
    int N, A, B;
    string S;
    cin >> N >> A >> B;
    cin >> S;

    int cnt1 = 0;
    int cnt2 = 0;
    
    rep(i, N) {
        string ans = "Yes";
        if (S[i] == 'c') ans = "No";
        if (S[i] == 'a') {
            if (cnt1 < A+B) {
                cnt1++;
            } else { ans = "No"; }
        }
        if (S[i] == 'b') {
            if (cnt1 < A+B && cnt2 < B) {
                cnt1++; cnt2++;
            } else { ans = "No"; }
        }
        cout << ans << endl;

    }

    return 0;

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main() {

  int n=0,a=0;
  string s;
  cin >> n;
  
  a=n/1000;
  if(n%1000==0){
  cout << a*1000-n;
  }else{
  cout << (a+1)*1000-n;
  }
}

Measured memory_bytes: 3628
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
  int x , y ;
   cin >> x >> y ;

   if ( x < 8 ) x = 8 ;
   if ( y < 8 ) y = 8 ;
   if ( x+y > 16 ) cout <<":(";
   else cout <<"Yay!";
return 0 ;
}


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

int main() {
	int64_t x; cin >> x;
	for(int64_t a = -1000; a <= 1000; ++a) {
		for(int64_t b = -1000; b <= 1000; ++b) {
			int64_t A = a * a * a * a * a;
			int64_t B = b * b * b * b * b;
			if(A - B == x) {
				cout << a << " " << b << '\n';
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3596
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
b = set(a)

NN = 10 ** 6 + 100
primes = set([])
isprime = [False for _ in range(NN + 1)]
cnt = [True for _ in range(NN + 1)]
for i in a:
    if cnt[i]:
        isprime[i] = True
        cnt[i] = False
    else:
        isprime[i] = False
for i in range(1, NN + 1):
    if not cnt[i]:
        for j in range(i * 2, NN + 1, i):
            isprime[j] = False
    if isprime[i]:
        primes.add(i)
ans = 0
for i in b:
    if isprime[i]:
        ans += 1
print(ans)


Measured memory_bytes: 172268
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
using namespace std;


int main() {
	int A, B;
	cin >> A >> B;
	if (A == 1 && B == 2) {
		cout << 3 << endl;
	}
	else if (A == 2 && B == 1) {
		cout << 3 << endl;
	}
	else if (A == 1 && B == 3) {
		cout << 2 << endl;
	}
	else if (A == 3 && B == 1) {
		cout << 2 << endl;
	}
	else if (A == 2 && B == 3) {
		cout << 1 << endl;
	}
	else if (A == 3 && B == 2) {
		cout << 1 << endl;
	}



}

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

typedef pair<int, int> P;

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

int sx, sy;
int ans;
int w, h;
vector<string> ma;

void BFS(){
	queue<P> que;
	que.push(P(sy, sx));
	ans++;

	while(que.size()){
		P p = que.front(); que.pop();

		for(int i=0; i<4; i++){
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];

			if(ny >= 0 && ny < h && nx >= 0 && nx < w && ma[ny][nx] == '.'){
				ans++;
				ma[ny][nx] = '#';
				que.push(P(ny, nx));
			}
		}

	}

}

int main(void){
	while(1){
		ma.clear();
		ans = 0;
		cin >> w >> h;
		if(w == 0 && h == 0) break;

		for(int i=0; i<h; i++){
			string tmp;
			cin >> tmp;

			ma.push_back(tmp);
		}

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(ma[i][j] == '@' ){
					sy = i;
					sx = j;
				}

			}
		}

		BFS();

		cout << ans << endl;


	}


	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0, x;
  cin >> n;
  unordered_map<ll, ll> mp;
  for (int i = 1; i <= n; ++i) cin >> x, ans += mp[i - x], mp[i + x]++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18560
#include <iostream>

using namespace std;

int main() {
    long long N, *A, *B, answer = 0;

    // input
    cin >> N;

    A = new long long[N + 1];
    B = new long long[N];
    for (long long i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    for (long long i = 0; i < N; i++) {
        cin >> B[i];
    }

    // process
    for (long long i = N - 1; i >= 0; i--) {
        if (A[i + 1] >= B[i]) {
            answer += B[i];
            A[i + 1] -= B[i];
            B[i] = 0;
        } else {
            answer += A[i + 1];
            B[i] -= A[i + 1];
            A[i + 1] = 0;
            if (A[i] >= B[i]) {
                answer += B[i];
                A[i] -= B[i];
                B[i] = 0;
            } else {
                answer += A[i];
                B[i] -= A[i];
                A[i] = 0;
            }
        }

    }

    // output
    cout << answer;

    return 0;
}

Measured memory_bytes: 1792