akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Control.Monad.ST
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

newUF n = VUM.replicate n (-1 :: Int)

root uf x = do
    p <- VUM.read uf x
    if p < 0
        then return x
        else do
            r <- root uf p
            VUM.write uf x r
            return r

same uf x y = liftM2 (==) (root uf x) (root uf y)

unite uf x y = do
    px <- root uf x
    py <- root uf y
    when (px /= py) $ do
        sx <- VUM.read uf px
        sy <- VUM.read uf py
        let (par, chld) = if sx < sy then (px, py)　else (py, px)
        VUM.write uf chld par
        VUM.write uf par (sx + sy) 

size uf x = do
    px <- root uf x
    s <- VUM.read uf px
    return $ abs s
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    ab <- replicateM m $ do
        [a,b] <- getIntList
        return (a-1,b-1)
    
    let vec = VU.create $ do
        uf <- newUF n
        forM_ ab $ \(a,b) -> do
            unite uf a b
        return uf
    let ans = abs $ VU.minimum vec
    print ans

Measured memory_bytes: 102016
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a,b,c,d;

LL calc(LL a){
	return a/c+a/d-a/(c/__gcd(c,d)*d);
}
int main() {
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld\n",b-a+1-calc(b)+calc(a-1));
	return 0;
}


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

