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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
};

// a^n mod を計算する
long long modpow(long long a, long long n, long long m) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
};

long long fact[1000005], inv[1000005], factinv[1000005];

void init(int m) {
  fact[0] = 1;
  for(int i = 1; i < 1000001; i++) {
    fact[i] = (1ll * fact[i - 1] * i) % m;
  }
  for(int i = 0; i < 1000001; i++) {
    inv[i] = modinv(i, m);
    factinv[i] = modinv(fact[i], m);
  }
};

// nCrを計算する
long long comb(long long n, long long r) {
    return fact[n] * factinv[r] * factinv[n - r];
};

// nCr mod を計算する
long long modcomb(long long n, long long r, long long m) {
    return (fact[n] * factinv[r] % m) * factinv[n - r] % m;
};

static ll mod = 1e9 + 7;

int main() {
  ll X, Y;
  cin >> X >> Y;
  ll ans = 0;

  init(mod);
  for (ll i = 0; i < (Y/2 + 1); i++)  {
    if (X - i == 2 * (Y - 2 * i)) {
      // cout << "Y - i: " << Y - i << endl;
      // cout << "i: " << i << endl;
      // cout << "mod: " << mod << endl;
      // cout << modcomb(Y - i, i, mod) << endl;
      ans += modcomb(Y - i, i, mod);
      ans %= mod;
    }
  }

  cout << ans << endl;
};


Measured memory_bytes: 23680
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];


int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(n, a);
	vector<ll> ans(n);
	for (ll i = 0; i < n; i++)
	{
		ans[a[i] - 1] = i + 1;
	}
	for (ll i = 0; i < n; i++)
	{
		cout << ans[i] << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 4676
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(){
    string input;
    cin >> input;
    string output = "";
    
    for(int i = 0; i < input.size(); i++){
        string tmp = input.substr(i, 1);
        if(tmp == "1"){
            output += "9";
        } else {
            output += "1";
        }
    }
    
    cout << output;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i, x, y;
	
	for (i = 1;; i++) {
		scanf("%d %d", &x, &y);
		if ((x == 0) && (y == 0)) break;
		
		if (x < y) {
			printf("%d %d\n", x, y);
		} else {
			printf("%d %d\n", y, x);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    private Scanner in = new Scanner(System.in);

    void solve() {
        int n = in.nextInt(); in.nextLine();
        List<String> s = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            s.add(in.nextLine());
        }
        int m = in.nextInt(); in.nextLine();
        List<String> t = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            t.add(in.nextLine());
        }
        Map<String, List<String>> sMap = s.stream().collect(Collectors.groupingBy(String::toString));
        Map<String, List<String>> tMap = t.stream().collect(Collectors.groupingBy(String::toString));
        OptionalInt ans = sMap.keySet().stream()
                .mapToInt(str -> sMap.get(str).size() - (tMap.containsKey(str) ? tMap.get(str).size() : 0))
                .max();
        System.out.println(Math.max(0, ans.getAsInt()));
    }
    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 29140
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int n, d, x, ans = 0;
    cin >> n >> d >> x;
    ans += n + x;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans += (d - 1) / a;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
from copy import deepcopy
from collections import deque
from heapq import heappush, heappop


def warshallfloyd(cost,V):
    INF = float("inf")
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k]!=INF and cost[k][j]!=INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    for i in cost:
        if float("inf") in i:
            return False
    
    return True

N,M = map(int,input().split())
edge = [[float("inf") for i in range(N)] for j in range(N)]
ab = []
for _ in range(M):
    a,b = map(int,input().split())
    ab.append([a-1,b-1])
    edge[a-1][b-1] = 1
    edge[b-1][a-1] = 1

ans = 0

for a,b in ab:
    tmp = deepcopy(edge)
    tmp[a][b] = float("inf")
    tmp[b][a] = float("inf")
    if not warshallfloyd(tmp,N):
        ans += 1

print(ans)


Measured memory_bytes: 9740
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
#define point complex<double>
const int N = 3e5 + 5;
const int OO = 1e9 + 7;
using namespace std;
ll a, b, n;

ll solve(ll x) {
    re ((a * x / b)) - (a * (x / b));
}

int main() {
    IO;
    cin >> a >> b >> n;
    cout << solve(min(b - 1, n));
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

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

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////
ll ans;
ll k;
ll ruin=0;
vector<ll> vec[100005];

ll fin[100005];
ll al[100005];
ll kai[100005];


void bfs(ll u){
	ll cnt=0;
  for(ll i=0;i<vec[u].size();i++){
ll t=vec[u][i];
fin[t]++;
if(al[t]!=1) cnt++;
  }

if(k-fin[u]<cnt){ruin=1;}
  if(COM(k-fin[u],cnt)!=0)
ans*=COM(k-fin[u],cnt);
ans%=MOD;
ans*=kai[cnt];
ans%=MOD;
 for(ll i=0;i<vec[u].size();i++){
	 ll va=vec[u][i];
if(al[va]==0){
	al[va]=1;
bfs(va);
  }

}
}



ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}




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

ll a[n+1];
rep(i, n){
	cin>>a[i];
}

ll cm=1;
ll t=1;
rep(i, n){
	if(i==1){t=rad(a[i],(ll)2);}
cm=lcm(cm,a[i]);
if(cm>2*m){cout<<0<<endl;
return 0;}
if(t!=rad(a[i],(ll)2)){
	cout<<0<<endl;
	return 0;
}
}


ll k=cm/2;
ll ans=m/k;
cout<<(ans+1)/2<<endl;
return 0;





}




