akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20000 + 10;
const int M = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n,in[8*N];
vector<ii> t;
vi g[8*N],rg[8*N],id[8*N],nodes;
int Not(int x){
	if(x<8*n)
		return x+8*n;
	return x-8*n;
}

void build(int u, int s, int e){
	nodes.pb(u);
	nodes.pb(Not(u));
	if(s==e){
		id[t[s].second].pb(u);
		in[s]=u;
		return;
	}
	build(u*2,s,(s+e)/2);
	build(u*2+1,(s+e)/2+1,e);
	g[u].pb(u*2);
	g[u].pb(u*2+1);
	rg[u*2].pb(u);
	rg[u*2+1].pb(u);
}

void addEdge(int x, int y){
	g[Not(x)].pb(y);
	g[Not(y)].pb(x);
	rg[y].pb(Not(x));
	rg[x].pb(Not(y));
}
int l,r;
stack<ii> un;
void update(int u, int s, int e, int x){
	if(s>r || e<l)
		return;
	if(s>=l && e<=r){
		g[Not(x)].pb(u);
		rg[u].pb(Not(x));
		un.push(ii(Not(x),u));
		return;
	}
	update(u*2,s,(s+e)/2,x);
	update(u*2+1,(s+e)/2+1,e,x);
}
bool vis[8*N];
int cmp[8*N];
stack<int> st;
void dfs(int u){
	vis[u]=true;
	for(int i=0; i<g[u].size(); ++i)
		if(!vis[g[u][i]])
			dfs(g[u][i]);
	st.push(u);
}
void dfs(int u, int cc){
	cmp[u]=cc;
	for(int i=0; i<rg[u].size(); ++i)
		if(cmp[rg[u][i]]==-1)
			dfs(rg[u][i],cc);
}
bool can(int d){
	while(!un.empty()){
		ii e=un.top();
		un.pop();
		g[e.first].pop_back();
		rg[e.second].pop_back();
	}
	for(int i=1; i<t.size(); ++i){
		l=lower_bound(all(t),ii(t[i].first-d+1,0))-t.begin();
		r=i-1;
		update(1,1,2*n,in[i]);
		l=i+1;
		r=upper_bound(all(t),ii(t[i].first+d-1,oo))-t.begin()-1;
		update(1,1,2*n,in[i]);
	}
	memset(vis,0,sizeof(vis));
	for(int i=0; i<nodes.size(); ++i)
		if(!vis[nodes[i]])
			dfs(nodes[i]);
	int cc=0;
	memset(cmp,-1,sizeof(cmp));
	while(!st.empty()){
		int u=st.top();
		st.pop();
		if(cmp[u]!=-1)continue;
		dfs(u,cc++);
	}
	for(int i=0; i<nodes.size(); ++i)
		if(cmp[nodes[i]]==cmp[Not(nodes[i])])
			return false;
	return true;
}
int main(){
	cin>>n;
	t.resize(2*n+1);
	t[0].first=-2*oo;
	for(int x,y,i=0; i<n; ++i){
		scanf("%d%d",&x,&y);
		t[2*i+1]=ii(x,i);
		t[2*i+2]=ii(y,i);
	}
	sort(all(t));
	build(1,1,2*n);
	for(int i=0; i<n; ++i){
		int x=id[i][0],y=id[i][1];
		addEdge(x,y);
		addEdge(Not(x),Not(y));
	}
	int lo=0, hi=oo, md, bst=0;
	while(lo<=hi){
		md=(lo+hi)/2;
		if(can(md)){
			bst=md;
			lo=md+1;
		}else
			hi=md-1;
	}
	cout<<bst<<endl;
	return 0;	
}

Measured memory_bytes: 37112
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Long> list = new ArrayList<>();
    //final List<Long> list2 = new ArrayList<>();

    int x = sc.nextInt();
    int a = sc.nextInt();

    if(x < a){
        System.out.println(0);
    }else{
        System.out.println(10);
    }
    





}
}

