akhauriyash/Code-Regression huggingface dataset:
import sys

H, W, N, *cnt_color = map(int, sys.stdin.read().split())

def main():
    canvas = [[None] * W for _ in range(H)]

    h = w = 0
    for i in range(N):
        c = cnt_color[i]
        i = str(i+1)
        for _ in range(c):
            canvas[h][w] = i
            if h & 1:
                w -= 1
                if w == -1:
                    h += 1
                    w = 0
            else:
                w += 1
                if w == W:
                    h += 1
                    w = W - 1
    
    for i in range(H):
        yield' '.join(canvas[i])

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 3700
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


vector<pair<int,int>> vectorCnt(vector<int> a) {
    sort(a.begin(),a.end());
    int n=a.size();
    vector<pair<int,int>> b;
    int cnt=1;
    rep(i,n-1) {
            if (a[i+1]!=a[i]) {
                b.push_back(make_pair(a[i],cnt));
                cnt=1;
            } else {
                ++cnt;
            }
    }
    b.push_back(make_pair(a[n-1],cnt));
    return b;
}

int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<pair<int,int>> p=vectorCnt(a);
    vector<ll> b={0,0};

    rep(i,p.size()) {
        if (p[i].second>1)  b.push_back(p[i].first);
        if (p[i].second>3) b.push_back(p[i].first); 
    }
    ll ans=b[b.size()-1]*b[b.size()-2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[100],n,i,j,wk,cnt;
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	scanf("%d",&a[i]);
		cnt=0;
		for(i=n-2;i>=0;i--)	{
			for(j=0;j<=i;j++)	{
				if(a[j]>a[j+1])	{
					swap(a[j],a[j+1]);
					cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll L,A,B,mo;
ll F[20];
ll num[20];
ll p10[20];
ll S[20];

ll modpow(ll a, __int128 n) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll hoge(ll len,ll p) {
	if(len==0) return 0;
	if(len==1) return 1;
	ll a=modpow(p,len/2);
	ll v=hoge(len/2,p);
	if(len%2==0) {
		return v*(1+a)%mo;
	}
	else {
		return (v*(1+a)+a*a)%mo;
	}
}
ll hoge2(ll len,ll p) {
	if(len<=0) return 0;
	if(len==1) return 1;
	
	if(len%2==0) {
		ll a=modpow(p,len/2);
		ll v=hoge2(len/2,p);
		return (v*(1+a)+(len/2)%mo*hoge(len/2,p))%mo;
	}
	else {
		return (hoge2(len-1,p)+hoge(len,p))%mo;
	}
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>L>>A>>B>>mo;
	
	p10[0]=1;
	FOR(i,19) p10[i+1]=p10[i]*10;
	
	ll w=L;
	ll v=A;
	for(i=1;i<=19;i++) if(v<p10[i] && w) {
		ll d=min(w,(p10[i]-v+B-1)/B);
		F[i]=v;
		num[i]=d;
		v+=B*d;
		w-=d;
	}
	ll c=1;
	ll ret=0;
	for(i=19;i>=1;i--) if(num[i]) {
		
		ll p=p10[i]%mo;
		ll n=num[i];
		ll a=F[i];
		
		ll r=(F[i]%mo*hoge(n,p)+B%mo*hoge2(n-1,p))%mo;
		ret+=r*c%mo;
		c=c*modpow(10,__int128(i)*num[i])%mo;
		
	}
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[2010];//適宜変える
	int id[1010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n==0)exit(0);
	rep(i,0,m){
		ll x,y,c;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
	}
	g.vcnt=n;
	g.ecnt=2*m;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}



ll a[1010];
int flag;
//dfs
ll dfs(int v){
	rep(i,g.id[v],g.id[v+1]){
		ll nv=g.e[i].g;
		if(!a[nv]){
			a[nv]=a[v]^3;
			dfs(nv);
		}else{
			if(a[v]&a[nv])flag=0;
		}
	}
}

int main(){
	while(1){
		readgraph();
		rep(i,0,1005)a[i]=0;
		a[0]=1;
		flag=1;
		dfs(0);
		if(flag){
			int cnt=0;
			rep(i,0,g.vcnt)if(a[i]==1)cnt++;
			if(cnt%2==0){
				if((g.vcnt-cnt)%2==0){
					if(cnt>g.vcnt/2)cnt=g.vcnt-cnt;
					if(cnt*2==g.vcnt)printf("%d\n%d\n",1,cnt/2);
					else printf("%d\n%d\n%d\n",2,cnt/2,(g.vcnt-cnt)/2);
				}else{
					printf("%d\n%d\n",1,cnt/2);
				}
			}else{
				if((g.vcnt-cnt)%2==0){
					printf("%d\n%d\n",1,(g.vcnt-cnt)/2);
				}else{
					puts("0");
				}
			}
		}else{
			puts("0");
		}
	}
}


Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			while(true){
					String strs[] = br.readLine().split(" ");
					int s = Integer.parseInt(strs[0]);
					int d = Integer.parseInt(strs[1]);
					if(s == 0 && d == 0) return;
					
					// 水が通じてるかどうかフラグ
					
					int d_to_s[][] = new int[d][s];
					for(int i = 0; i < s; i++){
						strs = br.readLine().split(" ");
						for(int j = 0; j < d; j++){
							d_to_s[j][i] = Integer.parseInt(strs[j]);
						}
					}

					int d_to_d[][] = new int[d][d];
					for(int i = 0; i < d-1; i++){
						strs = br.readLine().split(" ");
						for(int j = 0; j < strs.length; j++){
							d_to_d[i][i + j + 1] = Integer.parseInt(strs[j]);
							d_to_d[i + j + 1][i] = Integer.parseInt(strs[j]);
						}
					}
					solve(s, d, d_to_s, d_to_d);
			}
		} catch (IOException e) {
				e.printStackTrace();
		}
	}
	
	public static void solve(int s, int d, int d_to_s[][], int d_to_d[][]){
		boolean pipeline_flag[] = new boolean[d];
		
		int before_min = 101;
		int before_min_d = -1;
		for(int i = 0; i < d; i++){
			if(pipeline_flag[i]) continue;
			for(int j = 0; j < s; j++){
				if(d_to_s[i][j] == 0) continue; // 接続されてない場合
				// 最小値を更新した場合
				if(before_min > d_to_s[i][j]){
					before_min = d_to_s[i][j];
					before_min_d = i;
				}
			}
		}
		int sum = before_min;
		pipeline_flag[before_min_d] = true;
		if(flagCheckAnd(pipeline_flag)){
			System.out.println(sum);
			return;
		}
		
		while(true){
			int min_d = -1;
			int min = 101;
			for(int i = 0; i < d; i++){
				if(pipeline_flag[i]) continue;
				for(int j = 0; j < s; j++){
					if(d_to_s[i][j] == 0) continue; // 接続されてない場合
					// 最小値を更新した場合
					if(min > d_to_s[i][j]){
						min = d_to_s[i][j];
						min_d = i;
					}
				}
				for(int j = 0; j < d; j++){
					if(d_to_d[i][j] == 0) continue; // 接続されてない場合
					// 最小値を更新した場合
					if(pipeline_flag[j] && min > d_to_d[i][j]){
						min = d_to_d[i][j];
						min_d = i;
					}
				}
			}
			sum += min;
			pipeline_flag[min_d] = true;
			if(flagCheckAnd(pipeline_flag)){
				System.out.println(sum);
				return;
			}
		}
	}
	
	public static boolean flagCheckAnd(boolean flags[]){
		for(int i = 0; i < flags.length; i++){
			if(!flags[i]) return false;
		}
		return true;
	}
}

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

int main()
{
    double x, h;

    while( cin >> x >> h )
    {
        if( x == 0 && h == 0 )
            break;
        
        //側面積=0.5*x*t, t = root(h^2+0.25x^2), 余弦
        double s = 0;
        s = 2 * x * sqrt( h * h + 0.25 * x * x ) + x * x;

        cout << fixed << setprecision(8) << s << endl;
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
#define MAXN 1123456
#define INF LLONG_MAX
#define MOD 32416187567

int v[112];
int n;
int tenta(int x){
    int resp=0;
    for(int i=0;i<n;i++)resp+=(x-v[i])*(x-v[i]);
    return resp;
}

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

    cin>>n;
    int resp=INF;
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=-100;i<=100;i++)resp=min(resp,tenta(i));
    cout<<resp<<endl;

    return 0;
}





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

int main () {
  int a,b,c;
  cin >> a >> b >> c;

  cout << min({abs(a-b)+abs(c-a),abs(a-c)+abs(b-a),
    abs(b-a)+abs(c-b),abs(b-c)+abs(a-b),
    abs(c-a)+abs(b-c),abs(c-b)+abs(a-c)}) << endl;

  return 0;
}


Measured memory_bytes: 256
/**
 * @Author: harshkhajuria
 * @Date:   09-May-2020 05:39:30 pm
 * @Email:  khajuriaharsh729@gmail.com
 * @Filename: C - Peaks.cpp
 * @Last modified by:   harshkhajuria
 * @Last modified time: 09-May-2020 06:00:54 pm
 */
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(),v.end()
using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
		out << '(' << p.ff << ", " << p.ss << ')';
		return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
		int l = v.size();
		for (int i = 0; i < l - 1; i++)
				out << v[i] << ' ';
		if (l > 0)
				out << v[l - 1];
		return out;
}

