akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using Graph = vector<vector<int>>;

const int INF = 1e9;

void NO() {
  cout << "No" << endl;
  exit(0);
}

class Tree {
 public:
  Tree(const auto& G, const auto& W) : child(G.size()), interval(G.size(), {-INF, INF}) {build(G, W);}

  void solve() {
    function<void(int)> dp = [&](int cur) {
      for(auto nex: child[cur]) {
        dp(nex);
        auto i = interval[nex];
        if(i.max != INF) {
          --i.min; ++i.max;
          if(i.max<interval[cur].min ||interval[cur].max<i.min) NO();
          if(interval[cur].max != INF) {
            if((i.min&1) != (interval[cur].min&1)) NO();
            if((i.max&1) != (interval[cur].max&1)) NO();
          }
        }
        interval[cur].min = max(interval[cur].min, i.min);
        interval[cur].max = min(interval[cur].max, i.max);
      }
    };
    dp(0);

    vector<int> ans(interval.size(), INF);
    ans[0] = interval[0].min;
    function<void(int, int)> aadp = [&](int cur, int pre) {
      if(cur != 0) {
        auto min = ans[pre] - 1;
        auto max = ans[pre] + 1;
        if(interval[cur].min <= min && min <= interval[cur].max) ans[cur] = min;
        if(interval[cur].min <= max && max <= interval[cur].max) ans[cur] = max;
        if(ans[cur] == INF) NO();
      }
      interval[cur];
      for(auto nex: child[cur]) aadp(nex, cur);
    };
    aadp(0, 0);

    cout << "Yes" << endl;
    for(auto i: ans) cout << i << endl;
  }

 private:
  struct Interval {int min, max;};

  void build(const auto& G, const auto& W) {
    function<void(int, int)> dfs = [&](auto cur, auto pre) {
      if(W[cur] != INF) interval[cur] = {W[cur], W[cur]};
      for(const auto& nex: G[cur]) if(nex != pre) {
        child[cur].emplace_back(nex);
        dfs(nex, cur);
      }
    };
    dfs(0, 0);
  }

  vector<vector<int>> child;
  vector<Interval> interval;
};

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

  Graph G(N);
  for(auto i=1; i<N; ++i) {
    int A, B;
    cin >> A >> B;
    --A; --B;
    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }

  int K;
  cin >> K;

  vector<int> W(N, INF);
  for(auto i=0; i<K; ++i) {
    int V, P;
    cin >> V >> P;
    --V;
    W[V] = P;
  }

  Tree(G, W).solve();
}


Measured memory_bytes: 21248
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, ans;

