akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long n,x,y,dem=0,dp[200005][2],check[200005];
long long mod=1e9+7;
vector<long> adj[200005];
void dfs(int i){
	if(check[i]==1){
		return;
	}
	check[i]=1;
	for(int j=0;j<adj[i].size();j++){
		if(check[adj[i][j]]==0){
			dfs(adj[i][j]);
			dp[i][1]=((dp[i][1]%mod)*(dp[adj[i][j]][0]%mod))%mod;
		    dp[i][0]=((dp[i][0]%mod)*((dp[adj[i][j]][1]%mod+dp[adj[i][j]][0]%mod)%mod))%mod;
		}
	}
}
int main(){
	cin>>n;
	memset(check,0,sizeof check);
	for(int i=1;i<=n;i++){
		dp[i][0]=1;
		dp[i][1]=1;
	}
	for(int i=1;i<n;i++){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1);
	cout<<(dp[1][0]+dp[1][1])%mod;
}

Measured memory_bytes: 15744
#include<cstdio>
#include<algorithm>
#include<list>

using namespace std;

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


/*
list<from,n,len>

*/

struct DATA {
	int f;
	int n;
	int l;
};
list<DATA> L;


int main(){
	
	int N;
	char q[2];
	int n,i,j;
	int I,S,P;
	int b;
	bool f;
	int nf,nl;
	
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		
		L.clear();
		
		
		rep(n,N){
			scanf("%s",q);
			if(q[0]=='W'){
				scanf("%d %d",&I,&S);
				P=0;
				for(auto it=L.begin();it!=L.end();it++){
					if((*it).n==-1){
						if((*it).l>S){
							(*it).n=I;
							nf=(*it).f+S;
							nl=(*it).l-S;
							(*it).l=S;S=0;
							it++;
							L.insert(it,DATA({nf,-1,nl}));
							
							break;
						}else if((*it).l==S){
							(*it).n=I;S=0;break;
						}else{
							(*it).n=I;
							S-=(*it).l;
						}
					}					
					P=(*it).f+(*it).l;
					if(S<=0)break;
				}
				if(S>0){
					L.insert(L.end(),DATA({P,I,S}));
				}
				
			}else if(q[0]=='D'){
				scanf("%d",&I);
				for(auto it=L.begin();it!=L.end();it++){
					if((*it).n==I){
						(*it).n=-1;
					}
				}
			
			}else if(q[0]=='R'){
				scanf("%d",&P);
				f=true;
				for(auto it=L.begin();it!=L.end();it++){
					if(((*it).f<=P)&&(P<((*it).f+(*it).l))){

						printf("%d\n",(*it).n);
						f=false;
					}
				}
				
				if(f){
					puts("-1");
				}
			
			
			
			}else{
				puts("Ereer!!!!");return -1;
			}
			/*
			for(auto it=L.begin();it!=L.end();it++){
				printf("#    %2d %2d %2d\n",(*it).f,(*it).n,(*it).l);
			}
			*/
			
		}
		puts("");
	
	}
}

Measured memory_bytes: 1244
#include<cstdio>
#define maxn 2005
#define mod 1000000007
int n,m,k,ans,dp[maxn*2][maxn*2],pre[maxn*2][maxn*2];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	dp[0][0]=1;
	for(int i=1;i<n+m;i++)
		for(int j=0;j<=m;j++)
		{
			pre[i][j]=(dp[i-1][j]+(j?pre[i][j-1]:0))%mod;
			dp[i][j]=(pre[i][j]-(j>=k?pre[i][j-k]:0)+mod)%mod;
		}
	for(;m>0;m-=k-1) ans=(ans+dp[(n+m-1)/(k-1)][m])%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 124928
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7

dp = [[0] * (M + 1) for i in range(N + 1)]
dp_sum = [[0] * (M + 1) for i in range(N + 1)]

for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        if s == t:
            dp[i][j] = (dp_sum[i - 1][j - 1] + 1) % MOD
        dp_sum[i][j] = dp_sum[i - 1][j] + dp_sum[i][j - 1] - dp_sum[i - 1][j - 1] + dp[i][j]
        dp_sum[i][j] %= MOD

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD

print((ans + 1) % MOD)


Measured memory_bytes: 105564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); ++i)
#define rng(i,a,b) for(int i = (a); i < int(b); ++i)
using ll = long long;
using mycomplex = complex<double>;