Measured memory_bytes: 35832
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    int a,b,h;
    cin >> a >> b >> h;

    cout << (a+b)*h/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	while(cin>>n,n){
		int sum = 0;
		for(int j = 0;j < n;j++){
			int x,y,h,w;
			cin>>x>>y>>h>>w;
			int v =x+y+h;
			int va = -1;
			int wa =-1;
			for(int i =60;i <=160;i+=20){
				if(v <=i){
					va =i;
					break;
				}
			}
			if(va==-1)continue;
			if(w<=2){
				wa =60;
			}else if(w<=5){
				wa =80;
			}else if(w <=10){
				wa =100;
			}else if(w <=15){
				wa =120;
			}else if(w <=20){
				wa =140;
			}else if(w <=25){
				wa =160;
			}
			if(wa==-1)continue;
			//cout <<wa<<" "<<va<<endl;
			sum +=max(wa,va)*10;
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

/*
説明
*/
public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        String n = s.next();
        String first = n.substring(0, (n.length())/2);
        String saigo = n.substring((n.length()+2)/2, n.length());

        String ans = "Yes";
        if (!first.equals(saigo)) {
            ans = "No";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(s;stdin.byLine())
    {
        int[10] c; foreach(n;s) ++c[n-'0'];
        bool dfs(int n, bool d)
        {
            if(n>9) return d;
            if(c[n]==0) return dfs(n+1,d);
            if(c[n]>=3)
            {
                c[n]-=3;
                auto r = dfs(n,d);
                c[n]+=3;
                if(r) return true;
            }
            if(n<=9-2 && c[n]>0 && c[n+1]>0 && c[n+2]>0)
            {
                foreach(i;0..3) --c[n+i];
                auto r = dfs(n,d);
                foreach(i;0..3) ++c[n+i];
                if(r) return true;
            }
            if(!d && c[n]>=2)
            {
                c[n]-=2;
                auto r = dfs(n,true);
                c[n]+=2;
                if(r) return true;
            }
            return false;
        }
        bool solve(int n)
        {
            if(c[n]>=4) return false;
            ++c[n];
            auto r = dfs(1,false);
            --c[n];
            return r;
        }
        auto a = iota(1,10).filter!solve().map!(to!string).join(" ");
        if(a=="") a="0";
        a.writeln();
    }
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	for (auto &i : a) cin >> i;

	auto f = [&]()
	{
		int x = 0;
		vector<int> b(n);
		iota(b.begin(), b.end(), 1);
		do
		{
			++x;
			if (a == b) return x;
		} while (next_permutation(b.begin(), b.end()));
		return -1;
	};

	int x = f();

	for (auto &i : a) cin >> i;
	cout << abs(x - f()) << "\n";

	return 0;
}



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

int main() {
  int r = 0, b = 0, length;
  char ctemp;
  string s;
  cin >> s;
  length = s.length();
  for (int i = 0; i < length; i++) {
    ctemp = s[i];
    if (ctemp == '0') r++;
    if (ctemp == '1') b++;
  }
  cout << min(r, b) * 2;
  return 0;
}

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

int mod = 1e9 + 7;

long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    long long res = modpow(x, y / 2);
    return res * res % mod;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<long long> inv(2e5 + 1, 1);
    for (int i = 2; i < 2e5 + 1; i++) inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
    vector<long long> cmb(n + 1, 1);
    for (int i = 1; i <= n; i++) cmb[i] = (cmb[i - 1] * (n - i + 1) % mod) * inv[i] % mod;
    vector<long long> cmb2(n, 1);
    for (int i = 1; i < n; i++) cmb2[i] = (cmb2[i - 1] * (n - 1 - i + 1) % mod) * inv[i] % mod;
    long long ans = 0;
    for (int i = 0; i < min(n, k + 1); i++)
    {
        ans += cmb[i] * cmb2[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> G[1005];
int owner[1005];
bool visited[1005];
bool can[1005];//太郎と花子が可能な統治数のbool配列
int tarohana=0;
bool clear=true;
void dfs(int s,int own)
{
    //own=1は太郎or花子
    //own=0は次郎
    //own=1の隣接頂点は必ずown=0
    //own=0の隣接頂点は必ずown=1
    //とりあえず,適当な頂点から太郎or花子とすることにして,
    //矛盾なく色付けできるか深さ優先探索していく.
    visited[s]=true;
    for(int i=0;i<int(G[s].size());i++)
    {
        int to=G[s][i];
        if(own==1)
        {
            if(!visited[to] && owner[to]==0)//まだ塗っていなかったので塗る
            {
                owner[to]=-1;
            }
            else
            {
                if(owner[to]==1)//既に塗られた所で不適切な衝突
                {
                    clear=false;
                    return;
                }
            }            
        }
        else
        {
            if(!visited[to] && owner[to]==0)//まだ塗っていなかったので塗る
            {
                owner[to]=1;
                tarohana++;
            }
            else
            {
                if(owner[to]==-1)//既に塗られた所で不適切な衝突
                {
                    clear=false;
                    return;
                }
            }      
        }      
    }
    for(int i=0;i<int(G[s].size());i++)
    {
        int to=G[s][i];
        if(!visited[to])
        {
            dfs(to,owner[to]);//色塗り後の隣接頂点へ移動.
        }
    }
}

int main(void)
{
    int N,M,conquer=0;
    while(cin >> N >> M && N)
    {
        for(int i=0;i<1005;i++) G[i].clear();
        vector<int> conquerlist;
        conquer=0;
        memset(visited,false,sizeof(visited));
        memset(owner,0,sizeof(owner));
        memset(can,false,sizeof(can));
        for(int i=0;i<M;i++)
        {
            int u,v;
            cin >> u >> v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        for(int i=1;i<=N;i++)
        {
            memset(visited,false,sizeof(visited));
            memset(owner,0,sizeof(owner));
            tarohana=1;//tarohanaが偶数なら,太郎と花子が同一数統治できる.
            owner[i]=1;//とりあえずi番目を太郎or花子が統治.
            dfs(i,1);
            bool clear=true;//色塗り中に矛盾が起きてないかのチェック
            bool ok=true;//全訪問できたかのチェック
            for(int i=1;i<=N;i++)
            {if(!visited[i]) ok=false;}
            if(clear && ok && tarohana%2==0) can[tarohana/2]=true;
        }
        for(int i=1;i<=N;i++) if(can[i]) conquer++,conquerlist.push_back(i);
        cout << conquer << endl;
        for(int i=0;i<conquer;i++)
        {
            cout << conquerlist[i] << endl;
        }
    }
}


Measured memory_bytes: 3204
import java.util.Scanner;

/**
 *
 * @author masa
 */
public class Main {
    public static void main(String[] args) {
         String str = new Scanner(System.in).nextLine();
         int A = Integer.parseInt(str.split(" ")[0]);
         int P = Integer.parseInt(str.split(" ")[1]);
         System.out.println((A*3+P)/2);
    }    
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[210];
int ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)scanf("%d",a+i);
	sort(a+1,a+2*n+1);
	for(int i=1;i<=n;i++)ans+=a[2*i-1];
	printf("%d",ans);
	return 0; 
}

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

using namespace std;

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

#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=(b)-1; i>=(a); --i)

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

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

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

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll x, a[2525], b[2525];
	cin>>n>>x;
	ll ans=0;
	REP(i, n){
		cin>>a[i];
		b[i]=a[i];
		ans+=a[i];
	}
	FOR(i, 1, n){
		ll tmp=i*x;
		REP(j, n){
			b[j]=min(b[j], a[(j-i+n)%n]);
			tmp+=b[j];
		}
		ans=min(ans, tmp);
	}
	cout<<ans<<'\n';
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);

		isUsed = new boolean[n];

		double[][] input = new double[n][3];

		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");

			for(int j = 0; j < 3; j++){
				input[i][j] = Double.parseDouble(tmpArray[j]);
			}
		}
		dfs(input, m, 0, 0);

		System.out.println(result);
	}

	static double result = 0;
	static boolean[] isUsed;

	//input カラー値 member メンバーの人数 depth 現在の階層（今見ているインデックス） count（既に使った色数）
	static void dfs(double input[][], int member, int depth, int count){
		isUsed[depth] = true;
		count++;

		if(count == member){
			calcDist(input);
		}
		else if(depth != input.length - 1){
			dfs(input, member, depth + 1, count);
		}

		isUsed[depth] = false;
		count--;
		if(depth != input.length - 1){
			dfs(input, member, depth + 1, count);
		}
	}

	static void calcDist(double input[][]){
//		printUsed();
		double sum = 0;
		for(int i = 0; i < input.length; i++){
			if(!isUsed[i]){
				continue;
			}
			for(int j = i + 1; j < input.length; j++){
				if(!isUsed[j]){
					continue;
				}
				for(int k = 0; k < 3; k++){
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
			}
		}

		result = Math.max(sum, result);
	}

	//for debug
	static void printUsed() {
		for(int i = 0; i < isUsed.length ; i++){
			System.out.print(isUsed[i]+" ");
		}
		System.out.println();
	}
}



Measured memory_bytes: 27848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		int[] buff = array.clone();
		int M = sc.nextInt();
		int[][] arrayM = new int[M][2];
		long sum=0;

		for(int i=0;i<M;i++) {
			for(int j=0;j<2;j++) {
				arrayM[i][j] = sc.nextInt();
			}
		}

		for(int i=0;i<M;i++) {
			buff[arrayM[i][0]-1] = arrayM[i][1];
			for(int a:buff) {
				sum+=a;
				//System.out.print(a+ " ");
			}
			//System.out.println();
			System.out.println(sum);
			sum=0;
			buff=array.clone();
		}


	}
	public static int sample(int n) {
		return n;
	}

}


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


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

	int count = 0;
	rep(i, K+1){
		rep(j, K+1){
			if((S-i-j) >= 0 && (S-i-j) <= K)
				count++;
		}
	}
	cout << count;

}