Measured memory_bytes: 5120
const MOD = 10**9+7
// factors[f].e+n-1、において max(n)=10**5, max(factors[f].e)=log(M)=log(10**9)=21
const N = 10**5+28

let fac = [...new Array(N)].fill(0)
let ifac = [...new Array(N)].fill(0)
const mul = (a,b) => ((a>>16)*b%MOD*65536+(a&65535)*b)%MOD;

const factorization = (n) => {
    let primes= []
    for(let i=2; i*i<=n; i++) {
        let exponent = 0
        while(n%i===0) {
            n /= i
            exponent++
        }
        if(exponent) {
            primes.push({p:i, e:exponent})
        }
    }
    
    if(n!==1) {
        primes.push({p:n, e:1})
    }
    return primes
}

const mpow = (x, n) => {
    ans = 1;
    let _x = x
    while(n != 0){
        if(n & 1) ans = mul(ans,_x);
        _x = mul(_x,_x);
        n = n >> 1;
    }
    return ans;
}

const comb = (n, r) => {
    if(n == 0 && r == 0) return 1;
    if(n < r || n < 0) return 0;
    const tmp = mul(ifac[n-r],ifac[r])
    return mul(tmp,fac[n])
}

const init = () => {
    fac[0] = 1;
    ifac[0] = 1;
    for(let i=0; i<N; i++){
        fac[i+1] = mul(fac[i],(i+1));
        ifac[i+1] = mpow(fac[i+1], MOD - 2)
    }
}

const main = (arg) => {
    let [n, m] = arg.split(" ").map(Number)
    let factors = factorization(m)
    let ans = 1
    init()
    Object.keys(factors).forEach(f=>{
        let a = factors[f].e+n-1
        let b = factors[f].e
        ans = mul(ans,comb(a, b))
    })
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37528
import java.util.*;

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

    int n = sc.nextInt();
    String s1 = sc.next();
    String s2 = sc.next();

    char[] c1 = s1.toCharArray();
    char[] c2 = s2.toCharArray();

    String s3 = "";

    for(int i=0;i<n;i++){
      s3 = s3 + c1[i] +c2[i];
    }

    System.out.println(s3);


  }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void) {
  int a,b,ans;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+')
      ans=a+b;
    else if(op=='-')
      ans=a-b;
    else if(op=='*')
      ans=a*b;
    else if(op=='/')
      ans=a/b;
    else break;
    printf("%d\n",ans);
  }
  return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

vector<int> odd(100000);
vector<int> even(100000);
int main(){
	int n; cin >>n;
	for(int i=0;i<n;i++){
		int v; cin >>v;
		if(i%2==0){
			even[v]++;
		}
		else{
			odd[v]++;
		}
	}
	int max1=0;
	int max2=0;
	for(int i=0;i<100000;i++){
		if(even[max1] <even[i])
			max1=i;
	}
	for(int i=0;i<100000;i++){
		if(odd[max2]< odd[i] && max1 !=i)
			max2 =i;
	}
	int cnt1=even[max1]+odd[max2];
	max1=0; max2=0;
	for(int i=0;i<100000;i++){
		if(odd[max1] <odd[i])
			max1=i;
	}
	for(int i=0;i<100000;i++){
		if(even[max2]< even[i] && max1 !=i)
			max2 =i;
	}
	int cnt2=odd[max1]+even[max2];
	cout << min(n-cnt1,n-cnt2)<< endl;
}


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

