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

#define int ll

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int32_t main() {
	string s;
	cin >> s;
	cout << s.substr(0, 3) << '\n';
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<sstream>
#include<cstdio>
#include<algorithm>

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;


int main() {
    ll N;cin >> N;
    N--;
    string s = "abcdefghijklmnopqrstuvwxyz";
    string a = "";

    char tmp = s[N % 26];
    a += tmp;
    N /= 26;

    while(N > 0){
        N--;
        char tmp = s[N % 26];
        a += tmp;
        N /= 26;
    }

    reverse(a.begin(), a.end());
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3600
#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>;
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; }

using Graph = vector<vector<int>>;

#define REP(i,n) for(int i=0;i<(n);++i)
class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<long long> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        long long show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    REP(i, n) par[i] = i;
    REP(i, n) ran[i] = 0;
    REP(i, n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    long long t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

long long union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    union_find uf(n);
    Graph Fri(n);
    rep(i,m){
    	int a, b;
    	cin >> a >> b;
    	a--; b--;
    	uf.unite(a, b);
    	Fri[a].push_back(b);
    	Fri[b].push_back(a);
    }
    Graph Blo(n);
    rep(i,k){
    	int c, d;
    	cin >> c >> d;
    	c--; d--;
    	Blo[c].push_back(d);
    	Blo[d].push_back(c);
    }
    rep(i,n){
    	int ans = uf.show_size(i);
    	ans--;
    	for(auto fr : Fri[i]){
    		if(uf.same(i, fr)) ans--;
    	}
    	for(auto bl : Blo[i]){
    		if(uf.same(i, bl)) ans--;
    	}
    	cout << ans;
    	if(i != n-1) cout << " ";
    	else cout << endl;
    }
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int f(int in) {
    if(in % 2 == 0) return in / 2;
    return 3 * in + 1;
}

int main() {
    //cout.precision(10);
    int s;
    cin >> s;
    int inv[1000002];
    inv[s] = 1;
    for(int i = 2; i <= 1000000; i++) {
        s = f(s);
        if(inv[s] != 0) {
            cout << i << endl;
            return 0;
        }
        inv[s] = i;
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) cin >> vec.at(i);
  int ans = 0;
  for(int i=0; i < N - 1; i++){
    for(int j= i + 1; j < N; j++){
      ans += vec.at(i) * vec.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

from math import factorial
mod =(10**9) + 7
# v_n = 1
# for i in range(1,n+1):
#     v_n*= i%mod
# v_m = 1
# for j in range(1,m+1):
#     v_m*= j%mod

v_n = factorial(n)
v_m = factorial(m)
if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>=2:
    print(0)

else:
    ans = (v_n * v_m)%mod
    print(ans)

Measured memory_bytes: 5184
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
	int a, b;
	int d, r;
	double f;
	
	cin >> a >> b;
	cout << a/b << ' ' << a%b;
	f = (double)a/b;
	cout << ' ' << fixed << f << endl;
	
	return 0;
}


Measured memory_bytes: 3276
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;


int main(){
    string S;
    int Q;
    cin>>S;
    cin>>Q;
    vector<string> Queries;
    string query;

    for(int i=0;i<=Q;i++){
        getline(cin,query);
        Queries.push_back(query);
    }

    bool rotated=false;
    string A,B,C;

    for(int i=1;i<=Q;i++){
        A=Queries[i][0];
        if(A=="1"){
            rotated=!rotated;
        }else{
            B=Queries[i][2];
            C=Queries[i][4];
            if(rotated){
                if(B=="2"){
                    S.insert(0,C);
                }else{
                    S+=C;
                }
            }else{
                if(B=="2"){
                    S+=C;
                }else{
                    S.insert(0,C);
                }
            }
        }
    }
    if(rotated){
        reverse(S.begin(),S.end());
    }
    cout<<S;

}



Measured memory_bytes: 13552
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;

class Program
{
    const int MOD = 1000000007;
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        decimal W = (decimal)cin.NextInt();
        decimal H = (decimal)cin.NextInt();
        decimal x = (decimal)cin.NextInt();
        decimal y = (decimal)cin.NextInt();

        decimal area = W * H;

        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        if (W / 2 == x && H / 2 == y)
        {
            Console.WriteLine("{0} {1}", area / 2, 1);
        }
        else
        {
            Console.WriteLine("{0} {1}", area / 2, 0);
        }

        Console.Out.Flush();
        
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll h, n,sum=0;
    cin >>h>> n;
    vector<ll> a(n);
    for (ll i = 0; i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum<h){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}


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

int main(){
    int n;
    cin>>n;
    if(n==25)cout<<"Christmas"<<endl;
    if(n==24)cout<<"Christmas Eve"<<endl;
    if(n==23)cout<<"Christmas Eve Eve"<<endl;
    if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;

}

Measured memory_bytes: 256
fun main() = Thread(null, ::abc173d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val sortedDesc = aList.sortedDescending()

    val answer = (0 until n - 1).map { sortedDesc[(it + 1) / 2] }.sum()

    println(answer)
}


Measured memory_bytes: 75976
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> a(N);

ll tmp,tmp1;
  for(ll i=0;i<M;i++){
cin>>tmp>>tmp1;
  a[--tmp]++;
  a[--tmp1]++;
  }

ll f=1;
  for(ll i=0;i<N;i++){
if(a[i]%2==1){
  f=0;
  break;
}
  }

  if(f==1){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }


}



Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
n = int(input())
abc = [list(map(int,input().split())) for _ in range(n-1)]
q,k = map(int,input().split())
query = [list(map(int,input().split())) for _ in range(q)]

point = [[] for _ in range(n+1)]
for l in abc:
  point[l[0]].append([l[1],l[2]])
  point[l[1]].append([l[0],l[2]])

done = set()
done.add(k)
d = [0]*(n+1)
lst = [k]

while lst:
  start = lst.pop()
  for l in point[start]:
    if l[0] not in done:
      d[l[0]] = d[start] + l[1]
      done.add(l[0])
      lst.append(l[0])

for l in query:
  print(d[l[0]]+d[l[1]])

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> food;
  food.resize(M);
  for(int i = 0;i < N;i++){
    int K;
    cin >> K;
    for(int j = 0;j<K;j++){
      int input;
      cin >> input;
      food[input-1]++;
    }
  }
  int ret = 0;
  for(int i=0;i<M;i++){
    if(food[i] == N){
      ret++;
    }
  }
  cout << ret << endl;
}


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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

ll ans[200000];

int main(){
	int n,K;cin>>n>>K;
	for(ll i=1;i<=K;i++){
		ll cnt=K/i;
		ans[i]=ppow(cnt,n);
	}
	ll res=0;
	for(int i=K;i>=1;i--){
		for(int j=i*2;j<=K;j+=i){
			(ans[i]+=MOD-ans[j])%=MOD;
		}
		(res+=i*(ll)(ans[i]))%=MOD;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(1){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
string s;
int k;
int dp[105][5][2] = {{{0}}};
void solve() {
	cin >> s;
	int n = (int) s.size();
	cin >> k;
	dp[0][0][0] = 1;
	s = '$' + s;
	for (int i = 1; i <= n; i++) {
		for (char here = '0'; here <= '9'; ++here) {
			for (int done = 0; done < 2; ++done) {
				if (!done and here > s[i])
					continue;
				for (int cnt = 0; cnt <= k; ++cnt) {
					int new_cnt = cnt;
					if (here != '0')
						++new_cnt;
					int new_done = done;
					if (!done and here < s[i])
						new_done = 1;
					dp[i][new_cnt][new_done] += dp[i - 1][cnt][done];
				}
			}
		}
	}
	cout << dp[n][k][0] + dp[n][k][1];
}   

Measured memory_bytes: 256
import string
s = input()
t = input()
n = len(s)
trans = {c:['', ''] for c in string.ascii_lowercase}

for i in range(n):
    if trans[s[i]][1] == '':
        trans[s[i]][1] = t[i]
        if trans[t[i]][0] != '' and trans[t[i]][0] != s[i]:
            print('No')
            exit()
        trans[t[i]][0] = s[i]
    if trans[s[i]][1] != t[i] or trans[t[i]][0] != s[i]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int n,m;
int a[51][51];
bool d[51][51];

void dfs(int nx, int ny) {
  d[nx][ny]=true;
  REP(i,-1,2) {
    REP(j,-1,2) {
      int x=nx+i,y=ny+j;
      if(check(n,m,x,y) && a[x][y] && !d[x][y]) dfs(x,y);
    }
  }
}

int main() {
  while(cin >> m >> n && (n||m)) {
    rep(i,n) {
      rep(j,m) cin >> a[i][j];
    }
    memset(d,false,sizeof(d));
    int cnt=0;
    rep(i,n) {
      rep(j,m) {
	if(!d[i][j] && a[i][j]) {
	  cnt++;
	  dfs(i,j);
	}
      }
    }
    pr(cnt);
  }
  return 0;
}


Measured memory_bytes: 1352
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		int[] nums = new int[5];
		for(int i = 0; i < 5; i++){
			nums[i] = scan.nextInt();
		}

		for(int i = 0; i < 5 - 1; i++){
			for(int j = 5 - 1; j > i; j--){
				if(nums[i] < nums[j]){
					int big = nums[j];
					nums[j] = nums[i];
					nums[i] = big;
				}
			}
		}
		System.out.printf("%d %d %d %d %d\n", nums[0], nums[1], nums[2],
							nums[3], nums[4]);
	}
}

Measured memory_bytes: 26224
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define VEC(kata, num) (kata*)malloc(num * sizeof(kata))
#define DB puts("ok")
#define SENTINEL 1000000007
typedef long long lli;

int main()
{
    int n, m, c, i, j, ans=0;
    int a[20][20], b[20];
    scanf("%d%d%d",&n,&m,&c);
    for(i=0; i<m; i++) {
        scanf("%d",&b[i]);
    }
    for(i=0; i<n; i++) {
        int sum = c;
        for(j=0; j<m; j++) {
            scanf("%d",&a[i][j]);
            sum += a[i][j] * b[j];
        }
        if(sum > 0)ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;


ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	// 前処理
	COMinit();

	ll N, M, K;

	cin >> N >> M >> K;

	ll A = COM(N*M - 2, K - 2);

	ll X = 0;
	for (ll i = 1; i <= N - 1; i++) { X += i * (N - i); X %= MOD; }

	ll B = X *M % MOD *M %MOD;

	X = 0;
	for (ll i = 1; i <= M - 1; i++) { X += i * (M - i); X %= MOD; }

	ll C = X *N % MOD *N %MOD;

	cout << A * (B + C) % MOD;

	system("PAUSE");

}

Measured memory_bytes: 9848
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    C = [0] * N
    for i in range(len(A)):
        C[A[i] - 1] += 1

    for j in range(N):
        print(C[j])


resolve()

Measured memory_bytes: 92788
#include <bits/stdc++.h>
using namespace std;
// C - Candies

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

    vector<vector<int>> a(2, vector<int>(n));
    for(int i=0;i<2;i++){
        for(int j=0; j<n;j++){
            cin >> a.at(i).at(j);
        }
    }
    // 2*n の行列でいつのタイミングで下に移動するかn通りある
    int ans = 0;
    for(int i=0;i<n;i++){
        int res=0;
        for(int j=0;j<=i;j++) res+=a.at(0).at(j);
        for(int k=i;k<n;k++) res+=a.at(1).at(k);
        if(ans<res) ans=res;
    }
    cout <<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>


using namespace std;

int n, m, ans;
vector<int> edge[110000];
bool done[110000];

void dfs(int u) {
  done[u] = true;
  for (int v: edge[u]) {
    if (done[v]) continue;
    dfs(v);
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  
  for (int i = 0; i < n; i++) {
    if (done[i]) continue;
    dfs(i);
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main(){
	int s,d,i,n;
	while(cin>>d){
		n=600/d;
		s=0;
		for(int i=0;i<n;i++){
			s+=d*d*d*i*i;
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1160
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int t = sc.nextInt();
		int[] x = new int[n];
		int[] w = new int[n];
		for(int i=0; i<n; i++){
			x[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}

		int cnt = 0;
		for(int i=1; i<n; i++){
			if(w[0]==1 && w[i]==2){
				if(t*2>=x[i]-x[0]){
					cnt += (1+(t*2-x[i]+x[0])/l);
				}
			}
			else if(w[0]==2 && w[i]==1){
				if(t*2>=l-x[i]+x[0]){
					cnt -= (1+(t*2-l+x[i]-x[0])/l);
				}
			}
		}
		if(w[0]==1){
			cnt %= n;
		}
		else{
			cnt = ((cnt%n)+n)%n;
		}

		for(int i=0; i<n; i++){
			if(w[i]==1){
				x[i] = (x[i]+t)%l;
			}
			else{
				x[i] = ((x[i]-t)%l+l)%l;
			}
		}
		int dist0 = x[0];
		Arrays.sort(x);
		int index0 = 0;
		if(w[0]==1){
			for(int i=n-1; i>=0; i--){
				if(x[i]==dist0){
					index0 = i;
					break;
				}
			}
		}
		else{
			for(int i=0; i<n; i++){
				if(x[i]==dist0){
					index0 = i;
					break;
				}
			}
		}
		for(int i=0; i<n; i++){
			System.out.println(x[(index0-cnt+n+i)%n]);
		}
	}
}

Measured memory_bytes: 100900
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define str string
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
#define popcount __builtin_popcountll
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve() {
	string S; cin >> S;
	string ans = "Yes";
	if (S[2] != S[3]) ans = "No";
	if (S[4] != S[5]) ans = "No";
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        double pi = acos(-1);
        double r;
        scanf("%lf", &r);
        printf("%.10f\n", 2 * pi * r);
    }
} NSPACE;
int main() {
    FPEN;
    // ios_base::sync_with_stdio(false);
    // cout.tie(0);
    // cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 3780
program aaa;
var
  n,d,x,i,m:longint;
begin
  readln(n,d,x);
  dec(d);
  for i:=1 to n do
  begin
    readln(m);
    x:=x+1+d div m;
  end;
  writeln(x);
  readln;
  readln;
end.       

Measured memory_bytes: 128
H, W = map(int, input().split())
C = []
for _ in range(10):
    C.append(list(map(int, input().split())))

# solve
for k in range(10):
    for i in range(10):
        for j in range(10):
            if C[i][j] > C[i][k] + C[k][j]:
                C[i][j] = C[i][k] + C[k][j]

from collections import Counter
cnt = Counter()
for __ in range(H):
    # A.append(list(map(int, input().split())))
    cnt.update(list(map(int, input().split())))

ans = 0
for i in cnt.keys():
    if i == -1:
        continue
    ans += C[i][1] * cnt[i]

print(ans)

Measured memory_bytes: 9488
<?php
  fscanf(STDIN,"%d",$a);
  $array = explode(" ",fgets(STDIN));
  $order_array = $array;
  $total_cnt = 0;
  $total_cnt_abs = 0;
  $sign  = 0;
  $through = 0;
  $ans = 0;

  //数からiを引いて均す
  for($i=0;$i<$a;$i++)
  {
    $order_array[$i] = (int)$array[$i] - ($i+1);
    $total_cnt_abs += abs($order_array[$i]);
    if($order_array[$i] > 0)
    {
      $total_cnt++;
    }
    else if($order_array[$i] < 0)
    {
      $total_cnt--;
    }
  }
  if($total_cnt > 0)
  {
    $sign = 1;
  }
  else if($total_cnt < 0)
  {
    $sign = -1;
  }
  else
  {
    //同数だった場合は合計を出力
    $ans = $total_cnt_abs;
    $through = 1;
  }
  if($through == 0)
  {
    $center = 0;
  	$sort_array = $order_array;
    sort($sort_array);//昇順でソート
	$center = ($sort_array[floor(count($sort_array)/2)]);//偶数でもまあいいや
    
    //本計算
    $total_cnt_abs = 0;
    
    for($i=0;$i<$a;$i++)
    {
      $order_array[$i] -= $center;
      $total_cnt_abs += abs($order_array[$i]);
    }
    $ans = $total_cnt_abs;
  }
  echo $ans;

Measured memory_bytes: 96460
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int z = Integer.parseInt(sc.next());
        int ans = ((x-z) / (y+z));
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val list = readLine()!!.split(' ').map { it.toInt() }

    val (sortedList, cnt) = mergeSort(list)

    println(sortedList.joinToString(" "))
    println(cnt)
}

private fun mergeSort(list: List<Int>): Pair<List<Int>, Int> {

    val array = list.toIntArray()
    var cnt = 0

    fun merge(left: Int, mid: Int, right: Int) {

        val leftArray = IntArray(mid - left + 1) { Int.MAX_VALUE }
        for (i in (0 until mid - left)) {
            leftArray[i] = array[left + i]
        }

        val rightArray = IntArray(right - mid + 1) { Int.MAX_VALUE }
        for (i in (0 until right - mid)) {
            rightArray[i] = array[mid + i]
        }

        var i = 0
        var j = 0

        for (k in left until right) {
            cnt++
            if (leftArray[i] <= rightArray[j]) {
                array[k] = leftArray[i++]
            } else {
                array[k] = rightArray[j++]
            }
        }
    }

    fun sort(left: Int, right: Int) {
        if (left + 1 < right) {
            val mid = (left + right) / 2
            sort(left, mid)
            sort(mid, right)
            merge(left, mid, right)
        }
    }

    sort(0, list.size)

    return array.toList() to cnt
}



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

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

    int D;
    cin >> D;

    vector<long> vec(2 * N, 0);
    int total = 0;

    for(int i = 0; i < 2 * N; i++){
        cin >> vec[i];

        if(i % 2 == 1){
            double heihoukon = (vec[i] * vec[i] + vec[i-1] * vec[i-1]);
            double length = sqrt(heihoukon);
            if(length <= D){
                total++;
            }
        }
    }

    cout << total << endl;
}

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

int main(){
    double mi, ma, h;
    mi = 1e100;
    ma = -1;
    while(cin >> h){
        mi = min(h,mi);
        ma = max(h,ma);
    }
    cout << ma-mi << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <math.h>
using namespace std;
int main(){
        int x,max=0;
        cin >> x;
        if(x==1) cout << 1 << endl;
        else{
        for(int i=2; i<=x; i++) {
                int j=i;int c=0;
                for(int j=2;j<=x;j++){
                  int c=pow(i,j);
                  if(c>x) break;
                  if(c>=max) max=c;
                }
        }
       cout << max << endl;
     }
}


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

int main() {
  int h,w; cin>>h>>w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) rep(j, w) cin>>a[i][j];

  rep(i, h) {
    int cnt = 0;
    rep(j, w) if (a[i][j]=='.') cnt++;
    if (cnt==w) rep(j, w) a[i][j] = 'x';
  }
  rep(i, w) {
    int cnt = 0;
    rep(j, h) if (a[j][i]=='.'||a[j][i]=='x') cnt++;
    if (cnt==h) rep(j, h) a[j][i] = 'x';
  }
  rep(i, h) {
    int cnt = 0;
    rep(j, w) {
      if (a[i][j] != 'x') printf("%c", a[i][j]);
      else cnt++;
    }
    if (cnt != w) printf("\n");
  }
}


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

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            int tmp = rList[0] - lList[lList.length - 1];

            if (tmp >= 0) {
                result += tmp + 1;
            }

            System.out.println(result);
        }
    }

}

Measured memory_bytes: 69528
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define IN(n) int n; cin>>n;
#define ARR(arr,i,n) int arr[n]; REP(i,0,n){cin>>arr[i];}
#define MOD 1000000007

using namespace std;

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

    // code comes here
    string s;
    cin>>s;
    char c1=s[0],c2;
    int countt1=0,countt2=0;
    for(int i=1;i<4;i++){
        if(s[i]==c1)
            countt1=1;
        else{
            c2=s[i];
        }
    }
    if(countt1==0){
        cout<<"No"<<"\n";
    }
    else{
        for(int i=1;i<4;i++){
            if(s[i]==c2){
                countt2++;
            }
        }
        if(countt2==2){
            cout<<"Yes"<<"\n";
        }
        else{

            cout<<"No"<<"\n";
        }
    }


    return 0;
}






Measured memory_bytes: 256
n,q = map(int,input().split())

par = [-1]*(n+1)

def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

for _ in range(q):
    c,x,y = map(int,input().split())
    if c == 0:
        unite(x,y)
    else:
        if same(x,y):print(1)
        else:print(0)


Measured memory_bytes: 5768
n, m = map(int, input().split())
s = []
u = []

for i in range(m):
    a, b = map(int, input().split())
    s.append(a)
    s.append(b)

for i in range(1, n+1):
    t = [x for x, y in enumerate(s) if y == i]
    t = len(t)
    u.append(t)

for i in u:
    print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int ans = 0, a = 0;
  if (S.size() % 2 == 1) {
	a = 1;
  }
  for (int i = 0; i < (S.size() - a)/2; i++) {
    if (S.at(i) != S.at(S.size() - 1 - i)) {
      ans++; 
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

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


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

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

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class AFairness {
public:
    void solve(std::istream &in, std::ostream &out) {
        int a, b, c;
        ll k;
        in >> a >> b >> c >> k;
        int res = (a - b) * (k % 2 ? -1 : 1);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    AFairness solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  string s;
  cin>>s;
  int r,l;
  int x=s.size();
  rep(i,x){
    if(s[i]=='A'){
      l=i;
      break;
    }
  }
  for(int i=x-1;i>=0;i--){
    if(s[i]=='Z'){
      r=i;
      break;
    }
  }
  cout<<r-l+1<<endl;
  return 0;
}


Measured memory_bytes: 644
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,k,q,a;
    cin>>n>>k>>q;
    vector<int>v(n,k-q);
    for(int i=0;i<q;i++){cin>>a;v[a-1]++;}
    for(auto x:v)cout<<(x>0?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int d[200][202020];
int main()
{
	int num, kai;
	scanf("%d%d", &num, &kai);
	for (int i = 0; i < num; i++)scanf("%d", &d[0][i]);
	for (int j = 0; j < 100; j++)
	{
		for (int i = 0; i < num; i++)d[j + 1][max(0, i - d[j][i])]++, d[j + 1][min(num - 1, i + d[j][i]) + 1]--;
		for (int i = 0; i < num; i++)d[j + 1][i + 1] += d[j + 1][i];
	}
	for (int i = 0; i < num; i++)printf("%d ", d[min(kai, 80)][i]); printf("\n");
}

Measured memory_bytes: 82504
#include<cstdio>
const int MAXN = 2e5 + 5;

inline int max(int a,int b){ return a>b? a: b;}
inline int min(int a,int b){ return a<b? a: b;}

int p[MAXN];

int a[MAXN<<2],b[MAXN<<2];
#define ls(u) ((u)<<1)
#define rs(u) ((u)<<1 | 1)

inline void push_up(int u)
{
	a[u] = max(a[ls(u)], a[rs(u)]);
	b[u] = min(b[ls(u)], b[rs(u)]);
}

inline void build(int u,int l,int r)
{
	if(l==r)
	{
		a[u]=b[u]=p[l];
		return;
	}
	
	int mid=(l+r)>>1;
	build(ls(u), l,mid);
	build(rs(u), mid+1,r);
	push_up(u);
}

inline int qa(int u,int l,int r, int ql,int qr)
{
	if(ql<=l && r<=qr) return a[u];
	
	int mid=(l+r)>>1, res=0;
	if(ql<=mid) res = max(res, qa(ls(u),l,mid, ql,qr));
	if(mid<qr) res = max(res, qa(rs(u),mid+1,r, ql,qr));
	return res;
}

inline int qb(int u,int l,int r, int ql,int qr)
{
	if(ql<=l && r<=qr) return b[u];
	
	int mid=(l+r)>>1, res=MAXN;
	if(ql<=mid) res = min(res, qb(ls(u),l,mid, ql,qr));
	if(mid<qr) res = min(res, qb(rs(u),mid+1,r, ql,qr));
	return res;
}

int f[MAXN];

int main(void)
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; ++i) scanf("%d",&p[i]), ++p[i];
	
	f[n]=1;
	for(int i=n-1; i>=1; --i)
	{
		if(p[i]<p[i+1]) f[i]=f[i+1]+1;
		else f[i]=1;
	}
	
	build(1,1,n);
	bool flag=0;
	int ans=1;
	if(f[1]>=k) flag=1, ans=0;
	for(int i=2; i+k-1<=n; ++i)
	{
		if(f[i]>=k)
		{
			flag=1;
			continue;
		}
		
		if(p[i+k-1] == qa(1,1,n, i,i+k-1) && p[i-1] == qb(1,1,n, i-1,i+k-2));
		else ++ans;
	}
	
	printf("%d",ans+flag);
	return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
const int N=100005;
const int mod=1e9+7;

int main()
{
    std::ios::sync_with_stdio(false);
    char a[201];
    scanf("%s",a);
    stack<char> s;
    int len=strlen(a);
    for(int i=0;i<len;i++){
        s.push(a[i]);
    }
    s.pop();
    int t,flag;
    while(1){
        if(s.size()%2==1) {
            s.pop();
        }
        else {
            t=s.size();
            t/=2;
            flag=1;
            for(int i=0;i<t;i++){
                if(a[i]!=a[i+t]){
                    flag=0;
                    break;
                }
            }
            if(flag){
                cout<<t*2<<endl;
                break;
            }
            else s.pop();
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = []
for i in range(N):
  L.append(input())
a = 0
b = 0
c = 0
d = 0
for i in L:
  if i == 'AC':
    a += 1
  elif i == 'WA':
    b += 1
  elif i == 'TLE':
    c += 1
  elif i == 'RE':
    d += 1
print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))

Measured memory_bytes: 16320
def lcm(a, b):
  if b > a:
    a, b = b, a
  
  while b != 0:
    a, b = b, a % b
  
  return a

city_num, start = map(int, input().split())

cities = list(map(int, input().split()))

for i in range(len(cities)):
  cities[i] = abs(start - cities[i])

cities.sort()

a = cities[0]
for num in cities[1:]:
  a = lcm(a, num)
  
print(a)

Measured memory_bytes: 15020
from collections import defaultdict
S = input()
N = len(S)

D=defaultdict(int)
D[0]=1
ans=0
prev=0

for i,s in enumerate(reversed(S)):
    cur=(prev+pow(10,i,2019)*int(s))%2019
    ans+=D[cur]
    D[cur]+=1
    prev=cur
print(ans)


Measured memory_bytes: 9584
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    int n;
    int i,j;
    string s,t;
    cin>>n;
    rep(i,0,n){
        cin>>s;
        sort(s.begin(),s.end());
        if(i==0){
            t=s;
        }
        else{
            if(0!=t.size()){
                j=0;
                while(1){
                    if(s.find(t[j])!=string::npos){
                        s.erase(s.begin()+s.find(t[j]));
                        j++;
                    }
                    else{
                        t.erase(t.begin()+j);
                    }
                    if(j==t.size()){
                        break;
                    }
                }
            }
        }
    }
    cout<<t<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int N,K,sum = 0;
  scanf("%d%d",&N,&K);
  sum += K;
  
  for(int i = 0;i < N - 1;i++)
  {
    sum *= (K - 1);
  }
  
  printf("%d",sum);
  
  return 0;
}
  

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

#define si(x) scanf("%d",&x)
using namespace std;

int main()
{
    int n,m,q,x,y;
    si(n);si(m);
    vector<pair<int,int> > color(n);
    vector<int> last(n,-1);
    vector<vector<int> > adj(n);
    for(int i=0;i<n;i++)color[i] = {0,-1};
    for(int i=0;i<m;i++){
        si(x);si(y);
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }
    si(q);
    vector<pair<pair<int,int> , int > > query;
    for(int i=0;i<q;i++){
        int v,d,c;
        si(v);si(d);si(c);
        v--;
        query.push_back({{v,d},c});
    }
    for(int i=query.size()-1;i>=0;i--){
        queue<pair<int,int> > q;
        q.push({query[i].first.first , 0});
        while(!q.empty()){
            pair<int,int> curr = q.front();q.pop();
            if(color[curr.first].second == i)continue;
            if(last[curr.first] >= query[i].first.second - curr.second)continue;
            last[curr.first] = query[i].first.second - curr.second;
            if(color[curr.first].first == 0)color[curr.first].first = query[i].second;
            color[curr.first].second = i;
            if(curr.second == query[i].first.second)continue;
            for(int j=0;j<adj[curr.first].size();j++){
                q.push({adj[curr.first][j] , curr.second + 1});
            }
        }
    }
    for(int i=0;i<n;i++)cout << color[i].first << "\n";
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll d,e;
  while(cin >> d >> e,d+e){
    double ans = inf;
    for(int x = 0; x <= d;++x){
      int y = d - x;
      ans = min(ans,abs(sqrt(x*x + y * y) - e));
    }
    fcout(10) << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
typedef pair<pii,int>piii;
const int N=1e3+5;
int n,D,x,y,i,j,k,h[N][N],hh[N][N],ans=2e9,mx,v3[N*2][N*2],zz;
vector<int>v1,v2;
int main(){
	scanf("%d%d",&n,&D);
	for(i=1;i<=n;++i)scanf("%d%d",&x,&y),h[x%D][y%D]++;
	for(i=0;i<D;++i)for(j=0;j<D;++j){
		for(k=0;k*k<h[i][j];++k);
		if(k*(k-1)>=h[i][j])hh[i][j]=1;
		h[i][j]=k;
		if(k>mx)mx=k;
	}
	for(i=0;i<D;++i)for(j=0;j<D;++j)if(h[i][j]==mx){
		if(!hh[i][j])v1.push_back(i),v2.push_back(j);
//			else v3.push_back(pii(i,j));
			else ++v3[i][j],++v3[i+D][j+D],++v3[i][j+D],++v3[i+D][j],++zz;
	}
	for(i=D*2-1;i>=0;--i)for(j=D*2-1;j>=0;--j)v3[i][j]+=v3[i][j+1];
	for(i=D*2-1;i>=0;--i)for(j=D*2-1;j>=0;--j)v3[i][j]+=v3[i+1][j];
	sort(v1.begin(),v1.end());sort(v2.begin(),v2.end());
	v1.erase(unique(v1.begin(),v1.end()),v1.end());
	v2.erase(unique(v2.begin(),v2.end()),v2.end());
	for(i=0;i<D;++i)for(j=0;j<D;++j){
		int v=0;
//		for(int x:v1)v=max(v,(x+D-i)%D);
		if(!v1.empty()){if(i<=v1[0])v=max(v,v1.back()-i);else v=max(v,*--lower_bound(v1.begin(),v1.end(),i)+D-i);}
		if(!v2.empty()){if(j<=v2[0])v=max(v,v2.back()-j);else v=max(v,*--lower_bound(v2.begin(),v2.end(),j)+D-j);}
//		for(pii u:v3)v=max(v,min((u.first+D-i)%D,(u.second+D-j)%D));
		int l=0,r=D-1,m;
		for(;l<r;){
			m=(l+r)>>1;
//			if(v3[i+m][j+m]-(i?v3[i-1][j+m]:0)-(j?v3[i+m][j-1]:0)+(i && j?v3[i-1][j-1]:0)==zz)r=m;
			if(v3[i][j]-v3[i+m+1][j+m+1]-(v3[i][j+D]-v3[i+m+1][j+D])-(v3[i+D][j]-v3[i+D][j+m+1])==zz)r=m;
				else l=m+1;
		}
		v=max(v,l);
		v+=(mx-1)*D;
if(v==7){
++v,--v;
}
		if(v<ans)ans=v;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 24948
SA = input()
SB = input()
SC = input()

turn = SA[0]
while True:
    if turn == 'a':
        if len(SA) == 0:
            print('A')
            break
        else:
            turn = SA[0]
            SA = SA[1:]
    elif turn == 'b':
        if len(SB) == 0:
            print('B')
            break
        else:
            turn = SB[0]
            SB = SB[1:]
    else:
        if len(SC) == 0:
            print('C')
            break
        else:
            turn = SC[0]
            SC = SC[1:]


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

long long w, h, v, t, x, y, p, q, r;

long long solve();
long long calc(long long a, long long b);

int main() {
  cin >> w >> h >> v >> t >> x >> y >> p >> q;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  r = v * t;
  res += calc(p - x, q - y);
  res += calc(-p - x, q - y);
  res += calc(p - x, -q - y);
  res += calc(-p - x, -q - y);
  return res;
}

long long calc(long long a, long long b) {
  long long res = 0;
  for(long long i = -4000000; i <= 4000000; ++i) {
    long long nx = 2 * i * w + a, d, u;
    if(abs(nx) > r) continue;
    d = u = sqrt(r * r - nx * nx);
    u = (u - b) / (2 * h);
    d = ceil(-(d + b) / (long double)(2 * h));
    if(u == d &&
       nx * nx + (2 * h * u + b) * (2 * h * u + b) > r * r)
      continue;
    res += max(0LL, u - d + 1);
  }
  return res;
}



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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    int ans=0;
    for (int i = 0; i < n; ++i) {
        int a;cin>>a;
        if(i%2==0&&a%2==1)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<P>vec;
int p[200005],q[200005],c[200005];
vector<P>edge[600105];
int dist[600105];
bool used[600105];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&p[i],&q[i],&c[i]);
		vec.pb(mp(p[i],c[i]));
		vec.pb(mp(q[i],c[i]));
	}
	SORT(vec); ERASE(vec);
	for(int i=0;i<vec.size();i++){
		int v = vec[i].fi;
		int ty = vec[i].sc;
		edge[v+500050].pb(mp(i,1));
		edge[i].pb(mp(v+500050,1));
	}
	for(int i=0;i<m;i++){
		int A = POSL(vec,mp(p[i],c[i]));
		int B = POSL(vec,mp(q[i],c[i]));
		edge[A].pb(mp(B,0));
		edge[B].pb(mp(A,0));
	}
	fill(dist,dist+600105,INF);
	dist[500051] = 0;
	deque<int>deq;
	deq.pb(500051);
	while(deq.size()){
		int q = deq.front(); deq.pop_front();
		if(used[q]) continue;
		used[q] = 1;
		for(int i=0;i<edge[q].size();i++){
			if(used[edge[q][i].fi]) continue;
			if(dist[edge[q][i].fi] > dist[q]+edge[q][i].sc){
			    dist[edge[q][i].fi] = dist[q]+edge[q][i].sc;
    			if(edge[q][i].sc == 0){
    				deq.push_front(edge[q][i].fi);
    			}
    			else{
    				deq.push_back(edge[q][i].fi);
    			}
			}
		}
	}
	if(dist[500050+n] == INF) cout << -1 << endl;
	else cout << (2+dist[500050+n])/2-1 << endl;
}

Measured memory_bytes: 41452