int main(){
  vector<string> v;
  string s;
  while(getline(cin, s)){
    stringstream ss(s);
    string tmp;
    v.clear();
    while(getline(ss, tmp, ' ')){
      v.push_back(tmp);
    }
    while(true){
      bool flag=false;
      for(int i=0; i<v.size(); i++){
        for(int j=0; j<v[i].length(); j++){
          if(v[i][j]=='.') continue;
          if(v[i][j]=='z') v[i][j]='a';
          else v[i][j]++;
        }
      }
      for(int i=0; i<v.size(); i++){
        if(v[i]=="this" || v[i]=="that" || v[i]=="the") flag=true;
      }
      if(flag)break;
    }
    for(int i=0; i<v.size(); i++){
      if(i!=v.size()-1) cout << v[i] << ' ';
      else cout << v[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n, k;
    cin >> n >> k;
    VL a(n);
    REP(i,n) a[i] = in();
    VI next(n, -1);
    map<int, int> mp, first;
    FORR(i,n-1,0){
        if (mp.count(a[i])){
            next[i] = mp[a[i]];
        }
        mp[a[i]] = i;
    }
    REP(i,n) if (first.count(a[i]) == 0) first[a[i]] = i;
    VI start(n, -1);
    FORR(i,n-1,0){
        if (next[i] == -1) start[i] = a[i];
        else if (next[i] == n - 1) start[i] = 0;
        else start[i] = start[next[i] + 1];
    }
    VI d({0});
    set<int> st({0});
    int x = 0;
    while (true){
        int y = (x == 0 ? 0 : first[x] + 1);
        if (y == n){
            y = 0;
        }else{
            y = start[y];
        }
        if (st.count(y)) break;
        d.push_back(y);
        st.insert(y);
        x = y;
    }
    // for (int x : d) cout << x << " ";
    //     cout << endl;

    ll p = d.size();
    ll s = d[(k - 1) % p];
    if (s != 0) s = first[s] + 1;
    VI ans(n, -1);
    x = 0;
    map<int, int> pos;
    FOR(i,s,n-1){
        if (pos.count(a[i]) == 0){
            ans[x] = a[i];
            pos[a[i]] = x;
            x++;
        }else{
            int xo = x;
            x = pos[a[i]];
            FOR(i,x,xo-1) pos.erase(ans[i]);
        }
        // REP(j,x) cout << ans[j] << " ";
        // cout << endl;
    }
    REP(i,x) printf("%d ", ans[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 43764
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, ans = 0;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            B.at(i) = 0;
        }
        else {
            B.at(i) = __gcd(B.at(i - 1), A.at(i - 1)); 
        }
    } 
    for (int i = N - 1; i >= 0; i--) {
        if (i == N - 1) {
            C.at(N - 1) = 0;
        }
        else {
            C.at(i) = __gcd(C.at(i + 1), A.at(i + 1));
        }
    }
    for (int i = 0; i < N; i++) {
        int a;
        a = __gcd(B.at(i), C.at(i));
        ans = max(ans, a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char S[3][2002];
int L[3];
bool mita[3][3][4020], dame[3][3][4020];
inline bool DAME(int i, int j, int k) {
	if (mita[i][j][k]) return dame[i][j][k];
	mita[i][j][k] = 1;
	auto si = S[i] + k;
	auto sj = S[j];
	rep(x, min(L[i] - k, L[j])) {
		if (si[x] != '?' && sj[x] != '?' && si[x] != sj[x]) {
			return dame[i][j][k] = 1;
		}
	}
	return 0;
}

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


	rep(i, 3) scanf("%s", S[i]);
	rep(i, 3) L[i] = strlen(S[i]);

	int P[3] = { 0,1,2 };
	int saishou = 6000;
	rep(x, 6) {
		int i = P[0];
		int j = P[1];
		int k = P[2];
		rep(p, L[i] + 1) {
			int tmp = max(L[i], L[j] + p);
			if (tmp >= saishou) break;
			if (!DAME(i, j, p)) {
				rep(q, saishou - L[k] - p) {
					if (!DAME(j, k, q) && !DAME(i, k, p + q)) {
						saishou = max(tmp, L[k] + p + q);
						break;
					}
				}
			}
		}
		next_permutation(P, P + 3);
	}

	printf("%d", saishou);


	Would you please return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 and 0 <= b )cout << "Zero" << endl;
    else if (a >= 1)cout << "Positive" << endl;

    else if ((abs(a) - abs(b) + 1)%2 == 0)cout << "Positive" << endl;
    else cout << "Negative" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

bool is_prime(ll n){
  for(int i = 2; i * i <= n; i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n; cin >> n;
  ll j = 6, cnt = 0;
  while(cnt<n){
    if(is_prime(j)){
      cout << j << " ";
      cnt++;
    }
    j += 5;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
input = gets.to_s.split(" ").map(&:to_i)
value_A = gets.to_s.split(" ").map(&:to_i)

sina_kosu = input[0]
waribiki = input[1]

new_value = 0
index = 0
sum = 0
value_A.sort!.reverse!  
priority_queue = []
priority_queue << value_A.shift / 2

for i in 0..waribiki-2 do
  if value_A == []
    value_A = priority_queue
    priority_queue = []
    priority_queue << value_A.shift / 2

  elsif value_A[0] > priority_queue[0]
    priority_queue << value_A.shift / 2
  else
    priority_queue << priority_queue.shift / 2
  end
end

value_A.each do |a|
  sum += a
end

priority_queue.each do |a|
  sum += a
end

puts sum


Measured memory_bytes: 12928
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Problems 1275
2007年 アジア地区予選 東京大会 問題A And Then There Was One
"""

while True:
    n, k, m = map(int, input().split())
    if n == 0 and k == 0 and m == 0:
        break
    list = [int(i) for i in range(1,n+1)]
    m -= 1
        
    while True:
        if 1 < n:
            list.pop(m)
            n -= 1
            m = (m+k-1) % n
        else:
            print(list[0])
            break


Measured memory_bytes: 5936
#include<bits/stdc++.h>
using namespace std;
map<long long,int> h;
int a[300000];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",a+i);
	long long sum=0,ans=0;
	h[0]++;
	for (int i=1;i<=n;i++){
		sum+=a[i];
		ans+=h[sum];
		h[sum]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 13568
#include<cstdio>
long long n;
double ans,x,d;
int main()
{
	scanf("%lld%lf%lf",&n,&x,&d);
	for(n*=2;n;n-=2)
	{
		ans+=(2*x+(n-1)*d)*1.0/2;
		x=((n+2)*x+5*d)*1.0/n;
		d=(n+4)*d*1.0/n;
	}
	printf("%.10f\n",ans);
}

Measured memory_bytes: 128
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    FAST;
    map<string,int>blue,red;
    map<string,int>::iterator it;
    ll n,m,t;
    cin>>n;
    while(n--)
    {
        string str;
        cin>>str;
        blue[str]++;
    }
    cin>>m;
    while(m--)
    {
        string str;
        cin>>str;
        red[str]++;
        blue[str]--;
    }
    int ans=INT_MIN;
    for(it=blue.begin();it!=blue.end();it++)
    {
        ans=max(ans,(it->second));
    }
    if(ans>=0)
    {
        cout<<ans<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long

using namespace std;

LL dp[1005][1005];
char a[1005][1005];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int r,c;
    cin >> r >> c;
    for (int i=1;i<=r;i++) {
        string s;
        cin >> s;
        for (int j=1;j<=c;j++) {
            a[i][j]=s[j-1];
        }
    }    
    memset (dp,0,sizeof(dp));
    for (int i=1;i<=r;i++) {
        for (int j=1;j<=c;j++) {
            if (i==1&&j==1) {
                dp[i][j]=1;
                continue;
            }
            if (a[i][j-1]=='.') dp[i][j]+=dp[i][j-1];
            if (a[i-1][j]=='.') dp[i][j]+=dp[i-1][j];
            dp[i][j]%=MOD;
        }
    }
    /*
    for (int i=1;i<=r;i++) {
        for (int j=1;j<=c;j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << dp[r][c];
    return 0;
}


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

const int maxn = 400+3;
const int maxm = 800+3;
const int mod = 998244353;
int nw[maxn][maxm];
int dp[maxn][maxm];
int a[maxn],b[maxn],s;
int sn,sm,n;
int fact[maxm],finv[maxm],invs[maxm];
inline int add(int a,int b){
	a+=b;
	if(a>=mod)	return a-mod;
	return a;
}
inline int sub(int a,int b){
	a-=b;
	if(a<0)	return a+mod;
	return a;
}
int mul(int a,int b){
	long long t=1ll*a*b;
	return t-t/mod*mod;
}
inline int qp(int a,int b){
	int ans=1;
	while(b){
		if(b&1)	ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
inline void tran(){
	dp[0][0]=1;
	int t,p,d;
	for(int i=0;i<n;++i){
		p=mul(a[i],invs[s]);
		for(int ii=sn;ii>=0;--ii)
			for(int jj=sm;jj>=0;--jj){
				if(!dp[ii][jj])	continue;
				t=dp[ii][jj];	dp[ii][jj]=0;
				dp[ii+a[i]][jj]=add(dp[ii+a[i]][jj],t);
				for(int k=0,d=1;k<b[i];++k,d=mul(d,p))
					dp[ii][jj+k]=sub(dp[ii][jj+k],mul(mul(finv[k],d),t));
			}
		sn+=a[i];
		sm+=b[i];
	}
	/*for(int ii=0;ii<=sn;++ii)
	{
		for(int jj=0;jj<=sm;++jj)
			cout<<dp[ii][jj]<<" ";
		cout<<endl;
	}*/
}
inline int get(int ai,int bi){
	int t,p=mul(ai,invs[s]);
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj)
			nw[ii][jj]=dp[ii][jj];
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj){
			if(bi)	nw[ii][jj]=sub(0,nw[ii][jj]);
			if(!nw[ii][jj])	continue;
			t=nw[ii][jj];
			nw[ii+ai][jj]=sub(nw[ii+ai][jj],t);
			for(int k=1,d=p;k<bi;++k,d=mul(d,p))
				nw[ii][jj+k]=add(nw[ii][jj+k],mul(mul(finv[k],d),t));
		}
	/*cout<<"vvvvv"<<endl;
	for(int ii=0;ii<=sn;++ii)
	{
		for(int jj=0;jj<=sm;++jj)
			cout<<nw[ii][jj]<<" ";
		cout<<endl;
	}
	cout<<"^^^^^"<<endl;*/
	int ans=0,lambda,f,d;
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj){
			lambda = nw[ii][jj];
			if(!lambda)	continue;
			f = mul(fact[jj+bi],finv[bi-1]);
			d = qp(mul(s,invs[s-ii]),jj+bi+1);
			//cout<<ii<<" "<<jj<<" "<<lambda<<" "<<f<<" "<<d<<endl;
			ans = add(ans, mul(lambda,mul(f,d)) );
		}
	return mul(ans,qp(p,bi));
}
inline void init(){
	fact[0]=invs[0]=1;
	for(int i=1;i<maxm;++i)
		fact[i]=mul(fact[i-1],i);
	finv[maxm-1]=qp(fact[maxm-1],mod-2);
	for(int i=maxm-2;i>=0;--i)
		finv[i]=mul(finv[i+1],i+1);
	for(int i=1;i<maxm-1;++i)
		invs[i]=mul(finv[i],fact[i-1]);
}
int main(){
    ios::sync_with_stdio(false);
    init();
    cin>>n;
    for(int i=0;i<n;++i)
		cin>>a[i]>>b[i];
	for(int i=0;i<n;++i)	s=add(s,a[i]);
	tran();
	int ans=0;
	for(int i=0;i<n;++i)
		ans = add(ans,get(a[i],b[i]));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2816
package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
    "strings"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    scanner.Text()
    scanner.Scan()
    in2 := scanner.Text()
    strs := strings.Fields(in2)

    Hs := []int{}
    maxH := 0
    solution := 0
    for i, str := range strs {
        v, _ := strconv.Atoi(str)
        Hs = append(Hs, v)

        if i == 0 || maxH <= v {
            maxH = v
            solution += 1
            continue
        }
    }

    fmt.Println(solution)
}

Measured memory_bytes: 640
#include<iostream>

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

using namespace std;

int main(){
	for(int n;cin>>n,n;){
		int g[26][26]={};
		bool tc[26][26]={},use[26]={};
		rep(i,n){
			string s;	cin>>s;
			int u=s[0]-'a',v=s[s.length()-1]-'a';
			g[u][v]++;
			tc[u][v]=true;
			use[u]=use[v]=true;
		}

		bool ok=true;
		rep(u,26){
			int indeg=0,outdeg=0;
			rep(v,26)	indeg+=g[v][u],outdeg+=g[u][v];
			if(indeg!=outdeg){ ok=false; break; }
		}
		if(!ok){ cout<<"NG"<<endl; continue; }

		rep(k,26)rep(i,26)rep(j,26)	tc[i][j]=tc[i][j]||(tc[i][k]&&tc[k][j]);

		rep(u,26){
			if(use[u]){
				rep(v,26)	if(use[v] && !tc[u][v]){ ok=false; break; }
				if(!ok)	break;
			}
		}
		cout<<(ok?"OK":"NG")<<endl;
	}

	return 0;
}

Measured memory_bytes: 916
class Dice():
    #0:上面、1:前面、2:側面(見える方)、3:側面(裏側)、4:背面、5:底面
    def __init__(self,numlist):
        self.lst=numlist
    
    def roll(self,direction):
        for x in direction:
            if x=="S" : self.lst=[self.lst[4],self.lst[0],self.lst[2],self.lst[3],self.lst[5],self.lst[1]]
            elif x=="N" : self.lst=[self.lst[1],self.lst[5],self.lst[2],self.lst[3],self.lst[0],self.lst[4]]
            elif x=="W" : self.lst=[self.lst[2],self.lst[1],self.lst[5],self.lst[0],self.lst[4],self.lst[3]]
            elif x=="E" : self.lst=[self.lst[3],self.lst[1],self.lst[0],self.lst[5],self.lst[4],self.lst[2]]        
    
    def dice_set_make(self):
        self.dice_set=[]
        for x in ["","W","WW","WWW","SE","SW"]:
            self.work=Dice(self.lst[:])
            self.work.roll(x)
            self.dice_set.append(self.work.lst)
            for _ in range(3):
                self.work.roll("S")
                self.dice_set.append(self.work.lst)
        

lst=list(map(int,input().split()))
d1=Dice(lst)
d1.dice_set_make()
dice_set=d1.dice_set
lst2=list(map(int,input().split()))

if lst2 in dice_set:
    print("Yes")
else : print("No")


Measured memory_bytes: 5608
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;
const int maxn = 60;
int A[maxn];
int ans;
int now[maxn];
int cnt;
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        cin >> A[i];
    }
    for(int i = 1;i <= min(m,n);i++){
        for(int j = 0;j <= i;j++){
            for(int k = 0;k <= n;k++){
                now[k] = 0;
            }
            cnt = 0;
            for(int k = 1;k <= i-j;k++){
                now[++cnt] = A[k];
            }
            for(int k = 1;k <= j;k++){
               now[++cnt] = A[n-k+1];
            }
            sort(now+1,now+1+i);        
            int tot = m - i;
            int Sum = 0;
            int x = 1;
            while(tot && now[x] < 0){
                x ++ ;
                tot--;
            }
            for(;x <= i;x++){
                Sum += now[x];
            }
            ans = max(ans,Sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ ->
    Scanf.scanf "%s\n" @@ fun s -> s in
  let dx = [| 1; 1; 0; -1; -1; -1; 0; 1 |] in
  let dy = [| 0; 1; 1; 1; 0; -1; -1; -1 |] in
  Array.iteri (fun i s ->
    print_endline @@ String.mapi (fun j c ->
      if c = '#' then '#'
      else
        Array.init 8 (fun n -> n)
        |> Array.to_list
        |> List.filter (fun n ->
            try ss.(i + dy.(n)).[j + dx.(n)] = '#' with _ -> false)
        |> List.length
        |> ( + ) (Char.code '0')
        |> Char.chr) s) ss

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll R, G, B, N;

void solve() {
  ll res = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if ((N - i * R - j * G >= 0) && (N - i * R - j * G) % B == 0) {
        res++;
      }
    }
  }
  cout << res << "\n";
}

int main() {
  cin >> R >> G >> B >> N;
  solve();
  return 0;
}

Measured memory_bytes: 256
s=input()
n=int(input())
t=""
u=""
bo=True
for _ in range(n):
  q=input().split()
  if q[0]=="1":
    t,u=u,t
    if bo==True:
      bo=False
    else:
      bo=True
  else:
    if q[1]=="1":
      t+=q[2]
    else:
      u+=q[2]
t=t[::-1]
if bo==False:
  s=s[::-1]
print(t+s+u)

Measured memory_bytes: 4384
url = "https://atcoder.jp/contests/abc092/tasks/abc092_a"

def main():
    ans = 0
    t = []
    for i in range(2):
        t.append(int(input()))
    ans = min(t)
    t = []
    for i in range(2):
        t.append(int(input()))
    ans += min(t)
    print(ans)


if __name__ == '__main__':
    main()




Measured memory_bytes: 2940
import Data.Foldable
import Data.List

main :: IO ()
main = interact $ unlines.map (solve.map read.words).takeWhile (/="0 0").lines

solve       :: [Int] -> String
solve [x,y] = unlines $ f x (f y '#' '.') (f y '.' '#')
    where f n a b = take n.cycle $ a : [b]

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 998244353

class Mod{
    //static const int MOD = 1000000007;
    long long a;
public:
    Mod(){a = 0;}
    Mod(long long x){a = (x % MOD + MOD) % MOD;}
    const Mod operator+(const Mod& x) const{return Mod(a + x.a);}
    const Mod operator-(const Mod& x) const{return Mod(a - x.a);}
    const Mod operator*(const Mod& x) const{return Mod(a * x.a);}
    const Mod operator/(const Mod& x) const{ //フェルマーの小定理、aとMODが互いに素の時のみ
        if(x.a == 0)return 0;
		if(a % x.a == 0)return Mod(a/x.a);
		int b = MOD - 2;long long c = x.a;long long ret = 1;
        while(b > 0){if(b & 1){ret *= c;ret %= MOD;}
            c *= c;c %= MOD;b >>= 1;
        }
        return Mod(a * ret);
    }
    long long getValue(){return a;}
};

typedef long long ll;
typedef pair<ll,ll> P;
ll seica[2222];
int main()
{
	seica[0] = 1;
	REP(i,2221)seica[i+1] = seica[i] * 2 % MOD;
	int n;cin >> n;
	vector<pair<ll,ll>> v;
	REP(i,n){
		int a,b;cin >> a >> b;
		v.PB(MP(a,b));
	}
	ll ans = (seica[n] - n - 1 + MOD) % MOD; 
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			vector<int> tmp;
			int cou = 0;
			ll a = v[i].FI - v[j].FI;
			ll b = v[i].SE - v[j].SE;
			for(int k = 0;k < n;k++){
				ll c = v[i].FI - v[k].FI;
				ll d = v[i].SE - v[k].SE;
				if(a * d == b * c){
					cou++;
					tmp.PB(k);
				}
			}
			DBG(cout << "ij " << i << ' ' << j << endl;);
			DBG(cout << "cou " << cou << endl;SHOW1d(tmp,tmp.size()););
			ans = (ans - Mod(Mod(seica[cou] - cou - 1)/(cou*(cou-1)/2)).getValue() + MOD) % MOD;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, c, i;
    int judge=0;
    scanf("%d %d %d", &a, &b, &c);
    if (a==b){
        judge+=1;
    }
    if (b==c){
        judge+=1;
    }
    if (a==c){
        judge+=1;
    }
    if (judge==1){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int b = 0;
		
		for(int c=0; c<=n-1; c++){
			
			for(int z=0; a[c]%2==0; ){
				
				a[c] = a[c]/2;
				b++;
				
			}
			
		}
		
		Console.WriteLine(b);
		
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>

int main()
{
  int N, x;
  std::cin >> N >> x;
  int a[N];
  for ( int i = 0; i < N; i++ ) std::cin >> a[i];
  std::sort(a, a+N);
  int ans = 0;
  bool all = true;
  for ( int i = 0; i < N; i++ ) {
    if ( x >= a[i] ) {
      ans++;
      x -= a[i];
    } else {
      all = false;
      break;
    }
  }
  if ( all & x > 0 ) ans--;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

using Graph = vector<vector<int>>;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    Graph G(n);
    vector<vector<int>> dp(n, vector<int>(n, mod));
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    rep(i, n)dp[i][i] = 0;
    rep(k, n)rep(i, n)rep(j, n){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }
    vector<vector<int>> ans(n, vector<int>(n, mod));
    rep(i, n)rep(j, n){
        if(dp[i][j] <= l){
            G[i].push_back(j);
            ans[i][j] = 1;
        }
    }
    rep(i, n)ans[i][i] = 0;
    rep(k, n)rep(i, n)rep(j, n){
        ans[i][j] = min(ans[i][j],ans[i][k] + ans[k][j]);
    }
    int q;
    cin >> q;
    rep(i, q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        if(ans[s][t] == mod)cout << -1 << endl;
        else cout << ans[s][t] - 1 << endl;
    }
}

Measured memory_bytes: 4908
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      vector<int> X(N);//初期化されてる
      int count=0;
      int box=1;
      
      for(int i=0;i<N;i++){
        cin >> X.at(i);
      }
      
      for(int i=0;i<N;i++){
        if(X.at(box-1)==2){
          cout << i+1 << endl;
          break;
        }else{
          box=X.at(box-1);
        }
        if(i==N-1){
          cout << -1 << endl;
        }
      }
      
    }

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 10000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    int N; cin>>N;
    vector<pair<int, int>> A(N);
    for(int i=0; i<N; i++){
        cin>>A[i].second>>A[i].first;
    }
    sort(ALL(A));
    bool ans=1;
    ll t=0;
    for(int i=0; i<N; i++){
        t+=A[i].second;
        if(t>A[i].first){
            ans=0;
            break;
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

#define int long long

const int maxn = 1E+5 + 5;

int x, y, a, b, c, ans;
int red[maxn], green[maxn];
priority_queue<int> q;

signed main()
{
	scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &c);
	for(int i = 1; i <= a; ++i)
		scanf("%lld", &red[i]);
	for(int i = 1; i <= b; ++i)
		scanf("%lld", &green[i]);
	
	sort(red + 1, red + a + 1);
	sort(green + 1, green + b + 1);
	
	for(int i = 1; i <= x && i <= a; ++i)
		q.push(red[a - i + 1]);
	for(int i = 1; i <= y && i <= b; ++i)
		q.push(green[b - i + 1]);
	
	for(int i = 1; i <= c; ++i) {
		int t;
		
		scanf("%lld", &t);
		q.push(t);
	}
	
	for(int i = 1; i <= x + y; ++i)
		ans += q.top(), q.pop();
	
	printf("%lld", ans);
}

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

typedef long long ll;
const int maxn = 5005;

int mod;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int add(int x, int y) {return x + y >= mod ? x + y - mod : x + y;}

int n, ans, f[maxn][maxn], b[maxn];

int main()
{
	n = gi(); mod = gi();
	for (int i = 2; i <= n / 2 + 1; ++i) b[i] -= n / 2 + 2 - i;
	for (int i = 1; i <= n - n / 2; ++i) b[i] += n / 2;
	for (int i = n - n / 2 + 1; i <= n; ++i) b[i] += n - i + 1;
	for (int i = 2; i <= n; ++i) ++b[i];

	f[n + 1][0] = 1;
	for (int i = n; i >= 2; --i)
		for (int j = 0; j < n; ++j) {
			f[i][j] = f[i + 1][j];
			if (j >= b[i]) f[i][j] = add(f[i][j], f[i][j - b[i]]);
		}
	
	for (int i = 0; i < n; ++i) ans = (ans + (ll)f[2][i] * (n - i)) % mod;
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 98048
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> v(n);
    for(int i = 0; i < n;i++)
    {
        cin >> v[i];
    }
    ll ret = (1L << 60);
    vector<ll> minDist(n);
    fill(minDist.begin(), minDist.end(), 1e12);
    for(int i = 0; i < n;i++)
    {
        ll sum = 0;
        for(int j = 0;j < n;j++)
        {
            ll index = (j - i + n) % n;
            minDist[j] = min(minDist[j], v[index]);
            sum += minDist[j];
        }
        sum += x * i;
        ret = min(ret, sum);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int N;
    map<int,int> A;
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        if (A.count(a)) {
            A[a] = (A[a] + 1) % 2;
        } else {
            A[a] = 1;
        };
    }
    int ans = 0;
    for (auto i:A) {
        ans += A[i.first];
    }
    print(ans);
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N);
	in_v(ll, X, N);
	decltype(auto) Xb = X;
	sort_v(X);
	loop(i, N)
		if (Xb[i] <= X[N / 2 - 1]) out(X[N/2]);
		else out(X[N / 2 - 1]);
	return 0;
}


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


int main(){
    int n, a=0, b=0, cnt=0;
    cin >> n;
    vector<int> p(n), q(n), perm(n);
    rep(i, n)perm[i] = i+1;
    rep(i, n)cin >> p[i];
    rep(i, n)cin >> q[i];
    
    while(next_permutation(perm.begin(), perm.end())){
        cnt++;
        if(perm == p)a = cnt;
        if(perm == q)b = cnt;
    }
    
    int ans;
    if(a==b){
        ans = 0;
    }else{
        ans = abs(a-b);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3444
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int search(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(){
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for (i = 0;i<n;i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for(i=0;i<q;i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}



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

using namespace std;

const int N = 1e5 + 100;

vector<int> adj[N];
bool use[N], win;
int n;

void dfs(int v, int p) {
	for (auto u : adj[v]) {
		if (u == p)
			continue;
		dfs(u, v);
		if (!use[u]) {
			if (!use[v]) {
				use[u] = true;
				use[v] = true;
			}
			else
				win = true;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		adj[--v].push_back(--u);
		adj[u].push_back(v);	
	}
	dfs(0, 0);
	return cout << ((win || !use[0]) ? "First" : "Second"), 0;
}

Measured memory_bytes: 5888
import scala.util.control.Breaks
object Main extends App {
  val b = new Breaks
  b.breakable {
    while(true) {
      var deck = readLine

      if (deck == "-") b.break

      val m = readLine.toInt

      for (k <- 0 until m) {
        val h = readLine.toInt
        val (head, tail) = deck.splitAt(h)
        deck = tail + head
      }
      println(deck)
    }
  }
}


Measured memory_bytes: 44076
from bisect import bisect_right as br
from itertools import combinations_with_replacement as cwr

MAX = 110000
ROOT = 340
tf = [True] * MAX
tf[0] = tf[1] = False
for i in range(2, ROOT + 1):
  if tf[i]:
    for j in range(i * i, MAX, i):
      tf[j] = False
primes = [i for i in range(MAX) if tf[i]]

while True:
  n, p = map(int ,input().split())
  if n == -1:break
  init = br(primes, n)
  choice = primes[init:init+p]
  lst = []
  for i, j in cwr(choice, 2):
    lst.append(i + j)
  lst.sort()
  print(lst[p - 1])


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

public class Main {
  Scanner sc;

  void run() {
    int m = ni();
    for ( int i = 0; i < m; ++i ) {
      int v = ni();
      int y = ni();
      int n = ni();
      int max = 0;
      for ( int j = 0; j < n; ++j ) {
        int h = ni();
        double r = nd();
        int d = ni();

        int a = v;
        int acc = 0;
        for(int k = 0; k < y; ++k) {
          int b = (int)(a * r);
          if( h == 1 ) {
            a += b;
//            debug("h", a);
          } else {
            acc += b;
//            debug("t", acc);
          }
          a -= d;
        }
        max = Math.max(max, a + acc);
      }

      System.out.println(max);
    }
  }

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  double nd() {
    return sc.nextDouble();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 41904
/*
螺旋本 p371

circumcenter:
    https://ja.wikipedia.org/wiki/%E5%A4%96%E6%8E%A5%E5%86%86#%E5%A4%96%E5%BF%83%E3%81%AE%E4%BD%8D%E7%BD%AE
    https://mathtrain.jp/goshin
*/
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 55
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(){
    while(true){
        int W,H;
        cin>>W>>H;
        if(H==0 && W==0) return 0;
        char C[23][23];
        int sh,sw;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin>>C[i][j];
                if(C[i][j]=='@'){
                    sh=i;sw=j;
                }
            }
        }
        queue<P> que;
        int count=1;
        que.push(P(sh,sw));
        while(!que.empty()){
            P x=que.front(); que.pop();
            for(int i=0;i<4;i++){
                int nh=x.first+dx[i],nw=x.second+dy[i];
                if(nh>=1 && nh<=H && nw>=1 && nw<=W && C[nh][nw]=='.'){
                    count++;
                    C[nh][nw]='#';
                    que.push(P(nh,nw));
                }
            }
        }
        cout<<count<<endl;
    }
}


Measured memory_bytes: 3104
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = sorted(list(map(int, input().split())))
    if N == [1,4,7,9]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 61580
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.println(a + b + c + Math.max(a, Math.max(b, c)) * 9);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL N, LL M, vector<LL> A){
	map<LL, LL> acc_mod;
	acc_mod[0] = 1;
	LL sum = 0;
	REP(i, N) {
		sum += A[i];
		sum %= M;
		acc_mod[sum]++;
	}
	sum = 0;
	for (auto m: acc_mod) {
		sum += m.second * (m.second - 1) / 2;
	}
	cout << sum << endl;
}


int main(){	
	LL M;
	LL N;
	scanf("%lld",&N);
	vector<LL> A(N-1+1);
	scanf("%lld",&M);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, M, A);
	return 0;
}



Measured memory_bytes: 5760
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

// VJUDGE

const int N = 305;
int n, a[4];
double dp[N][N][N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		a[m]++;
	}
	for (int z = 0; z <= a[3]; z++)
		for (int j = 0; j <= a[2] + a[3]; j++)
			for (int i = 0; i <= a[1] + a[2] + a[3]; i++) {
				// dp[i][j][z] => (
				if (!i && !j && !z)
					dp[i][j][z] = 0;
				else {
					dp[i][j][z] += (i ? (dp[i - 1][j][z] + 1) : 0) / n * i;
//					cout << dp[i][j][z] << " ** \n";
					dp[i][j][z] += (j ? (dp[i + 1][j - 1][z] + 1) : 0) / n * j;
//					cout << dp[i][j][z] << "*\n";
					dp[i][j][z] += (z ? (dp[i][j + 1][z - 1] + 1) : 0) / n * z;
//					cout << dp[i][j][z] << "***\n";
					dp[i][j][z] += (double)(n - i - j - z) / n;
//					cout << dp[i][j][z] << " **\n";
					dp[i][j][z] /= (i + j + z);
					dp[i][j][z] *= n;
				}
//				cout << i << "  " << j << "   " << z << " ==> " << dp[i][j][z] << endl;
			}
 	cout<< setprecision(16) << dp[a[1]][a[2]][a[3]] << endl;
}


Measured memory_bytes: 219392
s = gets.chomp
n = s.length
for i in "a" .. "z" do
    if s.include?(i) then
        next
    else
        puts s + i
        exit
    
    end
end

for k in 0 .. 25 do
 for j in s[25-k,1] .. "z" do
     if s[0,25-k+1].include?(j)
         next
     else
         ans = s[0,25-k] + j
         puts ans
         exit
     end
 end
end
puts -1

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

int main()
{
	int S;
	int h, m, s;
	cin >> S;
	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S - h * 3600 - m * 60;
	cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 3096
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
  char a;
  cin >> a;
  if (a <= 'Z')
    cout << "A" << endl;
  else
    cout << "a" << endl;
  return 0;
}


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

int main(){
	int n, q, s, temp;
	int count = 0;
	scanf("%d", &n);

	int *S = new int[n+1];
	for(int i=0; i<n; ++i){
		scanf("%d", &S[i]);
	}

	scanf("%d", &q);
	int *T = new int[q];
	for(int i=0; i<q; ++i){
		scanf("%d", &T[i]);
	}

	// Linear Search
	for(int i=0; i<q; ++i){
		temp = T[i];
		S[n] = temp;
		
		s = 0;
		while(S[s] != temp){
			s += 1;
		}
		if(s != n){
			count += 1;
		}
	}

	printf("%i\n", count);	

	return 0;
}


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

int main(){
   int64_t a, b, c, k;
   cin >> a >> b >> c >> k;
   int64_t ans = 0;
   
   if(a>=k){
      ans = k;
      cout << ans << endl;
   }else{
      k -= a;
      ans += a;
      if(b>=k){
         cout << ans << endl;
      }else{
         k -= b;
         ans -= k;
         cout << ans << endl;
      }

   }
   //cout << ans << endl;
}


Measured memory_bytes: 3636
/**
 * Created by hiramekun at 13:48 on 2020-05-17.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string n;
    ll k;
    cin >> n >> k;
    ll len = n.size();
    ll dp[len + 1][k + 1][2];
    // dp[i][j][k]: i桁目まで決めて、j個の非ゼロを使って、k→0: そこまでの桁はNと一致、k→1: すでにN以下であることが確定
    rep(i, len + 1)
        rep(j, k + 1)
            rep(l, 2) {
                dp[i][j][l] = 0;
            }

    dp[0][0][0] = 1;
    rep(i, len) {
        rep(j, k + 1) {
            rep(l, 2) {
                ll nd = n[i] - '0';
                rep(d, 10) {
                    ll ni = i + 1, nj = j, nl = l;
                    if (d != 0) nj++;
                    if (nj > k) continue;
                    if (l == 0) {
                        if (d > nd) continue;
                        if (d < nd) nl = 1;
                    }
                    dp[ni][nj][nl] += dp[i][j][l];
                }
            }
        }
    }
    cout << dp[len][k][0] + dp[len][k][1] << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void call(int n){
	for(int i=1;i<=n;++i){
		int  x=i;
		if(x%3==0){
			printf(" %d",i);
			x=0;}
		while(x){
			if(x%10==3){
			printf(" %d",i);
			break;}
			x/=10;}}
}
int main(){
    int a;
	scanf("%d",&a);
	call(a);
	printf("\n");
	return 0;
}


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

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

int main() {
    int N; cin >> N;
    map<string, int> A;
    vector<string> S;
    S.push_back("AC");
    S.push_back("WA");
    S.push_back("TLE");
    S.push_back("RE");
    rep(i, 4) A[S[i]] = 0;
    string str;
    rep(i, N) {
        cin >> str;
        A[str]++;
    }
    rep(i, 4) {
        cout << S[i] << " x " << A[S[i]] << endl;
    }
}

Measured memory_bytes: 3596
n=gets.to_i
n.times do
  ary=gets.split(" ").collect do |x|
    x.to_i
  end
  ary.sort!
  if ary[0]**2+ary[1]**2==ary[2]**2 then
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 6108
s = input().strip()
chars = list(set(s))
chars.sort()
dic = {"a": 0,
       "b": 1,
       "c": 2,
       "d": 3,
       "e": 4,
       "f": 5,
       "g": 6,
       "h": 7,
       "i": 8,
       "j": 9,
       "k": 10,
       "l": 11,
       "m": 12,
       "n": 13,
       "o": 14,
       "p": 15,
       "q": 16,
       "r": 17,
       "s": 18,
       "t": 19,
       "u": 20,
       "v": 21,
       "w": 22,
       "x": 23,
       "y": 24,
       "z": 25
       }
swap = {v: k for k, v in dic.items()}
ans = "None"
count = 0
for c in chars:
    if dic[c] != count:
        ans = swap[count]
        break
    count += 1
if count <= 25:
    print(swap[count])
else:
    print(ans)

Measured memory_bytes: 45168
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	int32_t N;
	string S;
	cin >> N >> S;

	vector<int32_t> left_cnt(N, 0), right_cnt(N, 0);
	for (int32_t i = 1; i < N; i++) {
		left_cnt[i] = left_cnt[i - 1];
		if (S[i - 1] == 'W') {
			left_cnt[i]++;
		}
	}
	for (int32_t i = N - 2; i >= 0; i--) {
		right_cnt[i] = right_cnt[i + 1];
		if (S[i + 1] == 'E') {
			right_cnt[i]++;
		}
	}

	int32_t res = N;
	for (int32_t i = 0; i < N; i++)
		res = min(res, left_cnt[i] + right_cnt[i]);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3076