int main (void){
	int *a, *b;
	int max, i, p, N = 0;
	
	a = malloc(sizeof(int)*100000);
	b = malloc(sizeof(int)*100000);
	
	scanf("%d",&N);
		
	for(i = 0;i < N;i++){
		
		scanf("%d",&a[i]);
		
		p = a[i];
		b[p-1]++;
		b[p]++;
		b[p+1]++;
	}
	
	for(i = 0;i < 100000;i++){
		if(max < b[i])max = b[i];
	}
	printf("%d",max);
	
	return 0;
}

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

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

	vector<int> A(N);

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	bool ans = true;
	sort(A.begin(), A.end());
	int sum = 0;
	int j = 1;


	while (ans) {
		for (int i = j; i < N; i++) {
			A.at(i) = A.at(i) % A.at(j-1);
			//cout << A.at(i) << endl;
			if (A.at(i) == 0) {
				sum++;
			}
		}
		//cout << sum << endl;
		j = sum+1;
		sort(A.begin(), A.end());
		if (sum == N - 1) {
			ans = false;
		}
	}
	
	reverse(A.begin(), A.end());
	/*for (int i = 0; i < N; i++) {
		cout << A.at(i) << endl;
	}*/

	cout << A.at(0) << endl;

	return 0;
}

Measured memory_bytes: 640
import sys, heapq
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def dijkstra(G, s):
    que = []
    d = [INF]*len(G)
    d[s] = 0
    heapq.heappush(que, (d[s], s))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if d[v] < p[0]: continue
        for e in G[v]:
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heapq.heappush(que, (d[e[0]], e[0]))
    return d

def resolve():
    V, E, r = LI()
    std = [LI() for _ in range(E)]

    edge = [[] for _ in range(V)]
    for i in std:
        edge[i[0]].append((i[1], i[2]))

    d = dijkstra(edge, r)

    for i in d:
        if i<INF:
            print(i)
        else:
            print('INF')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 155348
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
        return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门提示: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, x; cin >> n >> x;
    vi m(n);

    ll sum = 0;
    rep(i, n){
        cin >> m[i];
        sum += m[i];
    }

    x -= sum;
    sort(all(m));
    x = x/m[0];

    cout << n+x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	int u, v;
	ll cost;
};

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

#define N 100010

int par[N];
int urank[N];

void init(int n) {
	REP(i, n) {
		par[i] = i;
		urank[i] = 0;
	}
}

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

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (urank[x] < urank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (urank[x] == urank[y]) urank[x]++;
	}
}

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

edge es[N];

bool used[N];
int V, E;

ll kruskal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	REP(i, E) {
		edge e = es[i];
		if (!same(e.u, e.v) && !used[e.u] && !used[e.v]) {
			unite(e.u, e.v);
			res += e.cost;
			used[e.u] = used[e.v] = true;
		}
	}
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;
}


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

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
    int N;
    cin >> N;
    string ans = "No";
    while(N > 0) {
       int d = N%10;

       if(d == 7) {
          ans = "Yes";
           break;
       }
       N /= 10;
    }
cout << ans;
return 0;
}


Measured memory_bytes: 3132
while (h,w = gets.split(" ").map(&:to_i)) != [0, 0]
    line = ["#." *( w / 2 ) + "#" *( w % 2), ".#" * ( w / 2) + "." * (w % 2)]
    h.times do |i|
        puts line[ i % 2]
    end
    
    puts