class FastFourierTransform {
private:
    static void dft(vector<mycomplex>& func, int inverse) {
        int sz = func.size();
        if (sz == 1)return;
        vector<mycomplex> veca, vecb;
        rep(i, sz / 2) {
            veca.push_back(func[2 * i]);
            vecb.push_back(func[2 * i + 1]);
        }
        dft(veca, inverse); dft(vecb, inverse);
        mycomplex now = 1, zeta = polar(1.0, inverse * 2.0 * acos(-1) / sz);
        rep(i, sz) {
            func[i] = veca[i % (sz / 2)] + now * vecb[i % (sz / 2)];
            now *= zeta;
        }
    }
public:
    template<typename T>
    static vector<double> multiply(vector<T> f, vector<T> g) {
        vector<mycomplex> nf, ng;
        int sz = 1;
        while (sz < int(f.size() + g.size()))sz *= 2;
        nf.resize(sz); ng.resize(sz);
        rep(i, f.size()) {
            nf[i] = f[i];
            ng[i] = g[i];
        }
        dft(nf, 1);
        dft(ng, 1);
        rep(i, sz)nf[i] *= ng[i];
        dft(nf, -1);
        vector<double> res;
        rep(i, sz)res.push_back(nf[i].real() / sz);
        return res;
    }
};

int main(){
    ll n, m;
    cin >> n >> m;
    vector<int> a(200200,0),b(200200,0);
    rep(i,n) {
        int v; cin >> v;
        a[v] += 1; b[v] += 1;
    }
    vector<double> c = FastFourierTransform::multiply(a, b);
    ll ans = 0, ind = 200000;
    while (m > 0) {
        ll num = min(m, (ll)(c[ind]+0.5));
        ans += ind * num;
        m -= num;
        ind--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 38236
#include<stdio.h>
#include<stdlib.h>
#include <math.h>

long long x[10],y[10];

float kyori(long long i,long long j){
  return pow(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2),0.5);
}

int main(){
  long long n,i,j,fact=1;
  float sum=0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&x[i],&y[i]);
  }
  // printf("%f",kyori(0,1));
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      sum+=kyori(i,j);
    }
  }
  printf("%f",sum*2/n);
  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<long> h(n,0);
    for(auto&& a: h)cin >> a;
    sort(h.begin(), h.end());
    long ans = 0;
    for(int i = 0; i < n - k; i++)ans += h.at(i);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll a,b;
    cin>>a>>b;

    //数列{0,1...B-1,B}のXORの和は
    //Bi,1,Bi+1,0 ... の繰り返しになる
    if(b==0){
        cout << "0" << endl;
        return 0;
    }
    const int keta = 12;
    ll xorsumA=0, xorsumB=0;

    int m = (a==0) ? 0 : a%4;
    switch(m){
        case 0:
            xorsumA = a;
            break;
        case 1:
            xorsumA = 1;
            break;
        case 2:
            xorsumA = a+1;
            break;
        case 3:
            xorsumA = 0;
            break;

    }

    m = (b==0) ? 0 : b%4;
    switch(m){
        case 0:
            xorsumB = b;
            break;
        case 1:
            xorsumB = 1;
            break;
        case 2:
            xorsumB = b+1;
            break;
        case 3:
            xorsumB = 0;
            break;

    }

    ll ans = (xorsumA ^ xorsumB) ^ a;
    cout << ans << endl;
    return 0;
}

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

int main(){
int x,n; cin >>x >>n;
int p[n+1];
int ans=0;
for(int i=0;i<n;i++) cin >> p[i];


if(n==0){
  cout << x <<endl;
  return 0;
}
else{
  for(int i=0;i<=200;i++){
  int count =0;
  for(int j=0;j<n;j++){
    if(i==p[j]) break;
    count +=1;
  }
  if(count ==n){
    if(abs(x-i)<abs(x-ans)) ans = i;
  }
}
cout << ans <<endl;
}
}

Measured memory_bytes: 3620
#include<iostream>
#include<math.h>
#include<queue>
#include<cstdio>
#define inf 1000000001
#define f first
#define s second
using namespace std;

int n;
double map[101][101];
  
double Prim()
{
  priority_queue<pair<double,int> > PQ;
  int color[100];
  double d[100];
  for(int i=0;i<n;i++){
    d[i]=inf;
    color[i]=0;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=0;
  while(!PQ.empty()){
    pair<double,int> p=PQ.top();PQ.pop();
    int u=p.s;
    color[u]=2;

    if(d[u]<p.f*(-1))continue;

    for(int i=0;i<n;i++){
      if(color[i]==2 || map[u][i]==inf)continue;
      if(d[i]>map[u][i]){
	d[i]=map[u][i];
	PQ.push(make_pair(d[i]*(-1),i));
	color[i]=1;
      }
    }
  }
  double ans=0;
  for(int i=0;i<n;i++)ans+=d[i];
  return ans;
}  

int main()
{
  double x[101],y[101],z[101],r[101];

  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i]>>r[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j)map[i][j]=inf;
	else {
	  double d=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) + (z[i]-z[j])*(z[i]-z[j]) );
	  map[i][j]=d-(r[i]+r[j]);
	  if(map[i][j]<0)map[i][j]=0;
	}
      }
    }
    printf("%.3f\n",Prim());
  }
  return 0;
}

Measured memory_bytes: 1464
#include <stdio.h>