Measured memory_bytes: 256
function main(input) {
    // "0 0"???????????????????????????????´????????????????
    var index = input.indexOf('0 0');
    var output =[];
    //????????§????????£??????????????????????????????0 0????????§??????
    for (var i=0; i <index; i++){
        var a = input[i].split(' ');
        if(parseInt(a[1]) < parseInt(a[0])){
            output.push(a[1]+ ' ' +a[0]);
        }
        else{
            output.push(input[i]);
        }
    }
    console.log(output.join('\n'));
}

  
  process.stdin.resume();
  var input = '';  
  process.stdin.setEncoding('utf-8');
  process.stdin.on('data', function(chunk) {
    input += chunk;
  });
  process.stdin.on('end', function() {
    var inputData = input.split('\n');
    main(inputData);
  });

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

int main(){
  long n;cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  } 
  sort(a, a+n);
  if (a[0] == 0){
    cout << 0 << endl;
    return 0;
  }

  long long ans=a[0];
  for(int i=1;i<n;i++){
    if (ans > 1000000000000000000/a[i]) {
      cout<<"-1"<<endl;
      return 0;
    }
    ans *= a[i];
  } 
  
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 4348
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 50000
#define INF 100000000
using namespace std;
typedef long long ll;
int t[MAX+1],c[21];
struct bags{
	int value;
	int weight;
};
vector<bags> B;
int dp[102][10002];
int main()
{	
	int n,m; 
	struct bags tian;
	cin>>n>>m;
	B.push_back(tian);
	for(int i=1;i<=n;i++)
	{
		struct bags tmp;
		cin>>tmp.value>>tmp.weight;
		B.push_back(tmp);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		dp[0][i]=0;
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j<B[i].weight)
				dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-B[i].weight]+B[i].value);
			}
		}
	cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 7080
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<iostream> 
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int x,y;
}a[100010];
bool cmp(node a,node b){return max(a.x,a.y)<max(b.x,b.y);}
int n;
long long sum,s[100010];
inline int erfen(int pos)
{
	int l=1,r=n,p=0,d=max(a[pos].x,a[pos].y);
	while(l<=r)
	{
		int mid=l+r>>1;
		long long uf=s[mid];if(mid>=pos)uf-=d;
		if(uf<=sum)p=mid,l=mid+1;
		else r=mid-1;
	}return p;
}
inline long long gcd(long long x,long long y)
{
	if(x==0)return y;
	else return gcd(y%x,x);
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)a[i].x=read(),a[i].y=read();
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		s[i]=s[i-1]+max(a[i].x,a[i].y);
		if(a[i].y>a[i].x)sum+=a[i].y-a[i].x;
	}
	long long ax=0,ay=1,x,y,ul;
	for(int i=1;i<=n;i++)
	{
		x=erfen(i);
		long long uf=sum-s[x];
		if(x>=i)
			x--,uf+=max(a[i].x,a[i].y);
		if(a[i].y>a[i].x)
			uf-=a[i].y-a[i].x;
		x=x*a[i].y+min(uf+a[i].y-a[i].x,1LL*a[i].y);
		y=1LL*n*a[i].y;
		if(x<=0)
			continue;
		ul=gcd(x,y); 
		x/=ul,y/=ul;
		if(1.0*ay*x>1.0*y*ax)
			ax=x,ay=y;//爆ll
	}
	printf("%lld %lld\n",ax,ay);
	return 0;
}