end




Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K,a;
  string ss;
  cin>>N>>ss>>K;
  
  if(ss[0]=='+'){
    cout<<N+K<<endl;
  }else{
    cout<<N-K<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
	int n, ba = 0, taihi = 0, zyun = 0;
	String a;
	Scanner scan = new Scanner(System.in);
	while(true){
	    n = scan.nextInt();
	    if(n == 0)break;
	    int[] player = new int[n];
	    for(int b = 0; b < n; b++){
		player[b] = 0;
	    }
	    a = scan.next();
	    char[] hairetu = a.toCharArray();
	    for(int i = 0; i < 100; i++){
		zyun = i % n;
		if(hairetu[i] == 'S'){
		    ba = ba + player[zyun] + 1;
		    player[zyun] = 0;
		}
		if(hairetu[i] == 'L'){
		    player[zyun] = player[zyun] + ba + 1;
		    ba = 0;
		}
		if(hairetu[i] == 'M'){
		    player[zyun] = player[zyun] + 1;
		}
	    }
	    for(int j = 0; j < n - 1; j++){
		for(int k = n - 1; k > j; k-- ){
		    if(player[j] > player[k]){
			taihi = player[j];
			player[j] = player[k];
			player[k] = taihi;
		    }
		}
	    }
	    for(int l = 0; l < n; l++){
		System.out.print(player[l] + " ");
	    }
	    System.out.println(ba);
	    for(int k = 0; k < n; k++){
		player[k] = 0;
	    }
	    ba = 0;
	}
    }
}

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