int main()
{
 int x,y;
 scanf("%d%d",&x,&y);
 int ans=0;
 for(int i=0;i<=x;i++){
   if(i*2+(x-i)*4==y){
     ans=1;
   }
 }
   if(ans==1){
     printf("Yes");
   }
    else{
      printf("No");
    }
   }
 
  
  
    
    
    
  
  
  


Measured memory_bytes: 1728
import sys

input=sys.stdin.readline

N,M=map(int,input().split())

# N: 処理する区間の長さ
INF = 2**31-1

LV = (M+2-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i in range(1,M+1):
    update(0,i+1,1)

add=M-N
hito=[]
for i in range(N):
    L,R=map(int,input().split())
    hito.append((L,R))
hito.sort()
#test=[query(i,i+1) for i in range(M+2)]
#print(test)
for l,r in hito:
    update(0,r+1,-1)
    #test=[query(i,i+1) for i in range(M+2)]
    #print(test)
    m=query(l+1,M+2)+l
    add=min(m,add)

print(max(-add,0))


Measured memory_bytes: 106336
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n,m; cin >> n;
    map<int,int> mp1, mp2;

    rep(i,n){
        int d; cin >> d;
        mp1[d]++;
    }

    cin >> m;
    vector<ll> t(m);
    rep(i,m){
        cin >> t[i];
        mp2[t[i]]++;
    }

    bool ans = true;
    rep(i,m){
        if(mp2[t[i]] > mp1[t[i]]) ans = false;
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
   ll n,m,k,i,j,ans=0,ind1=1,ind2=1;
   cin>>n>>m>>k;
   ll a[n+1],b[m+1];
   a[0]=0;b[0]=0;
   for(i=1;i<=n;i++)cin>>a[i];
   for(i=1;i<=m;i++)cin>>b[i];
   for(i=2;i<=n;i++)
   {
       a[i]+=a[i-1];
   }
   for(i=2;i<=m;i++)
   {
       b[i]+=b[i-1];
   }
   for(i=0;i<=n;i++)
   {
       ll temp;
       if(a[i]>k)
       {
           break;
       }
       ll d=k-a[i];
       ll ind=upper_bound(b+1,b+m+1,d)-b;
       temp=i+(ind-1);
       ans=max(ans,temp);
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 6760
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int limitHeight = sc.nextInt();
		int result = 0;
		
		for(int i = 0; i < num; i++) {
			if(limitHeight <= sc.nextInt() ) {
				result++;
			}
		}

		System.out.println(result);
		sc.close();
	}
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define llrep(i,a,b) for(ll i=a;i<b;i++)
#define llrepd(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
vector<ll> edges[200000];
ll num[200000];

void dfs(ll i, ll p) {
    fore(e, edges[i]) {
        if(e != p) {
            num[e] += num[i];
            dfs(e, i);
        }
    }
}

void _main(){
    ll N, Q; cin >> N >> Q;
    rep(i, 0, N-1) {
        ll a, b; cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    rep(i, 0, Q) {
        ll p, x; cin >> p >> x;
        num[p-1] += x;
    }
    dfs(0,-1);
    rep(i, 0, N) cout << num[i] << " ";
    cout <<endl;
}


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

int main(){
	int n,t;
	vector <int> a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t;
		a.push_back(t);
	}
	sort(a.begin(),a.end());
	for(int i=1;i<n;i++){
		if(a[i-1]==a[i]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1400
// author: lkx     
// Problem: 
// ID: 
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back 
#define MP make_pair
#define PH push

int n;
vector<int> vec[100100];

int dfs(int a,int par)
{
	int node=0; 
	int ans=0;
	for(int i=0;i<vec[a].size();i++)
	{
		if(vec[a][i]==par) continue;
		int xxx=dfs(vec[a][i],a);
		if(xxx==0) node++;
		ans+=xxx;
	}
	if(node>1) ans+=node-1;
//	cout<<a<<" "<<ans<<endl;
	return ans; 
}

int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		vec[a].PB(b);
		vec[b].PB(a);	
	} 
	int line=-1;
	for(int i=0;i<n;i++)
		if(vec[i].size()>2)
			line=i;
	if(line==-1) puts("1");
	else cout<<dfs(line,-1)<<endl;
	return 0; 
}

Measured memory_bytes: 10112
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

#define REP(i,n) for(int i=0; i < n; ++i)
#define EACH(it,c) for(decltype((c).begin()) it = (c).begin(); it != (c).end(); ++it)

using namespace std;

int str2num(const string& rhs) {
	int digit = 0;
	int result = 0;
	REP(j, rhs.length()) {
		const char ch = rhs[j];
		if(isdigit(ch)) {
			digit = ch - '0';
			continue;
		}
		// alpha
		if (digit == 0) {
			digit = 1;
		}
		int heavy = 1;
		switch (ch) {
			case 'm':
				heavy = 1000;
				break;
			case 'c':
				heavy = 100;
				break;
			case 'x':
				heavy = 10;
				break;
			case 'i':
				heavy = 1;
				break;
		}
		result += digit * heavy;
		digit = 1;
	}
	return result;
}

string num2str(int rhs) {
	int digit = 1000;
	string result;

	while(rhs > 0) {
		if(rhs / digit > 1)
			result.push_back(rhs / digit + '0');
		else if(rhs / digit == 0){
			digit /= 10;
			continue;
		}
		switch(digit) {
		case 1000:
			result.push_back('m');
			break;
		case 100:
			result.push_back('c');
			break;
		case 10:
			result.push_back('x');
			break;
		case 1:
			result.push_back('i');
			break;
		}

		rhs   %= digit;
		digit /= 10;
	}

	return result;
}

int main() {
	std::ios::sync_with_stdio();
	
	int n;
	cin >> n;
	REP(i, n) {
		string strA, strB;
		cin >> strA >> strB;

		// 10進数への変換
		const int dexNumA = str2num(strA);
		const int dexNumB = str2num(strB);
		const int sum = dexNumA + dexNumB;
		
		// x進数への変換
		const string result = num2str(sum);

		//cout << "sum = A + B == " << sum << " = " << dexNumA << " + " << dexNumB << endl;

		// 出力処理
		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if(s<t) pt("Yes");
    else pt("No");
    
}


Measured memory_bytes: 256
#include <cstdio>
#define MOD 1000000007
typedef long long ll; 
int a[405], b[405], appa[405], appb[405], val[405][405]; 
ll dp[405][405][405]; 
int main()
{
	// freopen("CF17-QC-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", a + i); 
		appa[a[i]] = i; 
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", b + i); 
		appb[b[i]] = i; 
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int x = 1; x <= n; x++)
				val[i][j] += appa[x] <= i || appb[x] <= j; 
		}
	}
	dp[0][0][0] = 1; 
	for (int i = 1; i <= n / 3; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				dp[i][j][k] = (dp[i][j - 1][k] + dp[i][j][k - 1] - dp[i][j - 1][k - 1]) % MOD; 
				if (appb[a[j]] > k && appa[b[k]] > j)
					(dp[i][j][k] += dp[i - 1][j - 1][k - 1] * (3 * i - val[j][k])) %= MOD; 
			}
		}
	}
	ll ans = (dp[n / 3][n][n] + MOD) % MOD; 
	for (int i = 1; i <= n; i++)
	{
		if (i % 3)
			ans = ans * i % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string alice;
    string bob;
    string charlie;
    int cursora = 0;
    int cursorb = 0;
    int cursorc = 0;
    char turn = 'a';
    
    cin >> alice;
    cin >> bob;
    cin >> charlie;
    
    while(true){
        if(turn == 'a'){
            if(cursora >= (int)alice.size()){
                std::cout << "A" << "\n";
                return 0;
            }else{
                turn = alice[cursora];
                cursora++;
            }
        }else if(turn == 'b'){
            if(cursorb >= (int)bob.size()){
                std::cout << "B" << "\n";
                return 0;
            }else{
                turn = bob[cursorb];
                cursorb++;
            }
        }else if(turn == 'c'){
            if(cursorc >= (int)charlie.size()){
                std::cout << "C" << "\n";
                return 0;
            }else{
                turn = charlie[cursorc];
                cursorc++;
            }
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 3540
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=2010;
const int MOD=1e9+7;
int n,k;
long long fac[MAXN*MAXN],inv[MAXN*MAXN],f[MAXN][MAXN];
long long C(long long x,long long y)
{
	return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
long long qpow(long long x,long long y)
{
	long long tmp=1;
	for(;y;y>>=1,x=x*x%MOD)if(y&1)tmp=tmp*x%MOD;
	return tmp;
}
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%d%d",&n,&k);
	if(k==1)
	{
		printf("1");
		return 0;
	}
	fac[0]=1;
	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*i%MOD;
	inv[n*k]=qpow(fac[n*k],MOD-2);
	for(int i=n*k;i>=1;i--)inv[i-1]=inv[i]*i%MOD;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			f[i][j]=f[i-1][j];
			if(!j)continue;
			f[i][j]=(f[i][j]+f[i][j-1]*(n-j+1)%MOD*C(n-i+(n-j+1)*(k-1)-1,k-2))%MOD;
		}
	printf("%lld\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 93056
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
	int N,K,i,a[1001],total=0;
	scanf("%d",&N);
	scanf("%d",&K);
	for(i=0;i<N;i++)scanf("%d",&a[i]);
	qsort(a, N, sizeof(int), compare_int);
	for(i=0;i<K;i++)total+=a[i];
	printf("%d",total);
	return 0;
}

Measured memory_bytes: 1748
def c_dice_and_coin():
    from math import ceil, log2
    N, K = [int(i) for i in input().split()]

    ans = 1 / N * sum(1 / 2**max(ceil(log2(K / d)), 0) for d in range(1, N + 1))
    return round(ans, 12)

print(c_dice_and_coin())

Measured memory_bytes: 3188
import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var minv = readInt
  var maxv = Int.MinValue
  var i=1

  while(i<n) {
    val r = readInt
    val m = r-minv

    if(m > maxv) maxv = m
    if(m < 0) minv = r
    i += 1
  }
  println(maxv)
}

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

int main()
{
	ll n,i;
	cin >> n;
	ll x=0LL;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin >> a[i];
		x^=a[i];
	}
	for(i=0;i<n;i++)
	{
		cout << ((x)^(a[i])) << " " ;
	}
}

Measured memory_bytes: 5128
N = int(input())
A = list(map(int, input().split()))

A = [0] + A + [0]
sum_all = 0

for i, a in enumerate(A[1:N + 2], start=1):
    sum_all += abs(a - A[i - 1])

for i, a in enumerate(A[1:N + 1], start=1):
    print(sum_all - abs(a - A[i - 1]) - abs(a - A[i + 1]) + abs(A[i + 1] - A[i - 1]))



Measured memory_bytes: 20580
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int a=2004;
			int s=sc.nextInt();
			int d=sc.nextInt();
			if(s==0&&d==0)break;
			if(s==1||s==2){a-=1;s+=13;}
			else if(s>=3)s+=1;
			//System.out.println(s+" "+a+" "+d);
			double A=Math.floor(a*365.25);
			double B=Math.floor(s*30.6);
			double C=Math.floor(a/400);
			double D=Math.floor(a/100);
			double E=A+B+C+d-D-429;
			double EE=Math.floor(E/7);
			double F=EE*7;
			//System.out.println(E+" "+F+" "+EE);
			double ans=E-F;
			//System.out.println(ans);
			if(ans==0)System.out.println("Monday");
			else if(ans==1)System.out.println("Tuesday");
			else if(ans==2)System.out.println("Wednesday");
			else if(ans==3)System.out.println("Thursday");
			else if(ans==4)System.out.println("Friday");
			else if(ans==5)System.out.println("Saturday");
			else if(ans==6)System.out.println("Sunday");
		}	
	}
}

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