Measured memory_bytes: 5224
#include<iostream>

using namespace std;

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

int dp[100100], sum[100100], t[10];

int main() {
  int a, b, p, res;
  t[0] = 1;
  rep (i, 9) t[i + 1] = t[i] * 10;
  while (true) {
    cin >> a >> b >> p;
    if (a == 0 && b == 0 && p == 0) break;
    res = 0;
    rep (i, b - a + 1) {
      dp[i] = 1;
      int m = (a + i) / 10;
      while (a <= m && m <= b) {
	dp[i] += sum[m - a];
	dp[i] %= p;
	m /= 10;
      }
      rep (j, 10) if (a + i == t[j]) {
	sum[i] = dp[i];
	goto end;
      }
      dp[i] += i > 0 ? sum[i - 1] : 0;
      dp[i] %= p;
      sum[i] = i > 0 ? sum[i - 1] + dp[i] : dp[i];
      sum[i] %= p;
    end:;
      res += dp[i];
      res %= p;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1940
from collections import deque

H, W = map(int, input().split())

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


def r(p):
    # 追加したもののリスト
    q_list = []
    h = p // W
    w = p % W
    # 上に追加
    if h != 0:
        q_list.append(p - W)
    # 下に追加
    if h != H - 1:
        q_list.append(p + W)
    # 左に追加
    if w != 0:
        q_list.append(p - 1)
    # 右に追加
    if w != W - 1:
        q_list.append(p + 1)
    return q_list


# 距離のmax は1999
d = [2000] * (H * W)
for i in black_cells:
    d[i] = 0

# BFS like dijkstra
queue = deque(black_cells)
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        # 既存の黒の隣なら +1
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))

Measured memory_bytes: 127532
#include<bits/stdc++.h>
using namespace std;
int const MAXN=510, MAXC=35;
int n, k, v[MAXN][MAXN], c[MAXN][MAXN], poss[MAXC][3];
int get_cost(int mod, int colore){
	int res=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if((i+j)%3==mod)
				res+=c[v[i][j]][colore];
	return res;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++) for(int j=1;j<=k;j++) cin>>c[i][j];
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>v[i][j];
	for(int i=1;i<=k;i++)
		for(int j=0;j<3;j++)
			poss[i][j]=get_cost(j,i);
	int res=INT_MAX;
	for(int i=1;i<=k;i++)
		for(int j=1;j<=k;j++)
			for(int z=1;z<=k;z++)
				if(i!=j && i!=z && j!=z)
					res=min(poss[i][0]+poss[j][1]+poss[z][2],res);
	cout<<res;
}

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