#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int> p(n),c(n);
    for(int& i:p) cin>>i,i--;
    for(int& i:c) cin>>i;
    ll ans=-1e18;
    for(int i=0;i<n;i++){
        int pos=i;
        ll sum=0;
        int cycle_cnt=0;
        while(true){
            cycle_cnt++;
            sum+=c[pos];
            pos=p[pos];
            if(pos==i) break;
        }
        
        ll path_sum=0;
        int cnt=0;
        while(true){
            cnt++;
            path_sum+=c[pos];
            if(cnt>k) break;
            int num=(k-cnt)/cycle_cnt;
            ans=max(ans,path_sum+max(0LL,sum)*num);
            pos=p[pos];
            if(pos==i) break;
        }
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3688
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll mod=1e9+7;

int main(){
    ll a,b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
        return 0;
    }
    if(a==1){
        cout << "Alice" << endl;
        return 0;
    }
    if(b==1){
        cout << "Bob" << endl;
        return 0;
    }
    if(a>b){
        cout << "Alice" << endl;
    }
    else{
        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        char[] ar=s.toCharArray();
        boolean result=true;
        for(int i=0;i<ar.length;i++){
            if(i%2==0){
                if(ar[i]!='R' && ar[i]!='U' && ar[i]!='D'){
                    result=false;
                    break;
                }
            }
            else{
                if(ar[i]!='L' && ar[i]!='U' && ar[i]!='D'){
                    result=false;
                    break;
                }
            }
        }
        if(result==true)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35700
i = 0
while i < 100 do
a,op,b = gets.split(" ")
a = a.to_i
b = b.to_i
if op == "+"
	c = a + b
elsif op == "-"
	c = a - b
elsif op == "*"
	c = a * b
elsif op == "/"
	c = a / b
elsif op == "?"
	break
end

puts c


end


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

int w,h;
int g[100][100];
bool visit[100][100];
bool open;

int dfs(int x,int y,int exist){
  visit[x][y] = true;
  int ex[] = {0,1,1,1,0,-1}, ey[] = {-1,-1,0,1,1,0};
  int ox[] = {-1,0,1,0,-1,-1}, oy[] = {-1,-1,0,1,1,0};
  int res  = 0;

  for(int i=0;i<6;i++){
    int sx,sy;
    if(y&1){sx = x+ox[i]; sy = y+oy[i];}
    else{sx = x+ex[i]; sy = y+ey[i];}

    if(sx<0 || sy<0 || w<=sx || h<=sy){
      res++;
      open = true;
      continue;
    }
    if(g[sx][sy] != exist){
      res++;
      continue;
    }
    if(visit[sx][sy])continue;
    
    res += dfs(sx,sy,exist);
  }
  return res;
}

int main(){
  cin >> w >> h;

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      cin >> g[j][i];
      visit[j][i] = false;
    }

  int ans = 0;
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      if(!visit[i][j]){
	open = false;
	int tmp = dfs(i,j,g[i][j]);

	if(g[i][j])ans += tmp;
	else if(!open)ans -= tmp;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> m(h);
  for(int i=0; i<h; ++i) cin >> m[i];
  vector<vector<int>> dp(h, vector<int>(w,0));
  dp[0][0] = 1;
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    if(m[i][j] == '#') continue;
    if(i>0) dp[i][j] += dp[i-1][j];
    if(j>0) dp[i][j] += dp[i][j-1];
    dp[i][j] %= MOD;
  }
  cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s.size() == 1)
    {
        cout << "0";
        return 0;
    }
    int count = 0;
    for(int i = 0;i < s.size() - 1;i++)
    {
        if(s[i] == s[i + 1] && s[i] == '0')
        {
            s[i + 1] = '1';
            count++;
        }
        else if(s[i] == s[i + 1] && s[i] == '1')
        {
            s[i + 1] = '0';
            count++;
        }
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,m;cin>>n>>m;
    priority_queue<int> pq;
    int a;
    rep(i,n){
        cin>>a;
        pq.push(a);
    }
    rep(i,m){
        pq.push(pq.top()/2);
        pq.pop();
    }
    ll ans=0;
    while(pq.size()){
        ans+=(ll)pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
#define ll long long 
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> list(n+1);
    vector<int> color(n+1, -1);
    vector<ll> u(n-1);
    vector<ll> v(n-1);
    vector<ll> w(n-1);
    map<P, ll> mp;
    rep(i, 0, n-1) {
        cin >> u[i] >> v[i] >> w[i];
    }
    rep(i, 0, n-1) {
        list[u[i]].push_back(v[i]);
        list[v[i]].push_back(u[i]);
        P p = make_pair(u[i], v[i]);
        P q = make_pair(v[i], u[i]);
        mp[p] = w[i];
        mp[q] = w[i];
    }
    queue<int> que;
    que.push(1);
    while(!que.empty()) {
        int s = que.front();
        que.pop();
        int num = 0;
        if(color[s] == -1) {
            color[s] = 0;
        }
        num = color[s];
        for(auto i : list[s]) {
            P tmp = make_pair(s, i);
            if(color[i] == -1) {
                if(mp[tmp]%2 == 0) {
                    color[i] = num;
                }
                else {
                    if(num == 0) {
                        color[i] = 1;
                    }
                    else {
                        color[i] = 0;
                    }
                }
                que.push(i);
            }
        }
    }

    rep(i, 1, n+1) {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 21632
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
#define PI 3.141592653589793
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};


using namespace std;
using Graph = vector< vector<int> > ;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> G;
    rep(i,n+1){
        vector<int> tmp;
        G.push_back(tmp);
    }
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(n+1,-1);
    queue<int> que;
    dist[1] = 0;
    que.push(1);
    vector<int> sirube(n+1,-1);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; 


            dist[nv] = dist[v] + 1;
            que.push(nv);
            if (sirube[nv] == -1){
                sirube[nv] = v;
            }
        }
    }
    for( int i=2;i<=n;i++){
        if (dist[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int v = 2; v <=n; ++v) cout << sirube[v] << endl;



        
}

Measured memory_bytes: 10408
X, N = map(int, input().split())

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

if N == 0:
    print(X)
else:
    for i in range(110):
        if X - i not in p:
            print(X - i)
            break
        elif X + i not in p:
            print(X + i)
            break


Measured memory_bytes: 9176
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int v = in.nextInt();
		int e = in.nextInt();

		init(v);
		for (int i=0;i<e;i++) {
			addEdge(in.nextInt(), in.nextInt());
		}
		makeStronglyConnectedComponent(v);

		int q = in.nextInt();
		for (int i=0;i<q;i++) {
			if (order[in.nextInt()]==order[in.nextInt()]) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}
	}

	///
	static List<Integer>[] edge;
	static List<Integer>[] revEdge;
	static boolean[] used;
	static List<Integer> lPostOrderNumber;
	static int[] order; // topological order number for each vertex
	@SuppressWarnings("unchecked")
	static void init(int v) {
		used = new boolean[v];
		edge = new ArrayList[v];
		for (int i=0;i<edge.length;i++) {
			edge[i] = new ArrayList<Integer>();
		}
		revEdge = new ArrayList[v];
		for (int i=0;i<revEdge.length;i++) {
			revEdge[i] = new ArrayList<Integer>();
		}
		lPostOrderNumber = new ArrayList<Integer>();
		order = new int[v];
	}
	static void addEdge(int from, int to) {
		edge[from].add(to);
		revEdge[to].add(from);
	}
	static void dfsPostOrderNumbering(int v) {
		// use stack instead of recursive call to avoid stack overflow
		Stack<Integer> s = new Stack<Integer>();
		s.push(v);
		used[v] = true;
		
		while (!s.isEmpty()) {
			int val = s.peek();
			boolean bPushed = false;
			for (int i=0;i<edge[val].size();i++) {
				if (!used[edge[val].get(i)]) {
					s.push(edge[val].get(i));
					used[edge[val].get(i)] = true;
					bPushed = true;
					break;
				}
			}
			if (!bPushed) {
				lPostOrderNumber.add(s.pop());
			}
		}
	}
	static void dfsMakeComponent(int v, int k) {
		// use stack instead of recursive call to avoid stack overflow
		Stack<Integer> s = new Stack<Integer>();
		s.push(v);
		used[v] = true;
		order[v] = k;

		while (!s.isEmpty()) {
			int val = s.pop();
			for (int i=0;i<revEdge[val].size();i++) {
				if (!used[revEdge[val].get(i)]) {
					s.push(revEdge[val].get(i));
					used[revEdge[val].get(i)] = true;
					order[revEdge[val].get(i)] = k;
				}
			}
		}
	}
	static long makeStronglyConnectedComponent(int v) {
		for (int i=0;i<v;i++) {
			if (!used[i]) dfsPostOrderNumbering(i);
		}

		Arrays.fill(used, false);
		int k=0;
		for (int i=lPostOrderNumber.size()-1;i>=0;i--) {
			if (!used[lPostOrderNumber.get(i)]) dfsMakeComponent(lPostOrderNumber.get(i), k++);
		}
		return k; // # of strongly connected components
	}

//	static void dfsPostOrderNumbering(int v) {
//		used[v] = true;
//		for (int i=0;i<edge[v].size();i++) {
//			if (!used[edge[v].get(i)]) dfsPostOrderNumbering(edge[v].get(i));
//		}
//		lPostOrderNumber.add(v);
//	}
//	static void dfsMakeComponent(int v, int k) {
//		used[v] = true;
//		order[v] = k;
//		for (int i=0;i<revEdge[v].size();i++) {
//			if (!used[revEdge[v].get(i)]) dfsMakeComponent(revEdge[v].get(i), k);
//		}
//	}

}