int main() {
  int H, W;

  cin >> H >> W;
  vector<vector<int>> G(H+1, vector<int>(W+1, 0));
  vector<vector<bool>> stained(H+1, vector<bool>(W+1, false));

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      int isStained;
      cin >> isStained;
      if (isStained) stained[i][j] = true;
    }
  }

  int max = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (stained[i][j]) {
        G[i][j] = 0;
        continue;
      }
      int left = G[i][j-1];
      int left_up = G[i-1][j-1];
      int up = G[i-1][j];
      int minVal = min(left, min(left_up, up));

      G[i][j] = minVal + 1;
      if (G[i][j] > max) max = G[i][j];
    }
  }

  cout << max * max << endl;
  return 0;
}



Measured memory_bytes: 10860
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef long long ll;
int expr(string&, int&);
int term(string&, int&);
int number(string&, int&);

int number(string& s, int& i){
    int c = s[i] - '0';
    i++;
    return c;
}

int term(string& s,int& i){
    if(isdigit(s[i]))return number(s,i);
    if(s[i] == '-'){
        while(s[i] == '-'){
            int val;
            i++;
            val = term(s,i);
            if(val == 2){
                val = 0;
            }
            else if(val == 0){
                val = 2;
            }
            return val;
        }
    }
    i++;
    int res = expr(s,i);
    i++;
    return res;
}