using namespace std;
using ll = long long;

int const N = 100 * 1000 + 16;

int a[N];

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n;
  cin >> n;
  for(int i = 0; i < n; ++i)
    cin >> a[i];

  int mn = *min_element(a, a+n);
  int mx = *max_element(a, a+n);
  cout << mx-mn << endl;
}

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

using ll = long long;
const ll mod = 998244353;


ll dp[3030][3030][3];
int a[3030];
int main(){
  int n, k;
  cin >> n >> k;
  for(int i=0;i<n;i++)cin >> a[i];
  dp[0][0][0] = 1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=k;j++){
      (dp[i+1][j][0] += dp[i][j][0]) %= mod;
      assert(dp[i + 1][j][0] <= 1);
      (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
      (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= mod;
      if(j + a[i] <= k){
        (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
        (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= mod;
      }
    }
  }
  cout << dp[n][k][2] << endl;
}

Measured memory_bytes: 215168
N, M = map(int, input().split())

gates = [[1, N]]

for m in range(M):
  L, R = map(int, input().split())
  updated = []
  for gate in gates:
    if L <= gate[0]:
      if gate[0] <= R:
        updated.append([gate[0], min(gate[1], R)])
    else:
      if L <= gate[1]:
        updated.append([L, min(gate[1], R)])
  gates = updated


print(sum([g[1] - g[0] + 1 for g in gates]))


Measured memory_bytes: 3188
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n],b[n],c[n],dp[n][3];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    rep(i,0,n)
    rep(j,0,3)
    dp[i][j]=0;
    //cout<<dp[0][2];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1], dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0], dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0], dp[i-1][1])+c[i];
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define ll long long

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<vector<int>> neigh(N);
	vector<int> minimum(N, N);
	vector<int> way(N);
	vector<int> color(N, -1);

	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}

	queue<int> q;
	q.push(0);
	minimum[0] = 0;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int i = 0; i < neigh[v].size(); i++){
			if (minimum[neigh[v][i]] > minimum[v] + 1) {
				way[neigh[v][i]] = v;
				minimum[neigh[v][i]] = minimum[v] + 1;
				q.push(neigh[v][i]);
			}
		}
	}

	int l = minimum[N - 1] - 1;
	l /= 2;
	int v = N - 1;
	color[v] = 1;
	for (int i = 0; i < l; i++) {
		color[way[v]] = 1;
		v = way[v];
	}
	while(v != 0) {
		color[way[v]] = 0;
		v = way[v];
	}
	color[0] = 0;

	q.push(N - 1);
	while(!q.empty()) {
		int vv;
		vv = q.front();
		q.pop();
		color[vv] = 2;
		for (int i = 0; i < neigh[vv].size(); i++) {
			if (color[neigh[vv][i]] != 0 && color[neigh[vv][i]] != 2) q.push(neigh[vv][i]);
		}
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) if (color[i] == 2) cnt++;
	//cout << cnt << endl;

	int Fennec = N - cnt;
	int Snuke = cnt;

	if (Fennec > Snuke) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;

	system("pause");


	return 0;
}

Measured memory_bytes: 7160
n = int(input())
h = list(map(int,input().split()))

dp = [0,abs(h[1]-h[0])]

for i in range(2,n):
    dp.append(min(dp[i-1] + abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2])))
    
print(dp[-1])

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