Measured memory_bytes: 103764
#include <iostream>
#include <math.h>
using namespace std;
int main(){

    int a[5];
    int q[5],r[5];
    int min = 0;
    int sum=0;
    for(int i=0; i<5; i++){
        cin >> a[i];
        q[i] = a[i] / 10;
        r[i] = a[i] % 10;
    }
    
    for(int i=1; i<5; i++){
        if(r[min] == 0){
            r[min] = r[i];
        }

        if(r[min] != 0 && r[i]!=0 && r[min] > r[i]){
            min = i;
        }
    }

    for(int i=0; i<5; i++){
        if(i != min){
            if(r[i] == 0){
                sum = sum+ q[i]*10;
            }
            else{
                sum = sum+ (q[i]+1)*10;
            }
           
        }
        else{
            sum = sum+ q[i]*10+r[i];
        }
    }

    
    cout << sum << endl;

    return 0;
}

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

int main(void)
{
    IOS
    ll n; cin >> n;
    ll a,b; cin >> a >> b;
    ll ab = a + b;

    ll ans = a * (n / ab);
    ans += min(a,n % ab);
    
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
    int a[10], i, j, temp, t;
    
    for (i=0; i<10; i++){
        scanf("%d", &a[i]);
    }
    for (i=0; i<10; i++){
        for (j=i+1; j<10; j++){
            if (a[i]<a[j])
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }

        printf("%d\n", a[0]);
        printf("%d\n", a[1]);
        printf("%d\n", a[2]);
    

    return 0;
}



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

int n,m,k;
int cost[15];
vector<vector<int> > vec(15,vector<int>(15));

int rec(int i,vector<int> sum){
	if(i>=n)return INT_MAX;
	int flag=0;
	for(int j=0;j<m;j++){
		sum[j]+=vec[i][j];
		if(sum[j]<k)flag=1;
	}
	if(flag==0)return 0;
	int val=INT_MAX;
	for(int j=i+1;j<n;j++){
		int p=rec(j,sum);
		if(p!=INT_MAX)val=min(val,cost[j]+rec(j,sum));
	}
	return val;
}

int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>cost[i];
		for(int j=0;j<m;j++){
			cin>>vec[i][j];
		}
	}
	vector<int> sum(m);
	int val=INT_MAX;
	for(int i=0;i<n;i++){
		int p=rec(i,sum);
		if(p!=INT_MAX )val=min(val,cost[i]+rec(i,sum));
	}
	if(val==INT_MAX)cout<<"-1"<<endl;
	else cout<<val<<endl;
	return 0;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n;
  cin >> n;
  cout << (n-1)*n/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct edges
{
	int to,next;
}edge[202020];
int first[101010],now;
void adde(int x,int y)
{
	now++;
	edge[now].to=y;
	edge[now].next=first[x];
	first[x]=now;
}
int l[101010],r[101010];
bool lim[101010];
bool ok=true;
int ans[101010];
void work(int p,int fa)
{
	bool ap[2];
	ap[0]=ap[1]=false;
	if(lim[p])
		ap[(r[p]+1)&1]=true;
	for(int e=first[p];e;e=edge[e].next)
		if(edge[e].to!=fa)
		{
			work(edge[e].to,p);
			if(lim[edge[e].to])
			{
				lim[p]=true;
				l[p]=max(l[p],l[edge[e].to]-1);
				r[p]=min(r[p],r[edge[e].to]+1);
				ap[(r[edge[e].to]&1)]=true;
			}
		}
	if((ap[0]&&ap[1])||l[p]>r[p])
		ok=false;
}
void getans(int p,int fa)
{
	if(fa)
	{
		if(ans[fa]-1>=l[p])
			ans[p]=ans[fa]-1;
		else
			ans[p]=ans[fa]+1;
	}
	for(int e=first[p];e;e=edge[e].next)
		if(edge[e].to!=fa)
			getans(edge[e].to,p);
}
int main()
{
	int n,k,x,y;
	scanf("%d",&n);
	memset(first,0,sizeof(first));
	now=0;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		adde(x,y);
		adde(y,x);
	}
	for(int i=1;i<=n;i++)
	{
		l[i]=-1000000;
		r[i]=2000000;
	}
	memset(lim,0,sizeof(lim));
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d",&x,&y);
		lim[x]=true;
		l[x]=r[x]=y;
	}
	work(1,0);
	if(ok)
	{
		printf("Yes\n");
		ans[1]=l[1];
		getans(1,0);
		for(int i=1;i<=n;i++)
			printf("%d\n",ans[i]);
	}
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[5], res;
string str;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> str;
        if (str[0] == 'M') a[0]++;
        if (str[0] == 'A') a[1]++;
        if (str[0] == 'R') a[2]++;
        if (str[0] == 'C') a[3]++;
        if (str[0] == 'H') a[4]++;
    }
    for (ll i = 0; i < 5; i++) {
        for (ll j = i + 1; j < 5; j++) {
            for (ll k = j + 1; k < 5; k++) {
                res += a[i] * a[j] * a[k];
            }
        }
    }
    cout << res << endl;
}


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