signed main(){
    cin >> N;
    for(int i = 1ll; i * i <= N; i++){
        if(N % i == 0 && N / i - 1 > i){
            ans += N / i - 1ll;
            //printf("1 x:%lld i:%lld\n", N / i - 1ll, i);
        }
    }
    cout << ans << endl;
    /*int ans2 = 0;
    for(int i = 1; i <= N; i++){
        if(N / i == N % i){
            ans2 += i;
            printf("2 x:%lld i:%lld\n", i, N / i);
        }
    }
    cout << ans2 << endl;*/

    return 0;
}
/*



*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100010];
  int ans=0;
  rep(i,n+1) cin>>a[i];
  int b[100000];
  rep(i,n) cin>>b[i];
  rep(i,n){
    if(b[i]<a[i]){
      ans+=b[i];
    }else if(b[i]<a[i]+a[i+1]){
      ans+=b[i];
      b[i]-=a[i];
      a[i+1]-=b[i];
    }else{
      ans+=a[i];
      ans+=a[i+1];
      a[i]=a[i+1]=0;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
    int n;
    
    while (scanf("%d", &n) * n != 0){
        int square[15][15] = {0};
        int i;
        int x, y;
        
        x = n / 2;
        y = n / 2 + 1;
        for (i = 1; i <= n * n; i++){
            while (x < 0 || y >= n || square[y][x] != 0){
                if (x < 0) x = n - 1;
                if (y >= n) y = 0;
                if (square[y][x] != 0) x--, y++;
            }
            square[y][x] = i;
            x++, y++;
            if (x >= n) x = 0;
            if (y >= n) y = 0;
        }
        for (y = 0; y < n; y++){
            for (x = 0; x < n; x++){
                printf("%4d", square[y][x]);
            }
            puts("");
        }
    }
    
    return 0;
}

Measured memory_bytes: 620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	double money = 100;
	for (int i = 0;i < n;++i) {
		money = money * 1.05;
		money = ceil(money);
	}
	int hoge = money;
	printf("%d000\n", hoge);
}


Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	set<string> S;
	int N;cin>>N;
	FOR(i,1,N){
		string x;cin>>x;
		S.insert(x);
	}
	cout<<sz(S);
}


Measured memory_bytes: 19200
#include<bits/stdc++.h>
#define ri register int
using namespace std;
int n,m,a[100005],f[100005],b[100005],t,c;
long long ans;
inline int read()
{
	char ch=getchar();int x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f;
}
inline int gf(ri x){return f[x]==x?x:f[x]=gf(f[x]);}
int main()
{
	n=read();m=read();for(ri i=1;i<=n;++i)a[i]=read(),f[i]=i;
	for(ri i=1,x,y;i<=m;++i)
	x=gf(read()+1),y=gf(read()+1),b[++t]=max(a[x],a[y]),a[x]=min(a[x],a[y]),f[y]=x;
	for(ri i=1;i<=n;++i)if(f[i]==i)ans+=a[i],c++;if(c==1){puts("0");return 0;}
	if(2*(c-1)>n){puts("Impossible");return 0;}sort(b+1,b+1+t);
	//for(ri i=1;i<=t;++i)cout<<b[i]<<" ";
	for(ri i=1;i<=c-2;++i)ans+=b[i];printf("%lld",ans);
	return 0;
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    vector<int> L(87);
    L[0] = 2; L[1] = 1;
    reps(i,2,86) L[i] = L[i-1] + L[i-2];
    int n; cin >> n;
    cout << L[n] << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func Min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func main() {
	var x, y int64
	fmt.Scan(&x)
	fmt.Scan(&y)
	var a [4]int64
	a[0] = y - x
	a[1] = 1 + y - (-x)
	a[2] = 2 + (-y) - (-x)
	a[3] = 1 + (-y) - x
	var ans int64 = math.MaxInt64
	for _, e := range a {
		if e < 0 {
			continue
		}
		ans = Min(ans, e)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int[]c = new int[N];
    int[]t = new int[N];
    ArrayList<Integer> A =  new ArrayList<>();

    for(int i=0; i<N; i++) {
    	c[i] = sc.nextInt();
    	t[i] = sc.nextInt();
    if(t[i]<=T) {
    	A.add(c[i]);
    }
}
    Collections.sort(A);
    if(A.size() == 0) {
    	System.out.println("TLE");
    }else {
    System.out.println(A.get(0));
    }
}
}

Measured memory_bytes: 36344
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let p: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", (a*3+p)/2);
}

Measured memory_bytes: 4352
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
using namespace std;

int main(){
    string str;
    cin >> str;
    int count = 0;
    for (auto s : str){
        if (s == '+') count += 1;
        else count -= 1;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
for i in range(N-1):
  B += [max(B[-1], A[i+1])]

ans = 0
for i in range(N):
  if A[i] == B[i]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<ll> a(n), sum(n);
  
  rep(i, n){
    cin >> a[i];
    if(i) sum[i] = sum[i-1] + a[i];
    else sum[i] = a[i];
  }

  ll res = INF;
  rep(i, n-1){
    chmin(res, abs(sum[n-1] - 2*sum[i]));
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	int o[31]={0};
	int inp;

	for(int i=0;i<28;i++){
		cin>>inp;
		o[inp]++;
	}

	for(int i=1;i<31;i++){
		if(o[i]==0) cout<<i<<endl;
	}

    return 0;
}

Measured memory_bytes: 1160
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    string s,t;
    cin >> n >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    std::vector<long long int> a(n);
    for(int i=0; i<n; i++) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    for(int i=0; i<n; i++)
    {
        if(a[i]==a[i+1])
        {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,x,y;
    cin>>n>>x>>y;
    x--;y--;
    vector<vector<int>> old(n,vector<int>(n,0));
    vector<int> ans(n,0);
    for(int i=0;i<n;i++){
        int count_ = 1;
        for(int j=i+1;j<n;j++){
            old[i][j] = count_;
            old[j][i] = count_;
            count_++;
        }
    }
    int count_ = 1;
    for(int i=y;i<n;i++){
        old[x][i] = count_;
        count_++; 
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            old[i][j] = min({old[i][j],old[i][x]+old[x][j],old[i][x]+old[x][y]+old[y][j]}); 
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans[old[i][j]]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n;
    cin >> n;
    int a[n];
    for (int& e: a) cin >> e;

    sort(a, a+n);

    int duh = 0;
    ll ans = 0;
    for (int i=1; i<n; i++) {
        if (i%2) duh++;
        ans += a[n-1-i+duh];
    }
    cout << ans << "\n";
}


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

int n,m,x,y,mx,my;
vector<int> vx,vy;

int main(){
    cin >> n >> m >> x >> y;
    vx.resize(n);
    vy.resize(m);
    for(int i = 0;i < n;++i)cin >> vx[i];
    for(int i = 0;i < m;++i)cin >> vy[i];
    mx = vx[0];
    my = vy[0];
    for(int i = 0;i < n;++i)mx = max(mx,vx[i]);
    for(int i = 0;i < m;++i)my = min(my,vy[i]);
    for(int z = x + 1;z <= y;++z)if(mx < z && my  >= z){
        cout << "No War" << endl;
        return 0;
    }
    cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,W; cin >> n >> W;
    vl v(n),w(n);
    rep(i,n) cin >> v[i] >> w[i];
    vpl fr,ba;
    rep(bit,1<<(n/2)){
        ll vs = 0, ws = 0;
        rep(i,n/2) if(bit>>i & 1) vs += v[i], ws += w[i];
        fr.emplace_back(P(ws,vs));
    }
    rep(bit,1<<(n-n/2)){
        ll vs = 0, ws = 0;
        rep(i,n-n/2) if(bit>>i & 1) vs += v[i+n/2], ws += w[i+n/2];
        ba.emplace_back(P(ws,vs));
    }
    sort(all(fr)); sort(all(ba));
    vpl ba2;
    ll mxv = -1;
    rep(bit,1<<(n-n/2)){
        if(mxv < ba[bit].second){
            ba2.emplace_back(ba[bit]);
            mxv = ba[bit].second;
        }
    }
    sort(all(ba2));
    ll ans = 0;
    for(auto i : fr){
        if(i.first > W) break;
        auto itr = upper_bound(all(ba2),P(W-i.first,linf));
        itr--;
        chmax(ans, (*itr).second + i.second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 43744
h,w,k = map(int,input().split())
C = list([] for _ in range(h))
for _ in range(h):
    C[_] = list(input())

ans =0

for s in range(2**h):
    b_h = '{:06b}'.format(s)
    for t in range(2**w):
        b_w = '{:06b}'.format(t)
        black = 0
        for i in range(h):
            for j in range(w):
                if C[i][j]=='#' and b_h[-(i+1)] == '0' and b_w[-(j+1)]=='0':
                    black += 1
        if black==k:
            ans +=1
print(ans)

Measured memory_bytes: 9152
/*
Name: ALDS1_3_C Doubly Linked List
Author: Momose Ryoya
Date: 2015.4.5
*/