def main():
    N = int(input())

    honest = [[None] * N for i in range(N)]

    for i in range(N):
        A = int(input())
        for j in range(A):
            x, y = map(int, input().split())
            honest[i][x-1] = True if y else False
    
    ans = 0
    for i in range(2**N):
        p = [False] * N
        tmp = 0
        for j in range(N):
            if i&1:
                p[j] = True
                tmp += 1
            i >>= 1
        
        # print(p)
        
        ok = True
        for j in range(N):
            if not ok:
                break
            if p[j]:# 正直者の証言の場合はhonestと一致するか調べる
                for k in range(N):
                    if (honest[j][k] == True and p[k] == False) or (honest[j][k] == False and p[k] == True):
                        ok = False
                        break
        
        if ok:
            ans = max(ans, tmp)
    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

//union find木(グループわけができる)
int par[600050];
int unifind(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
	return 0;
}
//木の根を求める
int unifind_root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = unifind_root(par[x]);
	}
}
//同じグループか判定
bool unifind_same(int x, int y) {
	return unifind_root(x) == unifind_root(y);
}
//グループ併合
int unifind_unite(int x, int y) {
	x = unifind_root(x);
	y = unifind_root(y);
	if (x == y) {
		return 0;
	}
	par[x] = y;
}
struct STRUCT{
	long long int x, y, id;
};
bool cmp(STRUCT A, STRUCT B) {
	if (A.x != B.x) { return A.x < B.x; }
	else { return A.y < B.y; }
}
int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	STRUCT tmp[200005];
	long long int N, K, L, p[200050], q[200050], res[600005] = {},p2[200050],q2[200050],now=1;
	cin >> N>>K>>L;
	unifind(600005);
	for (int i = 0; i < K; i++) {
		cin >> p[i]>>q[i];
		unifind_unite(p[i], q[i]);
	}
	for (int i = 0; i < L; i++) {
		cin >> p2[i] >> q2[i];
		unifind_unite(p2[i] + 200000, q2[i] + 200000);
	}
	for (int i = 1; i <= N; i++) {
		tmp[i].x = unifind_root(i);
		tmp[i].y = unifind_root(i+200000);
		tmp[i].id = i;
	}
	sort(tmp + 1, tmp + N + 1,cmp);
	for (int i = 1; i < N; i++) {
		if (tmp[i].x == tmp[i + 1].x && tmp[i].y == tmp[i + 1].y) {
			now++;
		}
		else {
			for (int j = i - now+1; j <= i; j++) {
				res[tmp[j].id] += now;
			}
			now = 1;
		}
	}
		
	for (int j = N - now+1; j <= N; j++) {
		res[tmp[j].id] += now;
	}
	
	for (int i = 1; i <= N; i++) {
		std::cout << res[i] << " ";
	}
}


Measured memory_bytes: 18560
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k = map(int, input().split())
a = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ord_ = [-1] * n # 何回目に訪れたか
homon = [] # 訪問した順番のリスト
current = 0
while ord_[current] == -1:
    ord_[current] = len(homon)
    homon.append(current)
    current = a[current] - 1

freq = len(homon) - ord_[current] # ループする都市数
n_before_loop = ord_[current] # ループするまでの都市数

if k < n_before_loop:
    print(homon[k] + 1)
else:
    k -= n_before_loop
    k %= freq
    print(homon[n_before_loop+k] + 1)



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

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

  vector<int> b(m);
  vector<int> a(m);

  int sum = 0;
  int flag = 0;

  rep(i, m) cin >> b.at(i);

  for (int i = 0; i < n;i++){
    sum = 0;
    rep(j, m)
    {
      cin >> a.at(j);
      sum += a.at(j) * b.at(j);
    }
    // cout << sum << endl;
    if (sum + c > 0)
      flag++;
  }

  cout << flag;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> a >> b;
  string s;std::cin >> s;
  if(s.size()==a+b+1){
    for(int i=0;i<a+b+1;i++){
      if((i==a&&s[i]!='-') || (i!=a&&(s[i]<'0'||s[i]>'9'))){
        std::cout << "No" << '\n';
        return 0;
      }
    }
    std::cout << "Yes" << '\n';
  }else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
k = int(input())
a, b = map(int,input().split())

flug = 0

A = list(range(a, b+1))

for number in A:
    if number % k == 0:
        flug = 1
        
    else:
        continue

if flug == 1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 9108
#  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D&lang=jp
#  Allocatin : python3
#  2018.12.09 yonezawa


#from collections import deque
import sys
input = sys.stdin.readline
#import cProfile