template <typename T> void trace(const char* name, T&& arg1) {
		cout << name << " : " << arg1 << endl;
}

template <typename T, typename ... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
		const char* comma = strchr(names + 1, ',');
		cout.write(names, comma - names) << " : " << arg1 << " | ";
		trace(comma + 1, args ...);
}

/*Input*/
ll n,k;
const ll vecSize = 1e6;
vector<ll> v(vecSize), heights(vecSize);
/*Input*/



int main()
{
		//ios::sync_with_stdio(false);
		//cin.tie(0);
		//cout.tie(0);
		clock_t tStart = clock();
		int test;
		test = 1;
		// cin >> test;
		while (test--) {
				cin >> n >> k;
				for(int i=0; i<n; i++) {
						ll temp;  cin >> temp;
						v[i] = temp;
						heights[i] = -1;
				}
				for(int i=0; i<k; i++) {
						ll a,b;
						cin >> a >> b;
						a--; b--;
						heights[a] = max(heights[a], v[b]);
						heights[b] = max(v[a], heights[b]);
				}
				ll ans = 0;
				for(int i=0; i<n; i++) {
						if(heights[i] < v[i] || heights[i]==-1) ans++;
				}
				cout << ans << endl;
		}
#ifdef LOCAL_DEFINE
		printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
		return 0;
}