int expr(string& s, int& i){
    int val = term(s,i);
    while(s[i] == '*' || s[i] == '+'){
        char op = s[i];
        i++;
        int val2 = term(s,i);
        if(op == '*'){
            if(val == 0 || val2 == 0){
                val = 0;
            }
            else if(val == 1 || val2 == 1){
                val =  1;
            }
            else{
                val = 2;
            }
        }
        else if(op == '+'){
            if(val == 2 || val2 == 2){
                val = 2;
            }
            else if(val == 1 || val2 == 1){
                val = 1;
            }
            else{
                val = 0;
            }
        }
    }
    //cout << "# " << val << "\n";
    return val;
}
int solve(string str,int depth){
    if(depth == 3){
        int idx = 0;
        return expr(str,idx) == 2;
    }
    string a,b,c;
    rep(i,str.size()){
        if(str[i] == 'P'+depth){
            a += "0";
            b += "1";
            c += "2";
        }
        else{
            a += str[i];
            b += str[i];
            c += str[i];
        }
    }
    return solve(a,depth+1) + solve(b,depth+1) + solve(c,depth+1);
}
int main(){
    string str;
    while(true){
        cin >> str;
        if(str == "."){
            break;
        }
        printf("%d\n",solve(str,0));
    }
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

long gcd(long a,long b){
  if(b == 0) return a;
  else return gcd(b,a%b);
}

int main(){
  long a,b;
  cin >> a >> b;
  cout << a*b/gcd(a,b) << endl;
}


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

int main(void)
{
    //const double PI=3.141592653589793238;


    int N, K, X, Y, count=0, i=1;
    cin >> N >> K >> X >> Y;

    while(i <= N)
    {
        if(i<=K) count += X;
        else count += Y;
        i++;
    }


    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	int N;
	cin >> N;
	ll result=0;
	vector<ll> data(N);
	rep(i,N){
		cin >> data.at(i);
	}
	std::sort(data.begin(), data.end());
	rep(i, N - 2) {
		for (int j = i + 1; j < N - 1; j++) {
			if (data.at(i) < data.at(j)) {
				for (int k = i + 2; k < N; k++) {
					if (data.at(j) < data.at(k)&&data.at(i)+data.at(j)>data.at(k)&&data.at(j)+data.at(k)>data.at(i)&&data.at(k)+data.at(i)>data.at(j)){
						result++;
					}
				}

			}
		}
	}

	cout << result << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

int n, x, y, c[N];

int Abs(int p) {return p > 0 ? p : -p;}

int main()
{
	int i, j, t;
	cin >> n >> x >> y;
	for (i = 1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
			t = min(j - i, Abs(i - x) + Abs(j - y) + 1);
			c[t]++;
		}
	}
	for (i = 1; i < n; i++) printf("%d\n", c[i]);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#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> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};


int main(){
    int n,h;
    cin >> n >> h;
    vector<int> p(2*h+1);
    vector<vector<int> > g(2*h+1);
    UnionFind uf(2*h+1);
    rep(i,n){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int x,y;
        if(c==0){
            x = a;
        }else{
            x = h+c;
        }
        if(d==0){
            y = h + b;
        }else{
            y = d;
        }
        p[x]++;
        p[y]--;
        g[x].push_back(y);
        uf.unite(x,y);
    }
    vector<int> s(2*h+1);
    rep(i,2*h+1){
        if(i<=h)s[uf.find(i)] += p[i];
    }
    rep(i,2*h+1){
        if(i<=h){
            if(p[i]<0){
                cout << "NO" << endl;
                return 0;
            }
        }else{
            if(p[i]>0){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    bool flag = 1;
    rep(i,2*h+1){
        if(g[i].size()>0){
            if(s[uf.find(i)]<=0){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()
    val b = scanner.nextInt()
    val k = scanner.nextInt()

    val v = (a until Math.min(a + k, b)) + (Math.max(a, b - k + 1)..b)
    v.toSet()
            .map { println(it) }

}

Measured memory_bytes: 31400
import sys
import heapq
input = sys.stdin.readline

n,m = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break
print(sum(A))

Measured memory_bytes: 97264
using System;

namespace B___Around_Square
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            long a = 0;
            for(var i=1; i*i<=n; i++)
            {
                a = i * i;
            }
            Console.WriteLine(a);

        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void dfs(int node, VEC(VEC(Pii))& edges, VEC(int)& colors, int parity,
            int parent = -1)
{
    colors[node] = parity % 2;
    for(auto& edge: edges[node]) {
        if (edge.first != parent)
        dfs(edge.first, edges, colors, (parity + edge.second) % 2, node);
    }
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(VEC(Pii)) edges(N);
    FOR(i, 0, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        edges[u].push_back(PAIR(v, w));
        edges[v].push_back(PAIR(u, w));
    }

    VEC(int) colors(N, -1);
    dfs(0, edges, colors, 0);
    FOR(i, 0, N)
        cout << colors[i] << endl;
    return 0;
};


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  long N,x;
  cin >> N >> x;
  
  vector<long>child(N,0);
  
  for(int i=0;i<N;i++){
    cin >> child[i];
  }
  
  sort(child.begin(),child.end());
  
  long ans = 0;
  long candy = 0;
  
  
  
  for(int i=0;i<N;i++){
    candy += child[i];
    if(candy == x && i == N-1){
      ans = N;
      break;
    }
    else if(candy > x)
      break;
    else
      ans++;
  }
  
  if(candy != x && ans == N)
    ans--;
  
  cout << ans << endl;
  
  return 0;
}

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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

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

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

int dp[50][(1 << 17)];

void solve() {
  int n, x, y, z;
  cin >> n >> x >> y >> z;

  int ans = 10;
  rep(i, 2, n) { ans = (ans * 10ll) % mod; }

  int m = (1 << (x + y +z)) - 1;
  int mask = (1 << (x - 1)) | (1 << (x + y - 1)) | (1 << (x + y + z - 1));
  dp[0][0] = 1;
  rep(i, 1, n) {
    rep(j, 0, m) {
      rep(k, 1, 10) {
        ll t = (j * 1ll << k) | (1ll << (k - 1));
        t &= m;
        if ((t & mask) == mask) { continue; }
        dp[i][t] = (dp[i][t] + dp[i - 1][j]) % mod;
      }
    }
  }
  
  rep(i, 0, m) {
    ans = (ans - dp[n][i] + mod) % mod;
  }

  cout << ans;
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e3 + 100;

int cnt[maxn];

int main()
{
  ios::sync_with_stdio(0);
  int n,x,y;
  cin >> n >> x >> y;
  
  for(int i = 1; i <= n ; i++)
  {
    for(int j = i + 1 ; j <= n ; j++)
    {
      int d = min(abs(j - i), abs(x - i ) + 1 + abs(y - j));
      cnt[d]++;
    }
  }

  for(int i = 1; i < n ; i++)
  {
    cout << cnt[i] << endl;
  }



  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,j;
  int adj[100][100];
  int n,u,k,v;

  for(i=0;i<100;i++){for(j=0;j<100;j++){adj[i][j]=0;}}

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      adj[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0){printf(" ");}
      printf("%d",adj[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2112
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
//AtCoderC++.cpp

using namespace std;

int main() {
	string S; cin >> S;
	if (S[0] == S[1] && S[1] == S[2] && S[2] == S[3]) {
		cout << "No" << endl;
		return 0;
	}
	auto found = vector<bool>(26, false);
	for (size_t i = 0; i < 4; i++) {
		found[S[i] - 'A'] = !found[S[i] - 'A'];
	}
	for (size_t i = 0; i < 26; i++) {
		if (found[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;
vector<int> prime;
bool isPrime[33000];

void PrimeCalc()
{
	memset(isPrime, 1, sizeof(isPrime));
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 33000; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < 33000; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		for(int i = 0; i < prime.size(); ++i)
		{
			if(n / 2 < prime[i])
			{
				break;
			}
			for(int j = i ; j < prime.size(); ++j)
			{
				if(n <= prime[i] + prime[j])
				{
					if(n == prime[i] + prime[j])
					{
						++count;
					}
					break;
				}
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1284
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {

    int count = 0;
    int max = 0;
    int D1 = 0;
    int D2 = 0; 

    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    for (int i = 0; i < N; i++){
      D1 = Integer.parseInt(scanner.next());
      D2 = Integer.parseInt(scanner.next());
      if (D1 == D2) {
        count++;
        if (count == N){
          max = count;
        }
      } else {
        if (count > max){
          max = count;
        }
        count = 0;
      }
    }
    scanner.close();

    if (max >= 3){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 27076
#include <iostream>
#include <vector>
#include <algorithm>

int binarySearch(std::vector<int>::iterator begin, std::vector<int>::iterator end, int key)
{
  auto n = std::distance(begin, end);

  auto cur_i = (n-1)/2;
  auto cur_left = 0;
  auto cur_right = n-1;
  auto cur_value = *(begin + cur_i);
  
  while (cur_right > cur_left)
    {
      if (cur_value == key)
        {
          return 1;
        }
      else if (cur_value > key)
        {
          cur_right = cur_i - 1;
        }
      else
        {
          cur_left = cur_i + 1;
        }
      cur_i = cur_left + (cur_right - cur_left) / 2;
      cur_value = *(begin + cur_i);
    }
  return (cur_value == key);
}

int main ()
{
  int n, q;
  std::vector<int> S;

  std::cin >> n;
  for (int i=0; i<n; i++)
    {
      int s;
      std::cin >> s;
      S.push_back(s);
    }

  std::cin >> q;
  int ans = 0;
  for (int i=0; i<q; i++)
    {
      int t;
      std::cin >> t;
      ans += binarySearch(S.begin(), S.end(), t);
    }
  std::cout << ans << std::endl;
}



Measured memory_bytes: 3392
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n,odd=0;
	cin>>n;
	rep(i,n){
	    int p;cin>>p;
	    if(p%2)odd++;
	}
	cout<<(odd%2?"NO":"YES")<<endl;
	return 0;
}


Measured memory_bytes: 256
// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

//=========================================================

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//=========================================================
#ifdef DEBUG
#define xtp xtp1
#else
#define xtp(x)
#endif
//=========================================================

#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define F first
#define S second
#define pb push_back
#define endl "\n"

#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define rSORT(a) sort(rALL(a))
#define REV(a) reverse(ALL(a))
#define sqr(x) ((x) * (x))

#define TEZ                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);

const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;

signed main() {
	TEZ;

	int n;
	cin >> n;

	vi a(n);
	int s = 0, ss = 0;
	for (int &i : a) {
		cin >> i, s += i, s %= mod;
		ss = (ss + ((i * i) % mod)) % mod;
	}

	s = (s * s) % mod;

	s -= ss;

	s = (s + mod) % mod;

	s = (s * 500000004) % mod;

	cout << s << endl;

	return 0;
}


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

#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=(m);i<(n);i++)
#define sz(x) ((x).size())

int p,q;
string s[11],t[11];
int P[11],nr[11],nc[11],ns[11];
int mr[11],mc[11],ms[11];

int main2(){
	rep(i,p){
		int cur=0;
		while(cur<sz(s[i]) && s[i][cur]=='.') cur++;
		P[i]=cur;
	}
	int R=0,C=0,S=0;
	rep(i,p){
		nr[i]=R,nc[i]=C,ns[i]=S;
		rep(j,sz(s[i])){
			if(s[i][j]=='(')R++;
			if(s[i][j]==')')R--;
			if(s[i][j]=='{')C++;
			if(s[i][j]=='}')C--;
			if(s[i][j]=='[')S++;
			if(s[i][j]==']')S--;
		}
	}
	rep(i,q){
		mr[i]=R,mc[i]=C,ms[i]=S;
		rep(j,sz(t[i])){
			if(t[i][j]=='(')R++;
			if(t[i][j]==')')R--;
			if(t[i][j]=='{')C++;
			if(t[i][j]=='}')C--;
			if(t[i][j]=='[')S++;
			if(t[i][j]==']')S--;
		}
	}
	int ans[11];
	fill(ans,ans+q,-2);
	rep2(r,1,21)rep2(c,1,21)rep2(s,1,21){
		int ok=1;
		rep(i,p){
			int indent = r*nr[i] + c*nc[i] + s*ns[i];
			if(indent != P[i]){
				ok=0;break;
			}
		}
		if(ok==0)continue;
		rep(i,q){
			int indent = r*mr[i] + c*mc[i] + s*ms[i];
			if(ans[i]==-2)ans[i]=indent;
			else if(ans[i]!=indent)ans[i]=-1;
		}
	}
	rep(i,q)cout<<ans[i]<<(i==q-1?"\n":" ");
}

int main(){
	while(cin>>p>>q && p){
		getline(cin,s[0]);
		rep(i,p)getline(cin,s[i]);
		rep(i,q)getline(cin,t[i]);
		main2();
	}
}

Measured memory_bytes: 1216
import sys
input = sys.stdin.readline

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = [0]*N

for i in range(N):
    temp[i] = T - H[i]*0.006
    temp[i] = abs(A - temp[i])

temp2 = sorted(temp)
print(temp.index(temp2[0])+1)


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int x,y,d,r;

  scanf("%d%d",&x,&y);

  if(x<y){
    d=y;
    y=x;
    x=d;
  }
  

  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  printf("%d\n",x);
  return 0;
}



Measured memory_bytes: 2084
using System;

namespace ABC_154_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            var wort = Console.ReadLine().Split(' ');
            string S = word[0];
            string T = word[1];
            int A = int.Parse(wort[0]);
            int B = int.Parse(wort[1]);
            string U = Console.ReadLine();
            if (S == U) Console.WriteLine((A - 1) + " " + B);
            else if (T == U) Console.WriteLine(A + " " + (B - 1));
            Console.ReadKey();
        }
    }
}


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

int sum(int N) {
  int sum10sin = 0;
  while (true) {
    sum10sin += (N % 10);
    if (N / 10 != 0){      
      N /= 10;
    } else { break; }
  }
  return sum10sin;
  }


int main() {

  int N, A, B;
  cin >> N >> A >> B;
  
  int souwa = 0;
  for (int i = 1; i <= N; i++){
    if (A <= sum(i) && sum(i) <= B){
      souwa += i;
    }
  }
  
  cout << souwa << endl;
  
}
      
     
      

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

 class Main  {
     public static void main(String[]args){
         Scanner scan = new Scanner(System.in);
         int n = scan.nextInt();
         int max = 0 ;
         if(n==1){
             max = 1;
         }
         for(int i = 2 ; i<= n ; i++ ){
             for(int j  = 1 ; j<=n ; j++){
                
                 if(Math.pow(j, i) - (int)Math.pow(j,i) == 0){
                     
                     if( (int)Math.pow(j,i) > max && (int)Math.pow(j,i)<=n){
                         max =  (int)Math.pow(j,i) ;
                     }
                 }
                  //System.out.print((int)Math.pow(j,i)+" ");
                 if( (int)Math.pow(j+1,i ) > n){
                     break;
                 }
                 
             }
             //System.out.println();
         }
         System.out.println(max);
         
     }
}


Measured memory_bytes: 22484
#include <stdio.h>
 
int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  
  while(1){
	C = C - B;
    if(0 >= C){
	  printf("Yes\n");
      break;
    }
    A = A - D;
    if(0 >= A){
	  printf("No\n");
      break;
    }
  }
  
  return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  ll n,k; cin>>n>>k;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  //cout<<<<endl;

  
  vector<ll> h(n+1);
  for(i=0;i<n;i++){
    cin>>buf;
    h[buf]++;
  }
  sort(ALL(h));
  buf=0;
  for(i=0;i<=n;i++){
    if(h[i]==0){
      buf++;
    }
  }
  buf2=n-buf+1;
  for(i=buf;buf2>k;i++,buf2--){
    result+=h[i];
  }
  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 1792