def calc(l,k,m):
    n = len(l)
    kp = 1
    mp = 0
    for i in range(n):
        if (l[i] >  m ):
            return False
        if (mp + l[i] <= m ):
            mp += l[i]
            continue
        kp += 1
        mp = l[i]
    if (kp <= k):
        return True
    else:
        return False

def binSearch(l,k):
    left = 0
    right = 100000 * 100000
    mid = right // 2
    flg = False
    while right - left > 1:
        if calc(l,k,mid) == False:
            left = mid
            flg = True
        else:
            right = mid
            flg = False
        mid =  (right + left ) // 2 
    return right


def main():
    l = []
    (n,k) = map(int,input().split())
    for i in range(n):
        l.append(int(input()))
    t = binSearch(l,k)
    print (t)

if __name__ == '__main__':
   main()
#    pr = cProfile.Profile()
#    pr.runcall(main)
#    pr.print_stats()


Measured memory_bytes: 9508
def main():
    a,b = map(int,input().split())
    def f(n):
        if n%4==0:
            return n
        if n%4==1:
            return 1
        if n%4==2:
            return n + 1
        if n%4==3:
            return 0
    print(f(b)^f(a-1))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9080
n, m, x, y = map(int, input().split())
lx = list(map(int, input().split()))
ly = list(map(int, input().split()))
z = False

for i in range(x+1, y+1):
  if i>max(lx) and i<=min(ly):
    z = True

if z:
  print("No War")
else:
  print("War")

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> sub;
  rep(i, n - 1) {
    if (a[i] < a[i + 1]) {
      sub.push_back(1);
    } else if (a[i] > a[i + 1]) {
      sub.push_back(-1);
    }
  }

  int ans = 1;
  if (sub.size() > 1)
    rep(i, sub.size() - 1) if (sub[i] != sub[i + 1]) ans++, i++;
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
int main(){
  ll N;
  cin >>N;
  vector<ll> v(5);
  
  ll m = 1000000000000000;
  for(int i = 0; i < 5; i++){
    cin >> v.at(i);
    if( m >= v.at(i)){
      m = v.at(i);
    }
  }
  ll ans;
  ans = (N + m - 1) / m + 4;
  cout << ans << endl;
  
}
  
  

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N, A, B, x;
    scanf("%d %d %d",&N, &A, &B);
    x=N*A;
    if(x>B)
    {
        printf("%d",B);
    }
    else if(x==B)
    {
        printf("%d\n",x);
    }
    else
    {
        printf("%d",x);
    }
    return 0;
}


Measured memory_bytes: 128
S = gets.chomp.chars

EVEN = S.select.with_index{|c,i|i.odd?}
ODD = S.select.with_index{|c,i|i.even?}

puts ODD.all?{|c|"RUD".include? c} && EVEN.all?{|c|"LUD".include? c} ? "Yes" : "No"

Measured memory_bytes: 1916
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int x;
    cin >> x;
    
    int a = x / 500;
    int aa = x % 500;

    int b = aa / 5;

    cout << 1000*a+5*b << endl;
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int n, d;
VV c;
V sm;

