akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int A[50];
void Calc(){
	int N = rei();
	int K = rei();
	for(int i=0;i<N;i++){
		A[i] = rei();
	}
	vector<int> ans;
	int last = -1;
	{
		int minp = 0;
		for(int i=1;i<N;i++){
			if(A[minp] > A[i]){
				minp = i;
			}
		}
		for(int i=0;i<N;i++){
			if(i != minp){
				ans.push_back(i);
				A[i]--;
			}
		}
		ans.push_back(minp);
		A[minp]--;
		last = minp;
	}
	for(int i=0;i<K;i++){
		int minp = -1;
		for(int i=0;i<N;i++){
			if(i != last){
				if(minp == -1 || A[minp] > A[i]){
					minp = i;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i != minp && i != last){
				ans.push_back(i);
				if(A[i] == 0){
					cout << -1 << endl;
					return;
				}
				A[i]--;
			}
		}
		ans.push_back(minp);
		if(A[minp] == 0){
			cout << -1 << endl;
			return;
		}
		A[minp]--;
		last = minp;
	}
	cout << ans.size() << endl;
	for(int i=0;i<ans.size();i++){
		cout << ans[i]+1;
		if(i == ans.size()-1){
			cout << endl;
		}
		else{
			cout << " ";
		}
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
  char ch_num[1000];
  int num[1000],i,i2,sum;

  while(1){

    for(i=0; i<1000; i++)num[i]=0;
    sum=0,i=0;

    while(1){

      scanf("%c",&ch_num[i]);

      if(ch_num[0]=='0')return 0;

      if(ch_num[i]=='\n'){
	ch_num[i]='0';
	break;
      }

      i++;

    }

    for(i2=0; i2<=i; i2++){

      num[i2]=ch_num[i2]-'0';
      sum+=num[i2];

    }    

    cout<<sum<<"\n";

  }

}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>

using namespace std;
#define ll long long

int main(void){
    int H,W;
    cin>>H>>W;
    vector<string> map(H);
    vector<vector<int>> tate(H,vector<int>(W));
    vector<vector<int>> yoko(H,vector<int>(W));
    vector<vector<int>> kei(H,vector<int>(W));
    
    for(int i=0;i<H;i++) cin>>map.at(i);
    
    for(int i=0;i<H;i++){
        //yokoを求める操作
        int memo=0;
        for(int j=0;j<W;j++){
            if(map.at(i).at(j)=='#'){
                for(int k=0;k<memo;k++) yoko.at(i).at(j-k-1)=memo;
                yoko.at(i).at(j)=0;
                memo=0;
            }
            else memo++;
            if(j==W-1){
                for(int k=0;k<memo;k++) yoko.at(i).at(j-k)=memo;
            }
        }
    }
    for(int i=0;i<W;i++){
        //tateを求める操作
        int memo=0;
        for(int j=0;j<H;j++){
            if(map.at(j).at(i)=='#'){
                for(int k=0;k<memo;k++) tate.at(j-k-1).at(i)=memo;
                tate.at(j).at(i)=0;
                memo=0;
            }
            else memo++;
            if(j==H-1){
                for(int k=0;k<memo;k++) tate.at(j-k).at(i)=memo;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            kei.at(i).at(j)=tate.at(i).at(j)+yoko.at(i).at(j);
        }
    }
    for(int i=0;i<H;i++) sort(kei.at(i).begin(),kei.at(i).end());
    vector<int> maxi(H);
    for(int i=0;i<H;i++) maxi.at(i)=kei.at(i).at(W-1);
    sort(maxi.begin(),maxi.end());
    cout<<maxi.at(H-1)-1<<endl;
    return 0;
}


Measured memory_bytes: 51456
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val (a,b) = readints()
    for(i in 1 .. 1000){
        if(i * 8 / 100 == a && i * 10 / 100 == b){
            println(i)
            return
        }
    }
    println(-1)
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

Measured memory_bytes: 37992
n,a,b = map(int,input().split())
mod = 10**9 + 7
aue,bue = 1,1
for i in range(a):
    aue = aue * (n-i) % mod
for i in range(b):
    bue = bue * (n-i) % mod
asita,bsita = 1,1
for i in range(1,a+1):
    asita = asita*i %mod
for i in range(1,b+1):
    bsita = bsita*i %mod
at = aue * pow(asita,mod-2,mod)
bt = bue * pow(bsita,mod-2,mod)

ans = (pow(2,n,mod) - 1 -at -bt)%mod
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int r; cin >> r;
    string ans = "";
    if (r < 1200) ans = "ABC";
    else if (r < 2800) ans = "ARC";
    else ans = "AGC";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
    int occur[100002] = {}; // occur[i] means occurence of i
    int N = 0;
    int temp = 0;
    scanf("%d", &N);
    for(int i=0; i < N; i++){
        scanf("%d", &temp);
        occur[temp]++;
    }

    int curMax = 0;
    for(int i=1; i <= 100000; i++){
        curMax = max(curMax, occur[i-1] + occur[i] + occur[i+1]);
    }

    printf("%d\n", curMax);

    return 0;
}

Measured memory_bytes: 512
import std.stdio;
import std.algorithm;
 
void main() {
  long n, d2;
  readf("%s %s\n", &n, &d2);
  d2 = d2 * d2;
 
  auto dList = new long[n];
  foreach (ref e;dList) {
    long x, y;
    readf("%s %s\n", &x, &y);
    e = x * x + y * y;
  }
 
  dList.count!((x) => x <= d2).writeln;
}


Measured memory_bytes: 4216
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define R register
using namespace std;
namespace chu_xuan{
    void swap(int &a,int &b){R int tmp=a;a=b,b=tmp;}
    void read(int &a) {a=0;int b=1,c=getchar(); while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b;}
    int In() {int a=0,b=1,c=getchar(); while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*b;}
    int max(int a,int b){return a>b?a:b;}
    int min(int a,int b){return a>b?b:a;}
}using namespace chu_xuan;

int main()
{
    int a,b;
    read(a);read(b);
    if(b%a==0) cout<<a+b;
    else cout<<b-a;
    return 0;
}

Measured memory_bytes: 256
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
S = []
for i in range(N):
    S.append(input())

SS = set(S)
print(len(SS))


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

using namespace std;
typedef long double ld;
int a[2000];
int main() {
    ios_base::sync_with_stdio(false);
    int n = 0, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<long long> vl;
    for (int i = 1; i <= n; i++) {
        long long s = 0;
        for (int j= i; j <= n; j++) {
            s += a[j];
            vl.push_back(s);
        }
    }
    long long ans = 0;
    vector<long long> nvl;
    for (int i = 50; i >= 0; i--) {
        nvl.clear();
        for (auto it: vl) {
            if ((it & (1ll << i)) != 0) nvl.push_back(it);
        }
        if (nvl.size() >= k) {
            ans += (1ll << i);
        }
        else nvl = vl;
        vl = nvl;
    }
    cout << ans << "\n";
    return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;


int main(){
  int A,B;cin >> A >> B;
  char table[110][110];
  for(int i = 0;i < 100;i++){
    for(int j = 0;j < 100;j++){
      if(i < 50){
        table[i][j] = '#';
      }else{
        table[i][j] = '.';
      }
    }
  }
  int cntW = 1,cntB = 1;
  for(int i = 0;i < 50;i += 2){
    for(int j = 0;j < 100;j++){
      if(cntW < A){
        if((i+j) % 2 == 0){
          table[i][j] = '.';
          cntW++;
        }
      }
    }
  }
  for(int i = 99;i >= 50;i -= 2){
    for(int j = 0;j < 100;j++){
      if(cntB < B){
        if((i+j) % 2 == 1){
          table[i][j] = '#';
          cntB++;
        }
      }
    }
  }
  cout << 100 << ' ' << 100 << endl;
  for(int i = 0;i < 100;i++){
    for(int j = 0;j < 100;j++){
      cout << table[i][j];
    }
    cout << endl;
  }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> AB(N);
  for (int i = 0, a, b; cin >> a >> b; i++) AB.at(i) = {a, b};
  sort(AB.begin(), AB.end());
  long ans = 0;
  int it = 0;
  while (M--) {
    if (AB.at(it).second == 0) it++;
    ans += AB.at(it).first, AB.at(it).second--;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func solve() {
	n := getInt()
	ss := getIntSlice(n)
	sort.Ints(ss)
	all := sum(ss...)

	ans := all
	if ans%10 == 0 {
		for i, s := range ss {
			if s%10 != 0 {
				ans -= s
				break
			}

			if i == n-1 {
				ans = 0
			}
		}
	}

	fmt.Fprintln(wr, ans)
}

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> h(n);
    for(int i = 0; i < n; i++)  cin >> h[i];
    vector<pair<int,int>> v[n];
    while(m-- > 0){
        int a, b, t;
        cin >> a >> b >> t;
        a--, b--;
        if(h[a]-t >= 0) v[a].push_back({b,t});
        if(h[b]-t >= 0) v[b].push_back({a,t});
    }
    priority_queue<pair<ll,pair<int,int>>> pq;
    pq.push({-0, {0, x}});
    vector<ll> dp(n, 1ll<<60);
    ll ans = 1ll<<60;
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        ll cost = -p.first;
        int pos = p.second.first, height = p.second.second;
        if(dp[pos] <= cost) continue;
        dp[pos] = cost;
        if(pos == n-1){
            ans = min(ans, cost + h[n-1]-height);
            continue;
        }
        for(auto q : v[pos]){
            int npos = q.first, nt = q.second;
            ll ncost = cost + nt;
            int nheight = height-nt;
            if(nheight < 0)             ncost += -(nheight), nheight = 0;
            else if(nheight > h[npos])  ncost += nheight-h[npos], nheight = h[npos];
            if(ncost < dp[npos]){
                pq.push({-ncost, {npos, nheight}});
            }
        }
    }

    cout << (ans == 1ll<<60 ? -1 : ans) << endl;
    return 0;
}


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

using namespace std;

typedef long long int lli;

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

    int n, v[50];

    cin >> n;
    for (int i=0; i<n; i++) cin >> v[i];
    sort(v, v+n);

    double ans = v[0];
    for (int i=1; i<n; i++) {
        ans = (ans+v[i]) / 2.;
    }

    printf("%.10f\n", ans);

    return 0;
}


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

using namespace std;
int ax[100015];
int n;

int main()
{
    scanf("%d",&n);
    int i,a;
    for(i=0;i<n;i++){
        scanf("%d",&a);
        ax[a-1]++;ax[a]++;ax[a+1]++;
    }
    int res=0;
    for(i=0;i<100005;i++)res = max(res,ax[i]);
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define OUT(x) cout << x << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main(){
  ll n,h,w;
  cin >> n >> h >> w;
  int ans=0;
  vector<LP> a(n);
  REP(i,n){
    cin >> a[i].first >> a[i].second;
  }
  REP(i,n){
    if(a[i].first>=h && a[i].second>=w) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int mem[100050];

int main()

{
	int a[100050];
	int n;
	
	cin>>n;
	
	for(int i=1;i<=n;i++)
	cin>>a[i];
	
	mem[n-1] = abs(a[n] - a[n-1]);
	mem[n] = 0;
	
	for(int i=n-2;i>0;i--)
	{
		mem[i] = min( abs (a[i+1] - a[i]) + mem[i+1] , abs (a[i+2] - a[i]) + mem[i+2] );
	}
	
	cout<<mem[1];
	
	
	
	
	
	
	
}

Measured memory_bytes: 1024
//
// Created by kuroneko on 2019-07-27.
//

#include <iostream>
#include <string>
#include <cmath>
#include <cstring>

#define MOD 1000000007LL

using namespace std;
typedef long long ll;

ll dp[100005][13];
int main() {
    string s; cin >> s;

    dp[0][0] = 1;
    for (int i = 0; i < s.size(); i++) {
        int c;
        if (s[i] != '?') c = s[i] - '0';
        else c = -1;
        for (int k = 0; k < 13; k++) {
            for (int j = 0; j < 10; j++) {
                if (c != -1 && c != j) continue;
                dp[i+1][(k * 10 + j) % 13] += dp[i][k];
                dp[i+1][(k * 10 + j) % 13] %= MOD;
            }
        }
    }

    cout << dp[int(s.size())][5] << endl;
    return 0;
}


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

long long int D = 10000000000;
long long int dp[10][102][1000];
int n, s;

void set(){
    int x, y, z;
    for(x = 0; x < 10; x++){
        for(y = 0; y < 102; y++){
            for(z = 0; z <= 1000; z++){
                dp[x][y][z] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    for(x = 0; x < 10; x++){
        for(y = 1; y <= 101; y++){
            for(z = 0; z < 1000; z++){
                dp[x][y][z] += dp[x][y-1][z];
                if(x && z >= y-1){
                    dp[x][y][z] += dp[x-1][y-1][z-y+1];
                }
                dp[x][y][z] %= D;
            }
        }
    }
}

int main(){
    set();
    while( cin >> n >> s, n|s ){
        long long int ans = 0;
        cout << dp[n][101][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 9124
def resolve():
    n = int(input())
    s = input()
    if len(set(s)) == 1:
        print(0)
    else:
        acc_w, acc_b = [], []
        w, b = 0, 0
        for i in range(n):
            if s[i] == ".":
                w += 1
            else:
                b += 1
            acc_w.append(w)
            acc_b.append(b)
        w = s.count(".")
        b = s.count("#")
        ans = min(w, b)
        for i in range(n - 1):
            if s[i] == "." and s[i + 1] == "#":
                t = acc_b[i] + w - acc_w[i]
                if t < ans:
                    ans = t
        print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 12800
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		HashMap<String, Integer> cnt = new HashMap<>();
		for (int i = 0; i < N; ++i) {
			String s = sorted(in.next());
			cnt.put(s, cnt.getOrDefault(s, 0) + 1);
		}
		
		long ans = 0;
		for (String s : cnt.keySet()) {
			ans += nc2(cnt.get(s));
		}
		
		System.out.println(ans);
	}
	
	private static long nc2(long x) {
		return (x * (x - 1)) >> 1;
	}
	
	private static String sorted(String s) {
		char[] arr = s.toCharArray();
		Arrays.sort(arr);
		return new String(arr);
	}
}

Measured memory_bytes: 55544
n = int(input())
A = list(map(int,input().split()))
for i in A:
    i = int(i)

def h(n,A):
    res = float('inf')
    f = []
    b = []
    t = 0
    for i in range(len(A)):
        t+=A[i]
        f.append(t)
    t = 0
    for i in range(len(A)-1,-1,-1):
        t += A[i]
        b.append(t)
    b.reverse()
    for i in range(len(A)-1):
        temp1 = f[i]
        temp2 = b[i+1]
        res = min(res,abs(temp1-temp2))
        
    #print(f)
    #print(b)
    print(res)
    
    
    
h(n,A)

Measured memory_bytes: 30960
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
int n, L, T, x[N], w[N], ans[N];
int f[3];
vector <int> p[3];

int get1(int add, int j) {
    int t = add - x[j];
    if (t < 0)
        return 0;
    else            
        return t / L + 1;
}   
int get2(int add, int j) {
    int t = add - (L - x[j]);
    if (t < 0)
        return 0;
    else            
        return t / L + 1;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    f[1] = 1;
    f[2] = -1;
    cin >> n >> L >> T;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> w[i];
        p[w[i]].app(i);
    }        

    for (int i = 0; i < n; ++i) { 
        int sh = 0;

        if (w[i] == 1) {
            vector <int> &v = p[3 - w[i]];
            int l = -1;
            int r = v.size();
            while (l < r - 1) {
                int m = (l + r) >> 1;
                int j = v[m];
                if (x[j] - x[i] < 2 * T)
                    l = m;
                else
                    r = m;   
            }   
            sh += max(0ll, l - (upper_bound(all(v), i) - v.begin()) + 1);
            
            if (v.size()) {
                int add = 2 * T - 1 - (L - x[i]);
                int l = 0;
                int r = v.size();
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (get1(add, v[m]) == get1(add, v[0]))
                        l = m;
                    else
                        r = m;
                }            
                sh += get1(add, v[0]) * v.size() - (v.size() - r);
            }
        }
        else {
            vector <int> &v = p[3 - w[i]];
            int l = -1;
            int r = v.size();
            while (l < r - 1) {
                int m = (l + r) >> 1;
                int j = v[m];
                if (x[i] - x[j] < 2 * T)
                    r = m;
                else 
                    l = m;
            }   
            sh += max(0ll, (upper_bound(all(v), i) - v.begin()) - r);
            
            
            if (v.size()) {
                int add = 2 * T - 1 - x[i];
                int l = 0;
                int r = v.size();
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (get2(add, v[m]) == get2(add, v[0]))
                        l = m;
                    else
                        r = m;
                }            
                sh += get2(add, v[0]) * v.size() + (v.size() - r);
            }
        }

        int to = x[i] + T * f[w[i]];
        to = (to % L + L) % L;

        int num = i + sh * f[w[i]];
        num = (num % n + n) % n;

        ans[num] = to;
    }           
    for (int i = 0; i < n; ++i)
        cout << ans[i] << endl;
}


Measured memory_bytes: 4596
#include<iostream>

using namespace std;
int main(void) {
	int A, B, C;
	cin >> A >> B;
	if (A % 2 != 0 && B % 2 != 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

using namespace std;
typedef long long ll;
const int mod = 1000000007;
int INF = 1001001001;

int main() {
    ll l, r;
    cin >> l >> r;
    if ((r - l) >= 2018) {
        cout << 0 << endl;
        return 0;
    }
    int ml, mr;
    mr = r % 2019;
    ml = l % 2019;

    int ans = INF;
    vector<int> x;
    
    if (ml < mr) {
        for (int i = ml; i <= mr; ++i) x.push_back(i);
    } else {
        cout << 0 << endl;
        return 0;
    }
    rep(i,x.size())rep(j,x.size()) {
        if (i==j) continue;
        else {
            int tmp = x[i] * x[j] % 2019;
            if (ans > tmp) ans = tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]

import bisect


x,y = MI()
if y % 2 ==0 and 2 * x <= y <= 4*x:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 27188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
//#include <vector>
//#include <functional>
template<typename Abel>
struct WeightedUnionFind {
    using OP = function<Abel(Abel, Abel)>;

    vector<int> parent;
    vector<Abel> diff_weight; // distance from root
    const OP add;
    const OP sub;
    const Abel e;
    
    WeightedUnionFind(int nmemb,
                      const Abel &e = 0,
                      const OP &add = [](Abel x, Abel y){return x+y;},
                      const OP &sub = [](Abel x, Abel y){return x-y;}):
        e(e), add(add), sub(sub)
    {
        parent.assign(nmemb, -1);
        diff_weight.assign(nmemb, e);
    };

    int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        
        int p = root(parent[x]);
        diff_weight[x] = add(diff_weight[x], diff_weight[parent[x]]);
        parent[x] = p;

        return p;
    };

    bool unite(int x, int y, Abel w) {
        Abel wx = weight(x);
        Abel wy = weight(y);
        x = root(x);
        y = root(y);

        if (x == y) return false;
        w = sub(add(w, wx), wy);
        if (size(x) < size(y)) swap(x, y), w = -w;

        parent[x] += parent[y];
        parent[y] = x;
        diff_weight[y] = w;
        
        return true;
    };
    
    bool same(int x, int y) {
        return root(x) == root(y);
    };
    
    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    };

    Abel diff(int x, int y) {
        return sub(weight(y), weight(x));
    };

    int size(int x) {
        return -parent[root(x)];
    };
};
//===

int main() {
    llong n, m;
    llong l, r, d;

    cin >> n >> m;
    WeightedUnionFind<llong> uf(n);

    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d;
        --l, --r;
        uf.unite(l, r, d);

        if (uf.diff(l, r) != d) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#define int long long
using namespace std;
int n, ai;
vector<int> data, when;
int M = 1000000007;
vector<int> fact;
int gcd (int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd (b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
int get(int nn, int kk){
    int el = (fact[nn - kk] * fact[kk]) % M;
    int x, y;
    gcd(el, M, x, y);
    el = x;
    el *= fact[nn];
    return el % M;
}
signed main()
{
    fact.push_back(1);
    fact.push_back(1);
    int now = 1;
    for (int i=2;i<=1e6;i++){
        now *= i;
        now %= M;
        fact.push_back(now);
    }
    cin >> n;
    for (int i=0;i<n;i++){
        when.push_back(-1);
    }
    int f, s;
    for (int i=0;i<n+1;i++){
        cin >> ai;
        data.push_back(ai);
        if (when[ai-1] == -1){
            when[ai-1] = i;
        }
        else{
            f = when[ai-1];
            s = i;
        }
    }
    int diff = s - f;
    for (int i=0;i<=n;i++){
        int pl = get(n+1, i+1);
        int mn = 0;
        if (n - diff >= i){
            mn = get(n-diff, i);
        }
        int ans = pl - mn;
        ans %= M;
        ans += M;
        ans %= M;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 13416
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

#define int long long

signed main() { 
        int n;
        cin >> n;
        vector<int> a(n + 1), b(n + 1);
        rer(i, 1, n) {
                a[i] = i;
                b[i] = 1000000000 - i;
        }
        rer(i, 1, n) {
                int x;
                cin >> x;
                rer(j, x, n) b[j] -= n - i;
                rer(j, x + 1, n) a[j] += n - i;
        }
        rer(i, 1, n) cout << a[i] << (i == n ? '\n' : ' ');
        rer(i, 1, n) cout << b[i] << (i == n ? '\n' : ' ');
        return 0;
}               


Measured memory_bytes: 896
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n, x, cnt = 0;
	cin >> n >> x;
	vector<int>m(n);
	for (int& p : m)cin >> p;
	sort(m.begin(), m.end());

	for (int i = 0; i < n; i++) {
		x -= m[i];
		if (x >= 0)cnt++;
		else { x += m[i]; break; }
	}

	cout << cnt + x/m[0] << endl;
}


Measured memory_bytes: 256
s = int(input())
def f(k):
  if k % 2 ==0:
    return k//2
  else:
    return 3*k+1

ary1 = [None]*1000001
ary1[1] = s

for i in range(2,1000001):
  fn = f(ary1[i-1])
  if fn in ary1:
    print(i)
    break
  else:
    ary1[i] = fn

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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String str = reader.readLine();
			String[] arr = str.split(" ");
			int a = Integer.parseInt(arr[0]);
			int b = Integer.parseInt(arr[1]);
			int c = Integer.parseInt(arr[2]);
			int temp;
			
			if (a > b) {
				temp = a;
				a = b;
				b = temp;
			}
			
			if (b > c) {
				temp = b;
				b = c;
				c = temp;
			}
			
			if (a > b) {
				temp = a;
				a = b;
				b = temp;
			}
			
			System.out.println(a + " " + b + " " + c);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int cnt = 0;
    for (int i = 1; i < n-1; i++) {
        vector<int> v = {p[i-1],p[i],p[i+1]};
        sort(v.begin(),v.end());
        if (v[1] == p[i]) cnt++;
    }
    cout << cnt << '\n';
}



Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
  list($a,$b,$c)=explode(' ',trim(fgets(STDIN)));
  if($b<$a){$d=$a;$a=$b;$b=$d;}
  if($c<$b){$d=$b;$b=$c;$c=$d;}
  $e=$a*$a+$b*$b;
  $f=$c*$c;
  echo ($e==$f)?'YES':'NO',PHP_EOL;
}

Measured memory_bytes: 15084
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100][100001];
int main()
{
  ll n,i,W,j;
  cin>>n>>W;
  ll w[n],v[n];
  for(i=0;i<n;i++)
   cin>>w[i]>>v[i];
  for(j=0;j<100001;j++)
      dp[0][j]=INT_MAX;
  for(i=0;i<100;i++)
   dp[i][0]=0;
  dp[0][v[0]]=w[0];
  for(i=1;i<n;i++)
  {
      for(j=0;j<=100000;j++)
      {
          dp[i][j]=dp[i-1][j];
          if(j-v[i]>=0 && dp[i-1][j-v[i]]+w[i]<dp[i][j])
            dp[i][j]=dp[i-1][j-v[i]]+w[i];
      }
  }
  ll ans=0;
  for(i=100000;i>=0;i--)
  {
      for(j=n-1;j>=0;j--)
      {
          if(dp[j][i]<=W)
          {
              ans=i;
              break;
          }
      }
      if(ans>0)
       break;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 78336
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> left(n+1), right(n+1);
    rep(i,0,n){
        left[i + 1] = gcd(left[i], a[i]);
    }
    rrep(i,n+1, 1){
        right[i-1] = gcd(right[i], a[i-1]);
    }
    ll ans = 0;
    rep(i,0,n){
        chmax(ans, gcd(left[i], right[i + 1]));
    }
    debug(left, right);
    cout << ans << "\n";
}

Measured memory_bytes: 5576
#include<iostream>
using namespace std;
void swap(int *a, int *b){
	int temp; temp = *a;
	*a = *b;
	*b = temp;
}

void quick_sort_sub_inv(int *data, int left, int right){
	int right_flag = right;
	int left_flag = left;
	int pivot = data[(right + left) / 2];
	int *data_right_flag;
	int *data_left_flag;

	while(right_flag >= left_flag){
		for(; data[right_flag] < pivot; right_flag --){
			if(right_flag == left){
				break;
			}
		}

		for(; data[left_flag] > pivot; left_flag ++){
			if(left_flag == right){
				break;
			}
		}

		if(right_flag >= left_flag){
			data_right_flag = data + right_flag;
			data_left_flag = data + left_flag;
			swap(data_right_flag, data_left_flag);
			right_flag --;
			left_flag ++;
		}
	}

	if(right_flag > left){
		quick_sort_sub_inv(data, left, right_flag);
	}
	if(left_flag < right){
		quick_sort_sub_inv(data, left_flag, right);
	}
}

void quick_sort_inv(int *data, int data_size){
	quick_sort_sub_inv(data, 0, data_size - 1);
}

int fact(int n){
	if(n == 0)
		return 1;
	else
		return n * fact(n - 1);
}

int* del(int *array, int point, int size){
	int i;
	for(i = point; i < size - 1; i ++){
		array[i] = array[i + 1];
	}

	return array;
}

int *jisho(int *array, int num, int size){
	int keisu[size];
	--num;

	for(int i = size - 1;  i >= 0; --i){
		keisu[i] = num / fact(i);
		num = num % fact(i);
	}

	int flag[size];
	
	for(int i = size - 1; i >=  0; --i){
		flag[i] = array[keisu[i]];
		del(array, keisu[i], i + 1);
	}

	for(int i = 0; i < size; ++i)
		array[i] = flag[i];
	
	return array;

}

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

	int load[m][2];

	for(int i = 0; i < m; ++i)
		cin >> load[i][0] >> load[i][1];

	int count = 0;
	int array[n];
	bool judge = 0;
	for(int i = 0; i < n; ++i)
		array[i] = i + 1;

	for(int i = 1; i <= fact(n - 1); ++i){	
		for(int y = 0; y < n; ++y)
			array[y] = y + 1;

		jisho(array + 1, i, n - 1);

			/*		for(int y = 0; y < n; ++y)
						cout << array[y];
					cout << endl;*/
		for(int j = 0; j < n - 1; ++j){
			for(int k = 0; k < m; ++k){
				if((array[j] == load[k][0] && array[j + 1] == load[k][1]) || (array[j] == load[k][1] && array[j + 1] == load[k][0])) {
					judge = 1;
					//if(array[0] == 1 && array[1] == 6 && array[2] == 7 && array[3] == 5 && array[4] == 4 && array[5] == 2 && array[6] == 3)
					//	cout << array[j] << ", " << array[j + 1] << endl;
					break;
				}
			}
			if(judge == 0)
				break;
			else{
				judge = 0;
				if(j == n - 2){
					++count;
				/*	for(int y = 0; y < n; ++y)
						cout << array[y];
					cout << "OK!" << endl;*/
				}
			}
		}
	}

	cout << count << endl;

	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++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

ll f(ll x)
{
  if(x == 0) return 0;
  if(x == 1) return 1;
  if(x == 2) return 3;
  if(x == 3) return 0;

  ll y = 1; 
  while(y*2 <= x){
    y *= 2;
  }

  ll res = 0;
  if(x%2 == 0){
    res = y + f(x-y); 
  }else{
    res = f(x-y);
  }

  return res;
}

int main()
{
  ll a, b;
  cin >> a >> b;

  if(a == 0) a++;

  cout << (f(a-1)^f(b)) << endl; 

  return 0;
}


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

using namespace std;

int main(){
	char s[101];
	scanf("%s",s);
	for (int i = 1; i <= 101; i++){
		if((i%2 == 0 && s[i-1] == 'R') || (i%2 == 1 && s[i-1] == 'L')){
			printf("No");
			break;
		}
		if (s[i-1] == '\0'){
			printf("Yes");
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 256
def get_int
  gets.to_i
end

def get_int_array
  gets.chomp.split(' ').map(&:to_i)
end

def main
  n = get_int
  ab = get_int_array
  a = ab[0]
  b = ab[1]

  p_s = get_int_array.sort

  a_candidates = p_s.select{|p| p <= a }
  b_candidates = p_s.select{|p| p > b }
  others = p_s - a_candidates - b_candidates

  p [a_candidates.length, b_candidates.length, others.length].min
end

main


Measured memory_bytes: 1788
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
using namespace std;
using Data = pair<long long, vector<int> >;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;
typedef long long int ll;
const int mod = 1e9+7;

const int INF = 1e9;

struct edge{int to,cost;};

int V;
vector<edge> G[100000];
int d[100000];

void dfs(int v,int p,int c){
    d[v] = c;
    for(auto e:G[v]){
        if(p==e.to) continue;
        if(e.cost%2==0) dfs(e.to,v,c);
        else  dfs(e.to,v,1-c);
    }
}

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

    REP(i,n-1){
        int u,v,w;cin >> u >> v >> w;
        u--;v--;
        edge e1;e1.to=v;e1.cost=w;
        G[u].push_back(e1);
        edge e2;e2.to=u;e2.cost=w;
        G[v].push_back(e2);
    }

    dfs(0,0,1);

    REP(i,n) {
        pl(d[i])
    }
}

Measured memory_bytes: 9216
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
H,W = map(int,readline().split())
A = [list(map(int,readline().split())) for _ in range(H)]
B = [list(map(int,readline().split())) for _ in range(H)]
 
X = (H + W) * 80
# X点持った状態から始める
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = (1 << (X - d))
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = 0
        if h != 0:
            x |= (dp[h-1][w] << d) 
            x |= (dp[h-1][w] >> d)
        if w != 0:
            x |= (dp[h][w-1] << d) 
            x |= (dp[h][w-1] >> d)
        dp[h][w] = x
 
dp = dp[-1][-1]
 
B = bin(dp)[2:]
can_make = [i - X for i,b in enumerate(B[::-1]) if b == '1']
 
answer = min(x if x >= 0 else -x for x in can_make)
print(answer)

Measured memory_bytes: 20724
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	char al;
	scanf("%c", &al);
	if(al == 'a' || al == 'e' || al == 'i' || al == 'o' || al == 'u')
		printf("vowel\n");
		else
			printf("consonant\n");
}

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

using namespace std;

long long d[100001];
vector<pair<int, long long> > edge[100001];

void dfs(int u, int p, long long len){
    d[u] = len;
    for (auto v: edge[u])
        if (v.first != p) dfs(v.first, u, len + v.second);
}

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--, b--;
        edge[a].push_back({b, c});
        edge[b].push_back({a, c});
    }
    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, k, 0);
    for (int i = 0; i < q; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        cout << d[a] + d[b] << "\n";
    }
    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll A[200010];
ll B[200010];

int main(){
    ll N,K;
    cin >> N >> K;
    rep(i,N){
        cin >> A[i];
        A[i]--;
    }
    ll now = 0,M = 0,cnt = 0,s = 0;
    rep(i,N*2+1){
        //cout << bra(now+1,B[now]) << ' ';
        cnt++;
        if(B[now] != 0 || (now == 0 && i != 0)){
            M = i - B[now];
            s = now;
            //cout << now + 1 << ' ' << B[now] << endl;
            break;
        }
        B[now] = i;
        now = A[now];
    }
    //cout << endl;
    ll ans = 0;
    if(K <= N * 2){
        rep(i,K) ans = A[ans];
    }else{
        ans = now;
        rep(i,(K-B[now]) % M) ans = A[ans];
    }
    cout << ans + 1 << endl;
} 


Measured memory_bytes: 6744
n = int(input())

a_list = []
b_list = []
t = []
for i in range(n):
  a, b = map(int, input().split())
  t.append({"time": a, "limit": b})
  a_list.append(a)
  b_list.append(b)
  
s = sorted(t, key=lambda x: x["limit"])

time = 0
for ss in s:
  time += ss['time']
  if time > ss['limit']:
    print('No')
    exit(0)

print('Yes')


Measured memory_bytes: 83468
#include<stdio.h>
int c[102];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]>s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  merge(0,n-1,a);
  int count=0;
  for(i=0;i<n;i++){
    if(i%2==0)
      count+=a[i];
    else
      count-=a[i];
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
LST = input().split(" ")
D = int(LST[0])
X = int(LST[1])

a = 0
a += X
if D != 0:
    a += N

for i in range(N):
    d = int(input())
    a += int(D/d)
    if D%d ==0:
        a -= 1
        
print(a)
        

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut l = Vec::new();
    let mut r = Vec::new();
    for _i in 0..m {
        l.push(read::<isize>() - 1);
        r.push(read::<isize>() - 1);
    }
    let a = l.iter().max().unwrap();
    let b = r.iter().min().unwrap();
    println!("{}", max(0, b - a + 1));
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int cntA = 0, cntB = 0;
    for (int i = 0; i < n; i++) {
        if (cntA + cntB >= a + b) cout << "No" << endl;
        else if (s.at(i) == 'a') {
            cout << "Yes" << endl;
            cntA++;
        }
        else if (s.at(i) == 'b' && cntB < b) {
            cout << "Yes" << endl;
            cntB++;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 896
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    r,g,b = LI()
    ans = ["YES","NO"]
    print(ans[((g<<1)+b)&3>0])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int c0 = std::max(a ,b);
    if (a > b) {
        a -= 1;
    } else {
        b -= 1;
    }
    int c1 = std::max(a ,b);
    cout << c0 + c1;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
bool data[10000001];

int main(){
	int n,a,b;
	
	while(cin >> n >> a >> b, (n||a||b) ){
		memset(data,0,10000001);
		data[0] = true;
		int r = 0;
		for(int i=a;i<=n;i+=a)data[i] = true;
		for(int i=1;i<=n;i++){
			if( data[i] || (i-b>=0 && data[i-b]) ){
				r++;
				data[i] = true;
			}
		}
		cout << n-r << endl;
	}
}

Measured memory_bytes: 10000