#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
	int q,x;
	char com[20];
	list<int> v;
	scanf("%d",&q);
	for(int i = 0 ; i < q ; i++)
	{
		scanf("%s", com);
		if(com[0] == 'i')
		{
			scanf("%d", &x);
			v.push_front(x);
		} else if(com[6] == 'L')
		{
			v.pop_back();
		} else if(com[6] == 'F')
		{
			v.pop_front();
		} else if(com[0] == 'd')
		{
			scanf("%d", &x);
			for(list<int>::iterator it = v.begin(); it != v.end(); it++)
			{
				if(*it == x)
				{
					v.erase(it);
					break;
				}
			}
		}
	}
	int i = 0;
	for(list<int>::iterator it = v.begin(); it != v.end(); it++)
	{
		if(i++) printf(" ");
		printf("%d", *it);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 32220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static int M;
    static int[] X;
    static int[] Y;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        X = new int[M];
        Y = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = sc.nextInt() - 1;
            Y[i] = sc.nextInt() - 1;
        }

        System.out.println( solve() );
    }

    private static int solve() {
        int[] B = new int[N];
        boolean[] R = new boolean[N];
        Arrays.fill(B, 1);
        R[0] = true;

        for (int i = 0; i < M; i++) {
            int x = X[i];
            int y = Y[i];

            if( B[x] > 0 ) {
                B[x]--;
                B[y]++;
                if( R[x] ) {
                    R[y] = true;
                }
                if( B[x] == 0 ) {
                    R[x] = false;
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if( R[i] ) ans++;
        }
        return ans;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 43932
from collections import deque


queue = deque()

num, q = map(int, input().split())
for _ in range(num):
    job, time = input().split()
    queue.append([job, int(time)])

res = []
timer = 0
while queue:
    curr_job, job_time = queue.popleft()
    if job_time <= q:
        timer += job_time
        res.append([curr_job, timer])
        continue
    else:
        job_time -= q
        timer += q
        queue.append([curr_job, int(job_time)])

for job in res:
    print(*job)


Measured memory_bytes: 15104
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        long[] a = new long[100001];
        int n = in.ni();
        long k = in.nl();;
        for (int i = 0; i < n; i++) {
            a[in.ni()] += in.ni();
        }
        long sum = 0;
        int i = 0;
        int last = 0;
        while(sum < k){
            if(a[i]>0){
                last = i;
                sum += a[i];
            }
            i++;
        }
        out.println(last);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 46292
function main(input) {
    const input_array = input.split("\n");

    const coins_count = input_array.slice(0,3);
    const desired_sum = parseInt(input_array.slice(-1), 10);
    const A = parseInt(input_array[0], 10),
          B = parseInt(input_array[1], 10),
          C = parseInt(input_array[2], 10),
          X = parseInt(input_array[3], 10);

    var count = 0;

    for (var a = 0; a <= A; ++a) {
        for (var b = 0; b <= B; ++b) {
            for (var c = 0; c <= C; ++c) {
                var sum = (a * 500) + (b * 100) + (c * 50);
                if (sum === X) ++count;
            }
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 7372
n = int(input())
a_L = list(map(int,input().split()))

diff_L = []

for t in range(n):
    sum1 = sum(a_L[:t])
    sum2 = sum(a_L[t:])
    diff_L.append(abs(sum1-sum2))

print(sorted(diff_L)[0])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef long double ld;

void solve () {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll lcm = 1, sum = 0;
    for (ll i = 0; i < n; i++) {lcm = (a[i] * lcm) / (__gcd(lcm, a[i]));}
    for (ll i = 0; i < n; i++) {sum += (lcm / a[i]);}
    cout << (ld)lcm / sum;
}


int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


vi hashc[200005];

int main() {
    int N; cin >> N;
    rep(i, N) {
        int c; cin >> c;
        hashc[c].pb(i);
    }

    vi next(N, -1);

    rep(c, 200005) {
        int n = hashc[c].size();
        if (n <= 1) continue;
        for (int i = n - 1 ; i >= 0; i--) {
            if (i == n - 1) continue;
            if (hashc[c][i + 1] > hashc[c][i] + 1) {
                next[hashc[c][i]] = hashc[c][i + 1];
            }
        }
    }

    vll dp(N, 0);
    dp[N - 1] = 1;
    for (int i = N - 2 ; i >= 0 ; i--) {
        dp[i] = dp[i + 1];
        if (next[i] != -1) dp[i] += dp[next[i]];
        dp[i] %= MOD;

    }

    cout << dp[0] << endl;

}

Measured memory_bytes: 13568
#include <cstring>
#include <cstdio>
const int N=10005,mo=998244353;
long long f[N],fac[N],inv[N];
char a[N],b[N];
int ksm(int x,int y){
	int i=1;
	for (;y;y>>=1,x=1ll*x*x%mo)
		if (y&1) i=1ll*i*x%mo;
	return i;
}
void Pre(int n){
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;
	inv[n]=ksm(fac[n],mo-2);
	for (int i=n;i>=1;i--) inv[i-1]=inv[i]*i%mo;
}
int C(int n,int m){
	return fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int main(){
	scanf("%s%s",a,b);
	int len=strlen(a),n=0,m=0;
	for (int i=0;i<len;i++)
		if (a[i]=='1') b[i]=='1'?n++:m++;
	f[0]=1;
	for (int j=1;j<=m;j++){
		f[0]=f[0]*j*j%mo;
		for (int i=1;i<=n;i++)
			f[i]=(f[i]*j+f[i-1]*i)*j%mo;
	}
	Pre(n+m);
	int ans=0;
	for (int i=0;i<=n;i++)
		ans=(ans+C(n,i)*fac[i]%mo*fac[i]%mo*f[n-i]%mo*C(n+m,i))%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int a, b;
    cin >> a >> b;
    if(b > a){
        rep(i, b) cout << a;
    }
    else{
        rep(i, a) cout << b;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll INF = (1LL << 31) - 1;
struct RUQ {
  int N, K;
  vector<ll> data;
  vector<ll> lazyUpdate; // -1ならupdateしない
  RUQ(int N): N(N) {
    K = sqrt(N) + 1;
    data.resize(K * K + 1, INF);
    lazyUpdate.resize(K + 1, -1);
  }

  // kは分割した配列のindex
  void evil(int k) {
    if(lazyUpdate[k] != -1) {
      for(int i = k * K; i < (k + 1) * K; i++) {
        data[i] = lazyUpdate[k];
      }
      lazyUpdate[k] = -1;
    }
  }

  // [s, t)
  void update(int s, int t, int x) {
    for(int k = 0; k < K; k++) {
      int l = k * K, r = (k + 1) * K;
      // 区間でない
      if(r <= s || t <= l) continue;
      // 完全に含まれている
      if(s <= l && r <= t) {
        lazyUpdate[k] = x;
      } else {
        evil(k);
        for(int i = max(s, l); i < min(t, r); i++) {
          data[i] = x;
        }
      }
    }
  }

  int find(int i) {
    int k = i / K;
    evil(k);
    return data[i];
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  RUQ ruq(n);
  FOR(i,0,q) {
    ll a,s,t,x;
    cin>>a;
    if(a){
      cin>>s;
      cout<<ruq.find(s)<<endl;
    } else {
      cin>>s>>t>>x;
      ruq.update(s,t+1,x);
    }
  }
}


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

int main(){
	int input;
	cin >> input;
	
	int h = input / 3600;
	int m = input % 3600 / 60;
	int s = input % 3600 % 60 % 60;
	cout << h  << ":" << m << ":" << s << endl;
    return 0;
}

Measured memory_bytes: 1164
import bisect,collections,copy,heapq,itertools,math,string
import sys
def I():
    # 1 line 1 int
    return int(sys.stdin.readline().rstrip())
def LI():
    # 1 line n ints
    return list(map(int,sys.stdin.readline().rstrip().split()))
def S():
    # 1 line 1 string
    return sys.stdin.readline().rstrip()
def LS():
    # 1 line n strings
    return list(sys.stdin.readline().rstrip().split())

A = LS()
X = A[0]
Y = A[1]
if X < Y:
    print("<")
elif X == Y:
    print("=")
else:
    print(">")

Measured memory_bytes: 9952
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x1 = Integer.parseInt(sc.next());
        int y1 = Integer.parseInt(sc.next());
        int x2 = Integer.parseInt(sc.next());
        int y2 = Integer.parseInt(sc.next());
        
        int x3 = x2 + y1 - y2;
        int y3 = y2 + x2 - x1;
        int x4 = x1 + y1 - y2;
        int y4 = y1 + x2 - x1;
        
        System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
    }
}

Measured memory_bytes: 23764
def submit():
    n, k = map(int, input().split())
    hlist = [int(input()) for _ in range(n)]

    hlist.sort()
    min_diff = float('inf')
    for i in range(0, n - k + 1):
        minh = hlist[i]
        maxh = hlist[i + k - 1]
        if maxh - minh < min_diff:
            min_diff = maxh - minh

    print(min_diff)
        

if __name__ == "__main__":
    submit()

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

int H, A[2000000];

void Maxheapify(int i) {
    int largest = i;
    int l = 2*i;
    int r = 2*i+1;
    if (l <= H && A[l] > A[i])  largest = l;
    if (r <= H && A[r] > A[largest])  largest = r;
    if (largest != i) {
        swap(A[i], A[largest]);
        Maxheapify(largest);
    }
}

int main() {
    cin >> H;
    for (int i=1; i<=H; i++)  cin >> A[i];
    for (int i=H/2; i>=1; i--)  Maxheapify(i);
    for (int i=1; i<=H; i++)  cout << " " << A[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 5032
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

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

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c[i][j];
    }
  }
  vector<vector<int>> dp(H, vector<int>(W));
  bool is_clean_exist = 0;
  for (int i = 0; i < H; i++) {
    if (c[i][0] != 1) {
      dp[i][0] = 1;
      is_clean_exist = 1;
    }
  }
  for (int i = 0; i < W; i++) {
    if (c[0][i] != 1) {
      dp[0][i] = 1;
      is_clean_exist = 1;
    }
  }
  int mx = is_clean_exist;
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (c[i][j] == 1) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = min(min(dp[i - 1][j - 1], dp[i - 1][j]), dp[i][j - 1]) + 1;
      mx = max(mx, dp[i][j]);
    }
  }
  // debug(dp);
  int64 ans = pow(mx, 2);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 18188
import java.util.*

fun main(omkar: Array<String>) {
    val n = readLine()!!.toInt()
    val adj = arrayOf(mutableListOf<Int>()) + Array(n) {
        val line = "0" + readLine()!!
        val res = mutableListOf<Int>()
        for (j in 1..n) {
            if (line[j] == '1') {
                res.add(j)
            }
        }
        res
    }
    val q = LinkedList<Int>()
    q.add(1)
    val dist = IntArray(n + 1) { -1 }
    dist[1] = 0
    while (q.isNotEmpty()) {
        val a = q.removeFirst()
        for (b in adj[a]) {
            if (dist[b] == -1) {
                dist[b] = dist[a] + 1
                q.add(b)
            } else if ((dist[a] + 1 + dist[b]) % 2 != 0) {
                println(-1)
                return
            }
        }
    }
    var answer = 0
    for (r in 1..n) {
        //println("adj[$r] = ${adj[r]}")
        dist.fill(-1)
        dist[r] = 1
        q.add(r)
        while (q.isNotEmpty()) {
            val a = q.removeFirst()
            for (b in adj[a]) {
                if (dist[b] == -1) {
                    dist[b] = dist[a] + 1
                    q.add(b)
                }
            }
        }
        //println("r = $r, dist = ${dist.contentToString()}")
        answer = Math.max(answer, dist.max()!!)
    }
    println(answer)
}

Measured memory_bytes: 42224
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))

using namespace std;

int main(){

    int a,b,c,x,y;

    cin >> a >> b >> c >> x >> y;

    x = x * 2;
    y = y * 2;

    ll ans = LLONG_MAX;

    rep(i,max(x,y) + 1){

        ll needx = max((ll)0,(x - i + 1) / 2);
        ll needy = max((ll)0,(y - i + 1) / 2);

        ans = min(ans, needx * a + needy * b + i * c);
    }

    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;

int main(void) {
    const string CLECT = "CODEFESTIVAL2016";
    string C;
    cin >> C;
    int ans = 0;
    for (int index = 0; index < CLECT.length(); ++index) {
        if (CLECT[index] != C[index])
            ans++;
    }
        cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = 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 CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[125252];
int b[125252];

int main(){
    scanf("%d",&n);
    REP(i,n+1)scanf("%d",a+i);
    REP(i,n)scanf("%d",b+i);
    ll ans = 0;
    REP(i,n){
        int sb = min(a[i], b[i]);
        a[i] -= sb;
        b[i] -= sb;
        ans += sb;
        sb = min(a[i+1], b[i]);
        a[i+1] -= sb;
        b[i] -= sb;
        ans += sb;
    }
    printf("%lld\n",ans);
    return 0;
}


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

//thanks to pyf ...
//thanks to qhl ...

vector<pair<int, int> > v;

int main()
{
	ios :: sync_with_stdio(false);
	int n, k;
	while (cin >> n >> k)
	{
		v.clear();
		long long ans = 0;
		for (int i = 0; i < n; i++)
		{
			int a, b;
			cin >> a >> b;
			v.push_back(make_pair(a, b));
			if ((a & k) == a)
				ans += b;
		}
		for (int i = 30; i >= 0; i--)
		{
			if ((k & (1 << i)) == 0)
				continue;
			int tar = ((k ^ (1 << i)) | ((1 << i) - 1));
			long long temp = 0;
			for (int i = 0; i < n; i++)
			{
				int a = v[i].first;
				int b = v[i].second;
				if ((a & tar) == a)
					temp += b;
			}
			ans = max(ans, temp);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1528
#include <iostream>

using namespace std;

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

	if (M % 2 == 0) {
		int d = 1;
		for (int i = M / 2; i > 0; --i) {
			cout << i << " " << i + d << endl;
			d += 2;
		}
		d = 2;
		for (int i = M + M / 2; i > M; --i) {
			cout << i << " " << i + d << endl;
			d += 2;
		}
	}
	else {
		int d = 1;
		for (int i = (M + 1) / 2; i > 0; --i) {
			cout << i << " " << i + d << endl;
			d += 2;
		}
		d = 2;
		for (int i = M + (M + 1) / 2; i > M + 1; --i) {
			cout << i << " " << i + d << endl;
			d += 2;
		}
	}
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define  ft   ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  ll   long long
#define  pb   push_back
#define  ll   long long
#define  mk   make_pair
#define  msi  map<string,int>
#define  mii  map<int,int>
#define  pii  pair<int,int>
const int N=2e5+3;
string s,p;

int main()
{
    ft
    ll t,i,j,n,m;
    cin>>n>>m;
    if(n>9)
    {
        cout<<m<<"\n";
    }
    else
    {
        cout<<(m+100*(10-n))<<"\n";
    }
    return 0;
}


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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n;i++)cin>>b[i];
  ll c[n];
  for(i=0;i<n;i++)c[i]=a[i]-b[i];
  sort(c,c+n);
  ll s1=0,s2=0;
  for(i=0;i<n;i++){
    if(c[i]>0)s1+=c[i];
    if(c[i]<0)s2-=c[i]/2;
  }
  if(s1<=s2)cout<<"Yes";
  else cout<<"No";
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s,t;
    cin >> s >> t;
    vector<vector<int> > dp(s.size()+1, vector<int>(t.size()+1));
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }

    string res;
    int x = s.size(), y = t.size();
    while (x || y) {
        if (x && dp[x-1][y] == dp[x][y])
            x--;
        else if (y && dp[x][y-1] == dp[x][y])
            y--;
        else {
            x--, y--;
            res += s[x];
        }
    }
    reverse(all(res));
    cout<<res<<endl;
    return 0;
}

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

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

  // ここにプログラムを追記
  bool Y = false;
  for(int i = 0; i< N ; i++){
    string x;
    cin >> x;
    if(x == "Y"){Y = true; break;}
    
  }
  if(Y){cout << "Four"<< endl;}
  else{cout << "Three"<< endl;}
}

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

int n;
int parent[100000];
int r[100000]; //rank

void init(int n){
  for(int i = 0;i < n;i++){
    parent[i] = i;
    r[i] = 0;
  }
}

int find(int x){
  if(parent[x] == x) return x;
  else return parent[x] = find(parent[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  
  if(x == y) return ;
  
  if(r[x] < r[y]) parent[x] = y;
  else{
    parent[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

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

int main(){
  
  int m, q, s, t;
  
  cin >> n >> m;
  init(n);
  for(int i = 0;i < m;i++){
    cin >> s >> t;
    unite(s, t);
  }
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> s >> t;
    if(same(s, t)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  
  return 0;
}
 



Measured memory_bytes: 3868
#include <iostream>
#include <set>
#include <numeric> 
#include <vector> 
#include <algorithm>
#include <cstring>
#include <map>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int sz = 1e5 + 10;
int n;
string s;

int main() {

    while (cin >> s) {
        puts((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No");
    }
    
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool ok = false;
    for (int i=1; i<=b; i++) {
        if (a*i%b==c) {
            ok = true;
            break;
        }
    }
    if (ok) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : ads1_2_c_StableSort.cpp
// Author      : lovesaemi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

struct Card {
	char suit, value;
};

void bubble(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j].value < A[j - 1].value) {
				Card t = A[j];
				A[j] = A[j - 1];
				A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j].value < A[minj].value)
				minj = j;
		}
		Card t = A[i];
		A[i] = A[minj];
		A[minj] = t;
	}
}

void print(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0)
			cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card c1[], struct Card c2[], int N) {
	for (int i = 0; i < N; i++) {
		if (c1[i].suit != c2[i].suit) {
			return false;
		}
	}
	return true;
}

int main() {
	Card c1[100], c2[100];
	int N;
	char ch;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> c1[i].suit >> c1[i].value;
	}
	for (int i = 0; i < N; i++) {
		c2[i] = c1[i];
	}
	bubble(c1, N);
	selection(c2, N);
	print(c1, N);
	cout << "Stable" << endl;
	print(c2, N);
	if (isStable(c1, c2, N)) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
}



Measured memory_bytes: 3092
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;

typedef map<int, int> M;

const int MAX_N = 1000;
const int MAX_W = 10000;

int dp[MAX_N + 1][MAX_W + 1];

int main()
{
    int times = 1;
    while (1) {
        int lim;
        cin >> lim;
        if (lim == 0) break;
        int n;
        cin >> n;
        int v[MAX_N], w[MAX_N];
        for (int i = 0; i < n; i++)
            scanf("%d,%d", &v[i], &w[i]);

        M m;
        for (int i = n -1; i >= 0; i--) {
            for (int j = 0; j <= lim; j++) {
                if (j < w[i]) dp[i][j] = dp[i + 1][j];
                else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
                if (m[dp[i][j]] == 0 || m[dp[i][j]] > j ) m[dp[i][j]] = j;
            }
        }
        cout << "Case " << times << ":" << endl << dp[0][lim] << endl << m[dp[0][lim]] << endl;
        times++;
    }

    return 0;
}

Measured memory_bytes: 39048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
  cin >> N;

  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = (N - a * 1000 - b * 100 - c * 10);
  if ((a == b && b == c) || (b == c && c== d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int m = 1001001001;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (m < p[i]) continue;
    cnt++;
    m = p[i];
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << (a + b / 2) << "\n";

    return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int binpow(int a, int n) {
    if (n == 0) return 1;
    else if (n & 1)
        return (binpow(a, n - 1) * a) % MOD;
    else
        return (binpow(a, n / 2) * binpow(a, n / 2)) % MOD;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    int dp[k + 1];
    for (int i = k; i >= 1; --i) {
        int total = k / i;
        int cur = binpow(total, n);
        for (int j = 2 * i; j <= k; j += i) cur = (cur - dp[j] + MOD) % MOD;
        dp[i] = cur;
    }
    int ans = 0;
    for (int i = 1; i <= k; ++i)
        ans = (ans + i * dp[i]) % MOD;
    cout << ans;
    return 0;
}


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

#define INF INT_MAX

using namespace std;

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

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

	int N;
	cin >> N;
	
	vector<int> d(N);
	for(int i = 0;i<N;i++){
		cin >> d[i];
	}
	sort(d.begin(),d.end());

	cout << d[d.size()/2] - d[d.size()/2-1] << endl;

	return 0;
}

Measured memory_bytes: 640
n = int(input())
abcs = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*3 for _ in range(n)]
dp[0] = abcs[0]
mapping = [[1, 2], [2, 0], [0, 1]]
for i, abc in enumerate(abcs[1:], 1):
    di = dp[i-1]
    for j, happiness in enumerate(abc):
        k1, k2 = mapping[j]
        dp[i][j] = max(di[k1], di[k2])+happiness
print(max(dp[n-1]))

Measured memory_bytes: 74584