bool update() {
    V cand = sm;
    sort(all(cand));
    reverse(all(cand));
    rep(i, n) {
        if (!c[i].empty()) {
            int M, m;
            M = (sm[i] == cand[0] ? cand[1] : cand[0]);
            m = min(cand.back(), sm[i] - c[i].back());
            if (M - m <= d) {
                sm[i] -= c[i].back();
                c[i].pop_back();
                return true;
            }
        }
    }
    return false;
}

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

    while (cin >> n >> d, n) {
        c.clear();
        c.resize(n);
        rep(i, n) {
            int m;
            cin >> m;
            rep(j, m) {
                int x;
                cin >> x;
                c[i].emplace_back(x);
            }
        }
        sm.clear();
        sm.resize(n);
        rep(i, n) {
            sm[i] = accumulate(all(c[i]), 0);
        }

        while (update()) ;

        cout << (*max_element(all(sm)) <= 0 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3116
#include <iostream>

using namespace std;

int main() {
    int h, w;

    cin >> h >> w;

    string s;

    for (int i = 0; i < h; ++i) {
        cin >> s;
        for (int j = 0; j < 2; j++) {
            cout << s << endl;
        }
    }

}



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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N, K, L;

  cin >> N >> K >> L;
  UnionFind uf1(N), uf2(N);
  for(int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    uf1.unite(--p, --q);
  }
  for(int i = 0; i < L; i++) {
    int p, q;
    cin >> p >> q;
    uf2.unite(--p, --q);
  }

  map< int, map< int, int > > link;

  for(int i = 0; i < N; i++) {
    link[uf1.find(i)][uf2.find(i)]++;
  }
  for(int i = 0; i < N; i++) {
    if(i > 0) cout << " ";
    cout << link[uf1.find(i)][uf2.find(i)];
  }
  cout << endl;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


int main() {
	int n;
	cin >> n;
	n %= 10;
	if (n == 3)
		cout << "bon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;


}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


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

Measured memory_bytes: 3620
#include<stdio.h>
main(){
  float w;
  while(scanf("%f",&w)!=EOF){
    if(w<=48.0){
      printf("light fly\n");
    }
    else if(w>48.0 && w<=51.0){
      printf("fly\n");
    }
    else if(w>51.0 && w<=54.0){
      printf("bantam\n");
    }
    else if(w>51.0 && w<=54.0){
      printf("bantam\n");
    }   
    else if(w>54.0 && w<=57.0){
      printf("feather\n");
    } 
    else if(w>57.0 && w<=60.0){
      printf("light\n");
    } 
    else if(w>60.0 && w<=64.0){
      printf("light welter\n");
    }
    else if(w>64.0 && w<=69.0){
      printf("welter\n");
    }
    else if(w>69.0 && w<=75.0){
      printf("light middle\n");
    }
    else if(w>75.0 && w<=81.0){
      printf("middle\n");
    }
    else if(w>81.0 && w<=91.0){
      printf("light heavy\n");
    }
    else{
      printf("heavy\n");
    }
  }
  return 0;
}

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

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int X;
	cin >> X;
	cout << 360 / __gcd(360,X) << '\n';	
}

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

int main(){
  int n, c, k;
  cin >> n >> c >> k;
  vector<int>t(n);
  for(int i=0; i<n; i++){
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  int ret=0, bust=0, busp=2000000000;
  for(int i=0; i<n; i++){
    busp++;
    if(t[i]>bust || busp>c){
      ret++;
      bust=t[i]+k;
      busp=1;
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
using namespace std;

#define ll long long

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

Measured memory_bytes: 256
n = int(input())
l = len(str(n))

if l == 1:
    print(n)
    exit()
ans = 9
if l % 2 == 1:
    ans += n + 1 - 10 ** (l - 1)

for i in range(3,l):
    if i % 2 == 1:
       ans += 10 ** i - 10 ** (i - 1)
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;
#define PI 3.14159265358979323846

using namespace std;
int MOD = 1000000007;


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

  int n;
  cin >> n;
  double ret = (double)2.0 * M_PI * n;
  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 3224
#include "bits/stdc++.h"
using namespace std;

int n;
long long a,mn=10000000000,mx=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>mx)
			mx=a;
		if(a<mn)
			mn=a;
	}
	cout<<mx-mn;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 r,c,k;
    cin >> r >> c >> k;
    vector dp(4, vector(r+1, vector(c+1, 0LL)));
    vector rc(r+1, vector(c+1,0LL));
    for (int i=0; i<k; i++) {
        int64 r,c,v;
        cin >> r >> c >> v;
        rc[r][c] = v;
    }

    for (int64 i=1; i<=r; i++) {
        for (int64 j=1; j<=c; j++) {
            for (int64 l=0; l<4; l++) dp[0][i][j] = max(dp[0][i][j], dp[l][i-1][j]);
            for (int64 l=0; l<4; l++) dp[l][i][j] = max(dp[l][i][j], dp[l][i][j-1]);

            for (int64 l=0; l<4; l++) dp[1][i][j] = max(dp[1][i][j], dp[l][i-1][j] + rc[i][j]);
            for (int64 l=0; l<3; l++) dp[l+1][i][j] = max(dp[l+1][i][j], dp[l][i][j-1] + rc[i][j]);
        }
    }

    cout << max({dp[0][r][c], dp[1][r][c], dp[2][r][c], dp[3][r][c]}) << endl;
}

Measured memory_bytes: 355220
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	long long N,C,K;
	cin>>N>>C>>K;
	vector<long long> T(N,0);
	long long i;
	for (i=0;i<N;i++){
		cin>>T[i];
	}
	sort(T.begin(),T.end());
	bool start=true;
	long long maxTime=0;
	long long num=0;
	long long aw=0;
	for (i=0;i<N;i++){
		if (start){
			maxTime=T[i]+K;
			start=false;
			num=1;
			aw++;
		}else{
			if (num<C && T[i]<=maxTime){
				num++;
				if (num==C){
					start=true;
				}
			}else{
				start=true;
				i--;
			}
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    bool y = false;
    rep(i, 1, b + 1)
    {
        if (a * i % b == c)
            y = true;
    }
    cout << (y?"YES":"NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;


int main(){
    string s;
    cin >> s;

    REP(i, 0, s.size()){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }

    p(s);
}


Measured memory_bytes: 3724