Measured memory_bytes: 18648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  vb check(10);
  vvb checkback(N,vb(10)),checkfront(N,vb(10));
  rep(i,N) {
    rep(j,10) {
      if(check[j]) checkback[i][j]=true;
    }
    check[S[i]-'0']=true;
  }
  reverse(S.begin(),S.end());
  check=vb(10);
  rep(i,N) {
    rep(j,10) {
      if(check[j]) checkfront[N-i-1][j]=true;
    }
    check[S[i]-'0']=true;
  }
  vector<vvb> count(10,vvb(10,vb(10)));
  reverse(S.begin(),S.end());
  rep(i,N) {
    rep(l,10) {
      rep(r,10) {
        if(checkback[i][l]&&checkfront[i][r]) count[S[i]-'0'][l][r]=true;
      }
    }
  }
  int ans=0;
  rep(i,10) {
    rep(j,10) {
      rep(k,10) {
        if(count[i][j][k]) ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 7456
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

const INF=2<<32
function main()
    n::Int=parseInt(readline())
    data=[parseMap(split(readline())) for i in 1:n]
    dp::Array{Int,2}=zeros(Int,n,3)
    dp[1,:]=data[1]
    for i in 2:n
        for j in 1:3
            for k in 1:3
                if j==k
                    continue
                end
                dp[i,j]=max(dp[i,j],dp[i-1,k]+data[i][j])
            end
        end
    end
    println(maximum(dp[n,:]))
end
main()

Measured memory_bytes: 215336
while True:
    try:
        xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = map(float, input().split())
        if (xa1 <= xb2 and xb1 <= xa2) and (ya1 <= yb2 and yb1 <= ya2):
            print("YES")
        else:
            print("NO")
    except:
        break



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

int main(){
  string s;
  cin >> s;
  bool ac=false;
  if(s.at(0)==65){
    ac=true;
    bool Cdeta=false;
    for(int i=1;i<s.size();i++){
      if(s.at(i)<97){
        if(i>1&&i<s.size()-1&&s.at(i)==67&&!Cdeta){
          Cdeta=true;
        }else{
          ac=false;
        }
      }
    }
    ac=ac&Cdeta;
  }
  cout << (ac?"AC":"WA") << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;
 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
 
String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/
 
bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}
 
 
void solve()
{
    double a, b, h, m; cin >> a >> b >> h >> m;
    h = h*30 + m*0.5;
    m = m*6;
    double pi = 3.1415926535; 
    double angle = abs(h-m);
    angle = min(angle, 360-angle);
    //nout(2*a*b*cos(angle*pi/180));
    double ans =sqrt((a*a)+(b*b)-(2*a*b*cos(angle*pi/180)));
    cout << fixed << setprecision(15) << ans << endl;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4248
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,20001){
	bool flg=true;
	for(int j=2;j*j<=i;j++){
	    if(i % j == 0){
		flg = false;
		break;
	    }
	}
	if(flg){
	    primes.PB(i);
	}
    }
    while(true){
	int n;
	cin >> n;
	if(n == 0) break;
	int x = upper_bound(ALL(primes),n) - primes.begin();
	RREP(i,x){
	    if(primes[i]-primes[i-1]==2){
		cout << primes[i-1] << " " << primes[i]<<endl;
		break;
	    }
	}
    }


    return 0;
}

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

int main() {
  long long n, a, b, c, d, e, bottle;
  cin >> n >> a >> b >> c >> d >> e;

  bottle = min(min(a, b), min(min(c, d), e));

  if (n % bottle == 0)
    cout << n / bottle + 4 << endl;
  else
    cout << n / bottle + 5 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}




int main(void){
  int n;
  scanf("%d",&n);
  int g=0;
  int f=10000;
  int i;
  for(i=0;i<n;i++){
      int a;
      scanf("%d",&a);
      if(a<f){
          f=a;
      }
      if(g<a){
          g=a;
      }
  }

  printf("%d\n",g-f);

  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

vector<long long> fact_inv, inv, Com;

void init_nCk(int n, int SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    Com.resize(SIZE + 5);
    Com[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
    }
}
 
long long nCk(int k) {
    assert(!(k < 0));
    return Com[k];
}

int main()
{
  int N,K;
  cin >> N >> K;

  FOR(i,1,K+1){
    mint ans = 1;
    if(i>N-K+1){
      cout << 0 << endl;
    }else{
      init_nCk(K-1,i-1);
      ans*=nCk(i-1);
      init_nCk(N-K+1,i);
      ans*=nCk(i);
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 3684
def main():
  N, K = [int(i) for i in input().split()]
  R, S, P = [int(i) for i in input().split()]
  T = input()
  point = {"r":P, "s":R, "p":S}
  ans = 0
  
  for i in range(K):
    last = ''
    j = i
    while j<N:
      aite = T[j]
      if aite!=last:
        ans = ans+point[aite]
        last = aite
      else:
        last = ''
      j = j+K
   
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 3316
#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<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    if (n % 2 == 1)
    {
        a.push_back(0);
    }
    sort(a.begin(), a.end());
    int num;
    if (n % 2 == 0)
    {
        num = 1;
    }
    else
    {
        num = 0;
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] != num)
        {
            cout << 0 << endl;
            return 0;
        }
        if (i % 2 == 1)
        {
            num += 2;
        }
    }
    ll ans = 1;
    for (int i = 0; i < n / 2; i++)
    {
        ans = (ans * 2ll) % MOD;
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(is,1<<h)rep(js,1<<w){
    int cnt = 0;
    rep(i,h)rep(j,w){
      if (is>>i&1) continue;
      if (js>>j&1) continue;
      if (s[i][j] == '#') cnt++;
    }
    if (cnt == k) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int long long

int n,d;

signed main(){
  cin >> n >> d;
  int ans=n%(2*d+1);
  if(ans==0) cout << n/(2*d+1) << endl;
  else  cout << n/(2*d+1)+1 << endl;
  return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N;

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

	cin >> N;
	multiset<int> S;
	int diameter = 0;
	FOR(i,0,N){
		int a;
		cin >> a;
		S.insert(a);
		chmax(diameter,a);
	}

	if(diameter > N - 1){
		cout << "Impossible" << endl;
		return 0;
	}
	for(int i = 0;i <= diameter / 2;i++){
		if(diameter % 2 == 0 && i == diameter / 2){
			if(S.count(diameter - i) != 1){
				cout << "Impossible" << endl;
				return 0;
			}
			S.erase(diameter - i);
		}
		else if(diameter % 2 && i == diameter / 2){
			if(S.count(diameter - i) != 2){
				cout << "Impossible" << endl;
				return 0;
			}
			S.erase(diameter - i);
		}
		else{
			if(S.count(diameter - i) < 2){
				cout << "Impossible" << endl;
				return 0;
			}
			S.erase(diameter - i);
		}
	}

	if(S.empty()){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d=0;
    cin>>a>>b>>c>>d;
    int dis=abs(c-a);
    int dis1=abs(b-a);
    int dis2=abs(c-b);
    if(dis<=d){
        cout<<"Yes";
    }
    else if(dis>d&&dis1<=d&&dis2<=d){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int m = scanner.nextInt();
			int p = scanner.nextInt() - 1;
			int q = scanner.nextInt();
			int r = scanner.nextInt();
			Deque<Point> deque = new ArrayDeque<Main.Point>();
			deque.push(new Point(1, n));
			while (m-- > 0) {
				int x = scanner.nextInt();
				int y = scanner.nextInt();
				Deque<Point> tmp = new ArrayDeque<Point>();
				int ny = n - y;
				while (ny != 0) {
					Point point = deque.peekLast();
					if (point.len <= ny) {
						tmp.push(deque.pollLast());
						ny -= point.len;
					} else {
						tmp.push(new Point(point.len - ny + point.start, ny));
						deque.peekLast().len -= ny;
						break;
					}
				}
				int nx = y - x;
				while (nx != 0) {
					Point point = deque.peekLast();
					if (point.len <= nx) {
						deque.push(deque.pollLast());
						nx -= point.len;
					} else {
						deque.push(new Point(point.len - nx + point.start, nx));
						deque.peekLast().len -= nx;
						break;
					}
				}
				tmp.addAll(deque);
				deque = tmp;

			}
			int ny = n - q;
			while (ny != 0) {
				Point point = deque.peekLast();
				if (point.len <= ny) {
					deque.pollLast();
					ny -= point.len;
				} else {
					deque.peekLast().len -= ny;
					break;
				}
			}
			while (p != 0) {
				Point point = deque.peek();
				if (point.len <= p) {
					deque.poll();
					p -= point.len;
				} else {
					deque.peek().start += p;
					deque.peek().len -= p;
					break;
				}
			}
			int ans = 0;
			while (!deque.isEmpty()) {
				Point point = deque.poll();
				ans += Math.max(0, Math.min(r - point.start + 1, point.len));
			}
			System.out.println(ans);
		}
	}

	class Point {
		int start, len;

		public Point(int start, int len) {
			super();
			this.start = start;
			this.len = len;
		}

		@Override
		public String toString() {
			return "Point [start=" + start + ", len=" + len + "]";
		}

	}
}

Measured memory_bytes: 235720
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)
#define looplleq(i, n) for (ll i = 0; i <= (ll)n; i++)

int main() {
    int h1, h2, m1, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int time1 = h1 * 60 + m1;
    int time2 = h2 * 60 + m2;
    cout << time2 - time1 - k << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

int x,a;
cin>>x>>a;
//if(x==a) cout<<10<<endl;
if(x<a){
    cout<<0<<endl;
}else{
    cout<<10<<endl;
}
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

template<class Abel>
struct WeightedUnionFind {
  vector<int> uni;
  vector<Abel> dw;

  explicit WeightedUnionFind(int n, const Abel &UNIT = 0)
    : uni(n+5, -1), dw(n+5, UNIT) {}

  int   size(int x)       { return -uni[root(x)]; }
  Abel  weight(int x)     { root(x); return dw[x]; }
  bool  same(int x, int y){ return root(x) == root(y); }
  Abel  diff(int x, int y){ return weight(y) - weight(x); }

  int root(int x) {
    if (uni[x] < 0) return x;
    const int rt = root(uni[x]);
    dw[x] += dw[uni[x]];
    return uni[x] = rt;
  }

  bool unite(int x, int y, Abel w) {
    w += weight(x) - weight(y);
    x = root(x); y = root(y);
    if (x == y) return false;
    if (uni[y] < uni[x]) swap(x,y), w = -w;
    uni[x] += uni[y]; uni[y] = x; dw[y] = w;
    return true;
  }
};

signed main()
{
  iostreamBooster();
  int n, q;
  cin >> n >> q;
  WeightedUnionFind<i64> wuf(n);

  while(q--) {
    int com, x, y, z;

    cin >> com;
    if (com == 0) {
      cin >> x >> y >> z;
      wuf.unite(x, y, z);
    } else {
      cin >> x >> y;
      if (wuf.same(x, y))
        cout << wuf.diff(x, y) << LF;
      else {
        cout << '?' << LF;
      }
    }
  }
  return 0;
}




Measured memory_bytes: 4120
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	long long int n;
	int tmp[10];
	vector<int> r;
	while(cin >> n)
	{
		for (int i=0; i<10; i++)
		{
			tmp[i] = n%10;
			n/=10;
		}
		for (int i=0; i<9; i++)
		{
			for (int j=0; j<9-i; j++)
			{
				tmp[j] = (tmp[j] + tmp[j+1]) % 10;
			}
		}
		r.push_back(tmp[0]);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
	int n,ans=1,ok=0;
	scanf("%d",&n);
	int h[n];
	for(int i=0;i<n;i++)scanf("%d",&h[i]);
	for(int i=1;i<n;i++){
		ok=0;
		for(int j=0;j<i;j++){
			if(h[j]>h[i]){
				ok=0;
				break;
			}else{
				ok=1;
			}
		}
		if(ok)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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 pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N_MAX = 100010;
VI con_hash[N_MAX];
int cost1[N_MAX] = {};
int costn[N_MAX] = {};
bool reached1[N_MAX] = {};
bool reachedn[N_MAX] = {};


void dfs1(int v){
    reached1[v] = true;
    for(auto &adj : con_hash[v]){
        if(reached1[adj] == true) continue;
        cost1[adj] = cost1[v] + 1;
        dfs1(adj);
    }
}

void dfsn(int v){
    reachedn[v] = true;
    for(auto &adj : con_hash[v]){
        if(reachedn[adj] == true) continue;
        costn[adj] = costn[v] + 1;
        dfsn(adj);
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i, n - 1){
        int a, b;
        cin >> a >> b;
        con_hash[a].push_back(b);
        con_hash[b].push_back(a);
    }
    dfs1(1);
    dfsn(n);
    int b_cnt = 0;
    FOR(i, 1, n){
        if(cost1[i] <= costn[i]) b_cnt++;
    }
    int w_cnt = n - b_cnt;
    if(b_cnt > w_cnt){
        cout << "Fennec" << "\n";
    }else{
        cout << "Snuke" << "\n";
    }

    return 0;
}


Measured memory_bytes: 9856
#include <cstring>
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
int main(){
long long counter1,counter2;
counter1=0;
counter2=0;
long long counter3=0;
long long N;
cin>>N;
vector<long long>a(N);
vector<long long>b(N+1);
vector<long long>c(N+1);
vector<long long>d(N);
b.at(0)=0;c.at(N-1)=0;
for (int i=0;i<N;i++){
cin>>a.at(i);}
for (int i=0;i<N;i++){
b.at(i+1)=__gcd(b.at(i),a.at(i));}
for (int i=N-1;i>=0;i--){
c.at(i)=__gcd(c.at(i+1),a.at(i));}

for (int i=0;i<N;i++){
counter1=max(__gcd(b.at(i),c.at(i+1)),counter1);}
cout<<counter1<<endl;}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n; cin >> n;
    unordered_set<int> st;
    bool ok = true;
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        if(st.count(x)) {
            ok = false;
            break;
        }
        st.insert(x);
    }

    cout << (ok ? "YES" : "NO") << endl;
}

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

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

    ll a,b;
    cin>>a>>b;
    cout<<a/b<<" "<<a%b<<" "<<(double)a/b<<endl;
    return 0;
}


Measured memory_bytes: 3264
#include<stdio.h>
int main(void)
{
    int w,h,x,y,r,a;
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
    a=0;
    if(x-r<0){
        a+=1;
    }
    if(y-r<0){
        a+=1;
    }
    if(y+r>h){
        a+=1;
    }
    if(x+r>w){
        a+=1;
    }
    if(a==0){
        printf("Yes\n");
    }
    if(a>0){
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int A[2][100];
	int i,j;
	for (i=0;i<2;i++){
		for (j=0;j<N;j++){
			cin>>A[i][j];
		}
	}
	int aw=A[0][0];
	int maxAw=0;
	for (j=0;j<N;j++){
		aw+=A[1][j];
	}
	maxAw=aw;
	aw=A[0][0];
	for (i=1;i<N;i++){
		aw+=A[0][i];
		int x=0;
		for (j=i;j<N;j++){
			x+=A[1][j];
		}
		if (maxAw<aw+x){
			maxAw=aw+x;
		}
	}
	cout<<maxAw<<endl;
	return 0;
}

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

int main() {
	int N;
    int A,B,C,D;
    cin >> N ;
    A = N / 1000;
    N = N % 1000;
    B = N / 100;
    N = N % 100;
    C = N / 10;
    D = N % 10;
    if (A == B){
      if (B == C){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else if (B == C){
      if (C == D){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
       cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-20 14:17:08
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

class UnionFind {
 public:
  UnionFind(int n) : n_(n) { Initialize(); }

  int root(int x) {
    if (parent_[x] == -1)
      return x;
    else
      return parent_[x] = root(parent_[x]);
  }

  bool same(int x, int y) { return root(x) == root(y); }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank_[x] < rank_[y]) std::swap(x, y);
    if (rank_[x] == rank_[y]) ++rank_[x];
    parent_[y] = x;
    return;
  }

 private:
  const int n_;
  std::vector<int> parent_;
  std::vector<int> rank_;

  void Initialize() {
    parent_.assign(n_, -1);
    rank_.assign(n_, 0);
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vector<int> p(n); cin >> p;
  for_each(all(p), [](int& x){ --x; });

  UnionFind uf(n);

  for (int i = 0; i < m; ++i) {
    int x, y; cin >> x >> y;
    --x; --y;
    uf.unite(x, y);
  }

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    ans += uf.same(i, p[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;

void BFS(Graph G, vector<int> &Color) {
    queue<pair<int, int>> que;
    que.push(make_pair(1, 0));
    map<int, int> mp;
    ++mp[1];

    while (!que.empty()) {
        int ver = que.front().first;
        int color = que.front().second;
        //int distance = get<2>(que.front());
        que.pop();
        Color[ver - 1] = color;
        rep(i, G[ver - 1].size()) {
            if (mp[G[ver - 1][i].to] == 0) {
                ++mp[G[ver - 1][i].to];
                int distance = G[ver - 1][i].weight;
                if (distance % 2 == 0)que.push(make_pair(G[ver - 1][i].to, color));
                else que.push(make_pair(G[ver - 1][i].to, (color == 0 ? 1 : 0)));
            }
        }
    }

}

int main() {
	int N; cin >> N;
    Graph G(N);
    vector<int> Color(N, -1);
    rep(i, N - 1) {
        int u, v, w; cin >> u >> v >> w;
        G[u - 1].push_back(Edge(v, w));
        G[v - 1].push_back(Edge(u, w));
    }

    BFS(G, Color);
    rep(i, N)cout << Color[i] << endl;
}

Measured memory_bytes: 16896
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
s=["".join(sorted(stdin.readline().rstrip())) for _ in range(n)]
t=Counter(s).values()
ans=0
for i in t:
    ans+=sum(range(1,i))
print(ans)

Measured memory_bytes: 64220
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int NIL = -2000000050;
struct Node { int key, l = NIL, r = NIL; };
vector<Node> T(5e5);
inline void insert(int z) {
	if(z == 0) return;
	int y = NIL;
	int x = 0;
	while(x != NIL) {
		y = x;
		x = (T[z].key < T[x].key ? T[x].l : T[x].r);
	}
	if(y == NIL) (T[0].key < T[y].key ? T[y].l : T[y].r) = z;
	else (T[z].key < T[y].key ? T[y].l : T[y].r) = z;
}
inline void inorder(int x) {
	if(x == NIL) return;
	inorder(T[x].l);
	cout << ' ' << T[x].key;
	inorder(T[x].r);
}
inline void preorder(int x) {
	if(x == NIL) return;
	cout << ' ' << T[x].key;
	preorder(T[x].l);
	preorder(T[x].r);
}
int main() {
	int n; cin >> n;
	string s;
	int x;
	rep(i, 0, n) {
		cin >> s;
		if(s == "insert") {
			cin >> x;
			T[i].key = x;
			insert(i);
		} else {
			inorder(0);
			P("");
			preorder(0);
			P("");
		}
	}
	return 0;
}

Measured memory_bytes: 8468
def abc170_c_2():
    """
    もっとシンプルに考えると
    Xから-1、+1と順番に探索して、見つかったものをリターンすればOKなはず。
    ±0～99までを調べる？
    """
    def solve():
        x, n = map(int, input().split(' '))
        if n == 0:
            return x

        p = list(map(int, input().split(' ')))

        for i in range(100):
            for s in [-1, +1]:
                a = x + i * s
                if a not in p:
                    return a
    print(solve())

if __name__ == '__main__':
    abc170_c_2()

Measured memory_bytes: 9196
#include <algorithm>
#include <cstdio>

bool graph[4][4];

int main()
{
  for (int i = 0, a, b; i < 3; ++ i) {
    scanf("%d%d", &a, &b);
    a --;
    b --;
    graph[a][b] = graph[b][a] = true;
  }
  bool found = false;
  int p[] = {0, 1, 2, 3};
  do {
    bool valid = true;
    for (int i = 1; i < 4; ++ i) {
      valid &= graph[p[i - 1]][p[i]];
    }
    found |= valid;
  } while (std::next_permutation(p, p + 4));
  puts(found ? "YES" : "NO");
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r) { return l.second < r.second; }
bool greaterPair(const ipair& l, const ipair& r) { return l.second > r.second; }

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int i = n; i >= 0; i--)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}

bool pal(string s) {
	int n = s.length() / 2;
			rep(i, n) {
			if (s[i] != s[s.length() - 1 - i]) return false;
		}
			return true;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	};
	std::vector<ipair> ans;
	for (unsigned int i = 0; i < a.size(); i++) {
		ans.push_back(ipair(i, a[i]));
	};
	partial_sort(ans.begin(), ans.end(), ans.end(), lessPair);
	for (vector<ipair>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << it->first + 1<< " " ;
	}

	return 0;
}




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

int main() {
    int n,m;
    long long ans = 0;
    cin >> n >> m;
    vector<int>a(m),dis(m - 1);
    
    if(n < m){
        for(int i = 0;i < m;i++){
        cin >> a[i];
        }
        sort(a.begin(),a.end());
        for(int i = 1;i < m;i++){
            dis[i - 1] = a[i] - a[i - 1];
            ans += dis[i - 1];
        }
        sort(dis.begin(),dis.end(),greater<int>());
        for(int i = 0;i < n - 1;i++){
            ans -= dis[i];
        }
    }
    
    cout << ans << endl;
 }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    auto sign = [](int x){
        if (x == 0) return 0;
        else if (x > 0) return 1;
        else return -1;};
    
    ll pos = 0, neg = 0;
    REP(i,2) {
        int now = 0;
        int prevsign = (i == 0) ? -1 : 1;
        ll count = 0;

        REP(j,n) {
            now += v[j];
            int s = sign(now);
            //cerr << i << " " << j << " " << now << " " << s;
            if (prevsign == s || s == 0) {
                count += abs(now) + 1;
                if (prevsign == 1) {
                    now = -1;
                } else {
                    now = 1;
                }
            }
            prevsign = sign(now);
            //cerr << " " << count << endl;
        }
        if (i == 0) pos = count;
        else neg = count;
    }

    cout << min(pos,neg) << endl;
    

    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
using namespace std;

int n, x, y;
vector<int> g[100100];

int Dfs(int x, int fa) {
	int ans = 0;
	for(int i = 0; i < (int)g[x].size(); i++) {
		int v = g[x][i];
		if(v == fa) continue;
		ans ^= (Dfs(v, x) + 1);
	}
//	printf("%d : %d\n", x, ans ^ c1);
	return ans;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	Dfs(1, 0) ? puts("Alice") : puts("Bob");
}

Measured memory_bytes: 10368
N, M = map(int, input().split())
kaidan = [True] * (N+3)
for i in range(M):
    kaidan[int(input())] = False

dp = [0]*(N+3)
dp[0] = 1
for i in range(N):
    if kaidan[i+2]:
        dp[i+2] += dp[i]
        dp[i+2] %= 1000000007
    if kaidan[i+1]:
        dp[i+1] += dp[i]
        dp[i+1] %= 1000000007

print(dp[N])


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

typedef long long ll;
using namespace std;

ll n, x;
ll a[500000];

signed main()
{
    cin >> n >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans1 = 0, ans2 = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] + a[i - 1] > x)
        {
            ans1 += a[i] + a[i - 1] - x;
            a[i] = x - a[i - 1];
            if (a[i] < 0)
            {
                a[i - 1] += a[i];
                a[i] = 0;
            }
        }
    }
    cout << ans1;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int r; cin>>r;
	cout<<3*r*r;
}


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

using namespace std;
int main() {
  int pos[22];
  memset(pos, 0xff, sizeof(pos));

  int n;
  cin >> n;
  long long ans = 0;
  int right = -1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int p = 0; p < 21; p++)
      if (a & (1 << p)) {
        right = max(right, pos[p]);
        pos[p] = i;
      }
    ans += i - right;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

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


using namespace std;

ll maxx[105][100005];
pair<ll,ll>p[105];

int main(){
	int in,n;
	ll a,b;
	cin>>in>>n;
	rep(i,in,1){
		cin>>a>>b;
		p[i]=mp(a,b);
	}
	sort(p+1,p+in+1);
	rep(i,in,1){
		rep(j,n,1){
			if(j<p[i].fi){
				maxx[i][j]=maxx[i-1][j];
			}
			else{
				maxx[i][j]=max(maxx[i-1][j],maxx[i-1][j-p[i].fi]+p[i].sec);
			}
		}
	}
	cout<<maxx[in][n]<<endl;
	return 0;
}


Measured memory_bytes: 79360