using namespace std;
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define fr(i,n) for(int i = 0; i < n; ++i)
#define fr1(i,n) for(int i=1;i<=n;i++)


int main() {
      int n;
      cin>>n;
      if( n < 10 )            cout<<n;
      else if( n < 100)       cout<<"9";
      else if( n < 1000)      cout<<9+n-99;
      else if( n < 10000)     cout<<9+900;
      else if( n < 100000)    cout<<9+900+n-9999;
  		else cout<<9+900+90000;	
      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++)
    {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());
    vector<long long> ABC;
    for (int a = 0; a < X; a++)
    {
        for (int b = 0; b < Y; b++)
        {
            if ((a + 1) * (b + 1) > K)
            {
                break;
            }
            for (int c = 0; c < Z; c++)
            {
                if ((a + 1) * (b + 1) * (c + 1) > K)
                {
                    break;
                }
                ABC.push_back(A[a] + B[b] + C[c]);
            }
        }
    }
    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());
    for (int i = 0; i < K; i++)
    {
        cout << ABC[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1404
#include <iostream>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    for (int i=0; i<n; i++){
        cin >>a[i];
    }   
    long long ans=1e10;
    for (int i=0; i<n-k+1; i++){
        long long l,r;
        l=abs(a[i])+abs(a[i]-a[i+k-1]);
        r=abs(a[i+k-1])+abs(a[i]-a[i+k-1]);
        long long cand=min (l,r);
        ans=min(ans,cand);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 640
use std::io;
use std::char;

fn main(){
  let hw = read_vu();
  let h = hw[0];
  let w = hw[1];
  let snuke = "snuke".to_string();
  
  for i in 0 .. h {
    let sv = read_vs();
    for j in 0 .. w {
      if sv[j] == snuke {
        println!("{}{}", char::from_u32((65+j) as u32).unwrap(), i+1);
      }
    }
  }
}

fn read_vu() -> Vec<usize> {
   let mut buf = String::new();
   io::stdin().read_line(&mut buf).expect("read error");
   buf.trim().split_whitespace().map(|e| e.parse().unwrap()).collect()
}

fn read_vs() -> Vec<String> {
   let mut buf = String::new();
   io::stdin().read_line(&mut buf).expect("read error");
   buf.trim().split_whitespace().map(|e| e.to_string()).collect()
}


Measured memory_bytes: 4352
S = str(input())
n = len(S)
c = 0
for i in range(0, n//2):
    if S[i] != S[-i-1]:
        c += 1
for j in range(0, (n//2)//2):
    if S[j] != S[n//2-j-1]:
        c += 1
if c > 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
        return

    if self.parents[x] > self.parents[y]:
        x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

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

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

ans = []
ans.append(N * (N - 1) // 2)
uf = UnionFind(N)
for ab in AB[::-1]:
  a, b = ab
  if not uf.same(a-1, b-1):
    sizea = uf.size(a-1)
    sizeb = uf.size(b-1)
    ans.append(ans[-1] - sizea * sizeb)
  else:
    ans.append(ans[-1])
  uf.union(a - 1, b - 1)

for i in ans[::-1][1:]:
  print(i)
                        

Measured memory_bytes: 36052
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int d[200001];
int t[200001];
vector<int> vec;
int cnt[400001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
		vec.push_back(d[i]);
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&t[i]);
		vec.push_back(t[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	for(int i=0;i<n;i++){
		int v=lower_bound(vec.begin(),vec.end(),d[i])-vec.begin();
		cnt[v]++;
	}
	for(int i=0;i<m;i++){
		int v=lower_bound(vec.begin(),vec.end(),t[i])-vec.begin();
		cnt[v]--;
	}
	bool flag=true;
	for(int i=0;i<400000;i++){
		if(cnt[i]<0)flag=false;
	}
	printf("%s\n",flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 4336
class Main
  def self.run
    w, h, x , y, r = read_input
    rectangle = Rectangle.new(w, h)
    circle = Circle.new(x, y, r)
    puts rectangle.include?(circle) ? "Yes" : "No"
  end

  private

  def self.read_input
    gets.split(" ").map(&:to_i)
  end
end

class Rectangle
  def initialize(width, height)
    @width = width
    @height = height
  end

  def include?(circle)
    circle.left >= 0 \
    && circle.right <= @width \
    && circle.bottom >= 0 \
    && circle.top <= @height
  end
end

class Circle
  def initialize(x, y, radius)
    @x = x
    @y = y
    @radius = radius
  end

  def top
    @y + @radius
  end

  def bottom
    @y - @radius
  end

  def left
    @x - @radius
  end

  def right
    @x + @radius
  end
end

Main.run

Measured memory_bytes: 8608
a,b=map(int,input().split())
s=input()

ret=True
for i in range(0,a):
  if not (s[i]=='0' or s[i]=='1' or s[i]=='2' or s[i]=='3' or s[i]=='4' or s[i]=='5' or s[i]=='6' or s[i]=='7' or s[i]=='8' or s[i]=='9'):
    ret=False
if not s[a]=='-':
  ret=False
for i in range(a+1,len(s)):
  if not (s[i]=='0' or s[i]=='1' or s[i]=='2' or s[i]=='3' or s[i]=='4' or s[i]=='5' or s[i]=='6' or s[i]=='7' or s[i]=='8' or s[i]=='9'):
    ret=False

if ret:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064