akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define view(u,k) for(int k=fir[u];~k;k=nxt[k])
#define LL long long
#define maxn 500007
using namespace std;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')f=-1,ch=getchar();
    while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return x*f;
}
void write(int x)
{
    if(x==0){putchar('0'),putchar('\n');return;}
    int f=0;char ch[20];
    if(x<0)putchar('-'),x=-x;
    while(x)ch[++f]=x%10+'0',x/=10;
    while(f)putchar(ch[f--]);
    putchar('\n');
    return;
}
char s[maxn];
int a[maxn],now,sum,len;
int main()
{
    //freopen("increasing.in","r",stdin);
    //freopen("increasing.out","w",stdout);
    scanf("%s",s);len=strlen(s);
    dwn(i,len-1,0)a[len-i]=s[i]-'0';
    rep(i,1,len)a[i]*=9;
    rep(i,1,len)if(a[i]>9)
    {
    	if(i==len)len++;
    	a[i+1]+=a[i]/10,a[i]=a[i]%10;
    }
    rep(i,1,len)sum+=a[i];
	while(1)
    {
    	now+=9;sum-=a[1];
    	a[1]+=9;int i=1;
    	while(a[i]>9){a[i]-=10,sum+=a[i]-a[i+1],a[i+1]++,i++;}
    	sum+=a[i];
    	if(now>=sum){write(now/9);break;}
    }
    return 0;
}

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

#define ll long long
#define pb push_back
#define INF 1e9+7
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;
	ll c=max(a,b)+max(max(a,b)-1,min(a,b));
	cout<<c;
	
	
	
	return 0;
}


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

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)==3)
    {
        int re;
        if(a==b&&a!=c)
            re=c;
        if(a==c&&a!=b)
            re=b;
        if(b==c&&b!=a)
            re=a;
        printf("%d\n",re);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>

using namespace std;

#define P(s) cout << s << endl;
#define PVEC(v) cout << "vector: "; for(auto i = v.begin(); i != v.end(); ++i) cout << *i << ","; cout << endl;
#define PSET(v) cout << "set: "; for(auto i = v.begin(); i != v.end(); ++i) cout << *i << ","; cout << endl;
#define PMAP(m) cout << "map: "; for(auto elem : m)  elem.first << "->" << elem.second ", "; cout << endl;
#define DEBUG(x) cout << #x << ": " << x << endl;

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

  set<pair<int, int>> pathSet;
  for(int i = 0; i < m ; i++) {
    int a, b;
    cin >> a >> b;
    pathSet.insert(make_pair(a, b));
    pathSet.insert(make_pair(b, a));
  }

  bool is_possible = false;
  for(int second = 2; second < n ; second++) {
    if (pathSet.count(make_pair(1, second)) > 0) {
      if(pathSet.count(make_pair(second, n)) > 0) {
        is_possible = true;
        break;
      }
    }
  }

  if (is_possible) {
    cout << "POSSIBLE" << endl;
  } else { 
    cout << "IMPOSSIBLE" << endl;
  }
}


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

// 累積演算 (0-indexed・prefix, suffix, 任意連続部分列)
// 任意連続部分列は逆演算があるときのみできる？

template <typename MonoidType>
struct Accumulation {
    int n;
    vector<MonoidType> pre, suf;
    MonoidType E;
    
    using MMtoM = function< MonoidType(MonoidType, MonoidType) >;
    MMtoM op, rop;

    void build(int m, vector<MonoidType> vec) {
        pre = suf = vector<MonoidType>(m+1, E);
        for(int i=0; i<m; i++) {
            pre[i+1] = op(pre[i], vec[i]);
        }
        for(int i=m-1; i>=0; i--) {
            suf[i] = op(suf[i+1], vec[i]);
        }
    }

    Accumulation() {}
    Accumulation(vector<MonoidType> val_array, MonoidType E_,
                 MMtoM op_, MMtoM rop_ = MMtoM()) :
        E(E_), op(op_), rop(rop_) {
        n = val_array.size();
        build(n, val_array);
    }

    // [0, k)
    inline MonoidType get_prefix(int k) { return pre[k]; }
    // [k, n)
    inline MonoidType get_suffix(int k) { return suf[k]; }
    // [l, r) (rop が定義されてるときのみ)
    inline MonoidType get_subseq(int l, int r) {
        return rop(pre[r], pre[l]);
    }
};

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

// Verified on Apr 28, 2019 (prefix, suffix のみ)
// Judge: https://atcoder.jp/contests/abc125/tasks/abc125_c
void ABC125_C() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    
    Accumulation<int> acc(A, 0,
                          [](int a, int b) { return gcd(a, b); });

    int ans = 0;
    for(int i=0; i<N; i++) {
        int vl = acc.get_prefix(i), vr = acc.get_suffix(i+1);
        ans = max(ans, gcd(vl, vr));
    }
    cout << ans << endl;
}

int main() {
    ABC125_C();
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<max(a,max(b,c))-min(a,min(b,c))<<endl;
}

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

class TNode
{
	std::list<std::pair<TNode*, int> > FNexts;
	int  FDistance;
public:
	TNode()
	: FDistance(-1)
	{
	}
	
	int GetDistance()const {return FDistance;}
	
	void Push(TNode* New, int Weight)
	{
		FNexts.push_back(std::make_pair(New, Weight));
	}
	
	void Visit(int Distance)
	{
		if(FDistance >= 0 && Distance > FDistance) return;
		FDistance = Distance;
		for(std::list<std::pair<TNode*, int> >::iterator It = FNexts.begin(); It != FNexts.end(); ++It){
			It->first->Visit(Distance + It->second);
		}
	}
};

class TGraph
{
	std::vector<TNode*> FNodes;
public:
	TGraph(int Count)
	: FNodes(Count)
	{
		for(int i = 0; i < Count; ++i){
			FNodes[i] = new TNode();
		}
	}
	
	~TGraph()
	{
		for(unsigned int i = 0; i < FNodes.size(); ++i){
			delete FNodes[i];
		}
	}
	
	void InputNode()
	{
		int Index;
		std::cin >> Index;
		int BranchCount;
		std::cin >> BranchCount;
		for(int i = 0; i < BranchCount; ++i){
			int Target, Weight;
			std::cin >> Target >> Weight;
			FNodes[Index]->Push(FNodes[Target], Weight);
		}
	}
	
	void BreathFirstSearch()
	{
		FNodes[0]->Visit(0);
	}
	
	int Distance(int Target)const
	{
		return FNodes[Target]->GetDistance();
	}
};

int main()
{
	int Count;
	std::cin >> Count;
	TGraph Graph(Count);
	for(int i = 0; i < Count; ++i){
		Graph.InputNode();
	}
	Graph.BreathFirstSearch();
	
	for(int i = 0; i < Count; ++i){
		std::cout << i << " " << Graph.Distance(i) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <set>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  int n = 0;
  cin >> n;
  if(n >= 400 && n <= 599)cout << 8 << endl;
  else if(n >= 600 && n <= 799)cout << 7 << endl;
  else if(n >= 800 && n <= 999)cout << 6 << endl;
  else if(n >= 1000 && n <= 1199)cout << 5 << endl;
  else if(n >= 1200 && n <= 1399)cout << 4 << endl;
  else if(n >= 1400 && n <= 1599)cout << 3 << endl;
  else if(n >= 1600 && n <= 1799)cout << 2 << endl;
  else if(n >= 1800 && n <= 1999)cout << 1 << endl;
}


Measured memory_bytes: 3632
'use strict'

function main(input) {
    input = input.split('').map(v => ~~v)

    let ans = 'No'
    if ((input[0] == input[1]) && (input[1] == input[2]) && (input[0] == input[2])) ans = 'Yes'
    if ((input[1] == input[2]) && (input[2] == input[3]) && (input[1] == input[3])) ans = 'Yes'

    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll aa=1,pp=1,qq=1,ww=1;
    for(int i=0;i<n;i++ )
    {
        aa*=10;
        pp*=9;
        qq*=9;
        ww*=8;
        aa%=1000000007;
        pp%=1000000007;
        qq%=1000000007;
        ww%=1000000007;
    }
    cout<<((aa-pp-qq+ww)%1000000007+1000000007)%1000000007;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

string s[1010];
vector<int> G[1010];

void dfs(int v, int dep){
    if(v != 0){
        rep(i, dep) printf("%c", '.');
        cout << s[v] << "\n";
    }
    for(int nv: G[v]) dfs(nv, dep+1);
}

int main(){
    int n;
    scanf("%d", &n);
    For(i, 1, n+1){
        int K;
        scanf("%d", &K);
        G[K].push_back(i);
        cin >> s[i];
    }
    dfs(0, -1);
}


Measured memory_bytes: 3444
#include <cstdio>
#include <cstdlib>
#define INF (__INT32_MAX__ / 2)
#define MAX_NM 20

using namespace std;

int N, M, C;
int B[MAX_NM];
int A[MAX_NM][MAX_NM];

int main(int argc, char **argv) {
    scanf("%d %d %d", &N, &M, &C);
    for(int i = 0; i < M; ++i)
        scanf("%d", B + i);

    for(int i = 0; i < N; ++i)
        for(int j = 0; j < M; ++j)
            scanf("%d", &A[i][j]);

    int res = 0;
    for(int i = 0; i < N; ++i) {
        int sum = C;
        for(int j = 0; j < M; ++j)
            sum += A[i][j] * B[j];
        
        if(sum > 0)
            ++res;
    }
    printf("%d\n", res);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string str;
	cin >> str;
	int kcount = 0, ucount = 0, pcount = 0, ccount = 0;
	for(int i = 0; i < str.size(); ++i)
	{
		if(str[i] == 'K')
		{
			++kcount;
		}
		else if(str[i] == 'U')
		{
			++ucount;
		}
		else if(str[i] == 'P')
		{
			++pcount;
		}
		else if(str[i] == 'C')
		{
			++ccount;
		}
	}
	int min = 999999999;
	if(kcount < min)
	{
		min = kcount;
	}
	if(ucount < min)
	{
		min = ucount;
	}
	if(pcount < min)
	{
		min = pcount;
	}
	if(ccount < min)
	{
		min = ccount;
	}
	cout << min << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1188
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int H, W;
  cin >> H >> W;

  map<int, int> dests;
  multiset<int> lengths;

  for (int x = 1; x <= W; ++x) {
    dests[x] = x;
    lengths.insert(0);
  }

  int a, b;
  for (int k = 1; k <= H; ++k) {
    cin >> a >> b;

    auto it = dests.lower_bound(a);
    int max_f = -1;

    while (it != dests.end() && it->first <= b + 1) {
      int dest = it->first;
      int from = it->second;

      max_f = max(max_f, from);
      int len = dest - from;
      // fprintf(stderr, "len: %d\n", len);
      lengths.erase(lengths.find(len));

      dests.erase(it++);
    }

    if (max_f != -1 && b < W) {
      lengths.insert(b - max_f + 1);
      dests[b + 1] = max_f;
    }

    /*
    for (auto it : dests) {
      fprintf(stderr, "%d -> %d\n", it.second, it.first);
    }
    */

    if (lengths.empty()) {
      cout << -1 << endl;
    } else {
      cout << *lengths.begin() + k << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 22356
N=int(input())
D=[0]+sorted(map(int,input().split()))

B=[0]*13
for d in D:B[d]+=1
ans=1
if max(B)>2 or max(B[0],B[12])>1:ans=0
if ans>0:
    v1=[]
    v2=[0]
    if B[12]==1:v2.append(12)
    for i,b in enumerate(B[1:-1],1):
        if b==1:v1.append(i)
        elif b==2:v2.append(i);v2.append(24-i)

    l=len(v1)
    for i in range(1<<l):
        v3=v2[:]
        for j,v in enumerate(v1):
            if i&(1<<j):
                v3.append(24-v)
            else:
                v3.append(v)
        tmp=24
        for v in v3:
            for vv in v3:
                if v==vv:continue
                tmp = min(tmp,abs(v-vv),24-abs(v-vv))
        ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedInputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        String input = sc.next();
        int sum = 0;
        int n  = input.length();
        for (int i = 0; i < input.length()/2; i++) {
            if(input.charAt(i) != input.charAt(n-i-1)) sum++;
        }
        System.out.println(sum);
    }

    private static int solve(String s, int n) {
        return n;
    }

    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }
}

Measured memory_bytes: 23892
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define endl '\n'
#define MAX 100002
#define pii pair<int, int>
#define pll pair<long long, long long>


typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vec;

int main(){
    fast_cin();
    string s;cin>>s;
    if(s=="ABC")
        cout<<"ARC\n";
    else
        cout<<"ABC\n";
}

Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int a,b;
        scanf("%d %d",&a,&b);
        if(a>b){
                printf("a > b\n");
        }else if(a<b){
                printf("a < b\n");
        }else{
                printf("a == b\n");
        }
        return 0;
}

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

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  cout << max(n - h + 1, 1) * max(n - w + 1, 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N, K;
  cin >> N >> K;
  vi A(N);
  REP(i, N) cin >> A.at(i);
  if (K > 75) K = 75;

  REP(x, K) {
    vi B(N + 1);
    REP(i, N) {
      int l = max(0, i - A.at(i));
      int r = min(N - 1, i + A.at(i));
      B.at(l)++;
      B.at(r + 1)--;
    }
    A[0] = B[0];
    for (int j = 1; j < N; j++) {
      A[j] = A[j - 1] + B[j];
    }
  }

  REP(k, N) cout << A.at(k) << " ";
  cout << "\n";
  return 0;
}

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

using namespace std;

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

int n,T;
int r2;
long long ans=0;
string ss;

bool dfs(int index) {
    if(index == ss.size()) return true;
    int r = 0;
    if(ss[index] == 'n') {
        r = ss[index+2]-'0';
        if((n!=1&&r>9) || r2*r > 9) return false;
        
        ans += pow(n,r);
        if(ans > 1000000000) return false;
    }

    return dfs(index+1);
}

int main() {
    cin>>n>>T;
    cin>>ss;
    r2 = log10(n);

    if(dfs(0)) {
        if(log10(T) > 10.0 || log10(T) + log10(ans) > 10.0) cout<<"TLE"<<endl;
        else {
            if(ans*T>1000000000) cout<<"TLE"<<endl;
            else cout<<ans*T<<endl;
        }
    }
    else {
        cout<<"TLE"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x){
	return x*x;
}

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

ll manhattan(ll x1, ll y1, ll x2, ll y2){
	return ((ll)(abs(x1-x2)+abs(y1-y2)));
}

ll digit(ll x){
	ll ans = 0ll;
	if(!x){
		return 0ll;
	}
	while(x>0){
		ans++;
		x /= 10;
	}
	return ans;
}

ll f(ll a, ll b){
	return max(digit(a),digit(b));
}

int main(void){
	int n,i;
	string o,e;
	cin >> o;
	cin >> e;
	n = e.l_ength();
	for(i=0; i<n; i++){
		cout << o[i] << e[i];
	}
	if(o.l_ength() > n){
		cout << o[n];
	}
	cout << endl;
	return 0;
}

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

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

    // yy = 00 - 99
    // mm = 01 - 12

    // yymm
    int i1;
    int i2;

    int tmp1;
    int tmp2;

    tmp1 = S[0] - '0';
    tmp2 = S[1] - '0';
    i1 = tmp1*10 + tmp2;

    tmp1 = S[2] - '0';
    tmp2 = S[3] - '0';
    i2 = tmp1*10 + tmp2;

    if(i1>0 && i1 <=12) {
        if(i2>0 && i2 <=12) {
            cout << "AMBIGUOUS";
            return 0;
        }   
    }
    if(i1>=0 && i1 <=99) {
        if(i2>0 && i2 <=12) {
            cout << "YYMM";
            return 0;
        }
    }
    if(i2>=0 && i2 <=99) {
        if(i1>0 && i1 <=12) {
            cout << "MMYY";
            return 0;
        }
    }
    cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x, a, b;
  scanf("%d %d %d", &x, &a, &b);
  a -= x;
  b -= x;
  if(a < 0) a = -a;
  if(b < 0) b = -b;
  if(a > b) printf("B\n");
  else printf("A\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
ll a[200010];
map<ll,int> mp;
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%lld", a+i), a[i] += a[i-1];
	mp[0] = 1;
	ll cnt = 0;
	for(int i=1; i<=n; i++) {
		cnt += mp[a[i]];
		mp[a[i]]++;
	}
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;cin>>N;
vector<int>v(N); for(int i=0;i<N;++i){
cin>>v[i]; }
sort(v.begin(),v.end());
int answer=v[v.size()/2]-v[v.size()/2-1];
cout<<answer<<endl;
return 0;
   }

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

int main() {
	int N, K, Q, A;
	cin >> N >> K >> Q;
	vector<int> vec(N);
	int score = Q - K + 1;
	for (int i = 0; i < Q; i++) {
		cin >> A;
		vec.at(A - 1)++;
	}
	for (int j = 0; j < N; j++) {
		if (vec.at(j) >= score) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 3804
import functools
N,X = map(int,(input().split()))
x =  list(map(lambda a:abs(int(a)-X),(input().split())))
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)
print(gcd(x))

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

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

int binExp(int x,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

// int modInv(int i) {return binExp(i,mod-2);}
// int ncr(int n,int r) {return (fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod;}

int freq[600001];
int segtree[2400001];

// void build(int node, int cl, int cr)
// {
// 	if(cl == cr)
// 	{
// 		segtree[node] = freq[cl];
// 	}
// }

void update(int node, int cl, int cr, int idx, int val)
{
	if(cl == cr)
	{
		freq[idx] = val;
		segtree[node] = val;
		// cout<<"Update --- "<<"idx = "<<idx<<" node = "<<node<<'\n';
	}
	else
	{
		int m = (cl+cr)/2;
		if(cl <= idx && idx <= m)
		{
			update(2*node, cl, m, idx, val);
		}
		else
		{
			update(2*node+1, m+1, cr, idx, val);
		}

		segtree[node] = max(segtree[2*node], segtree[2*node+1]);
	}
}

int query(int node, int cl, int cr, int l, int r)
{
	if(r < cl || cr < l)
	{
		return 0;
	}
	
	if(l <= cl && cr <= r)
	{
		return segtree[node];
	}

	int m = (cl+cr)/2;
	int one = query(2*node, cl, m, l, r);
	int two = query(2*node+1, m+1, cr, l, r);
	return max(one,two);
}

signed main()
{
    fast

    #ifndef ONLINE_JUDGE
        freopen("inputf.in","r",stdin);
        freopen("outputf.in","w",stdout);
    #endif

    int n,k;
    cin>>n>>k;
    f1(i,0,600000) freq[i] = 0;
    f1(i,0,2400000) segtree[i] = 0;

    int x;

    int ans = 0;
    f0(i,0,n)
    {
    	cin>>x;

    	int z = query(1,0,300000,x-k, x+k);
    	// cout<<x<<' '<<z<<'\n';
    	update(1,0,300000,x,z+1);
    	ans = max(ans, z+1);
    }
    cout<<ans;
}

Measured memory_bytes: 27092
#include<stdio.h>

int main(void){

	double max,min,h;

	scanf("%lf",&h);
	max = h;
	min = h;

	while(scanf("%lf",&h)!=EOF){

		if(max < h)
			max = h;
		else if(min > h)
			min = h;

	}

	printf("%lf\n",max-min);

	return 0;
}

Measured memory_bytes: 648
A,B=map(int,input().split())
n=str(input())
numbers=['1','2','3','4','5','6','7','8','9','0']
if n[A]!='-':
    print('No')
    exit()
for i in range(A):
    if not(n[i] in numbers):
        print('No')
        exit()
for j in range(B):
    if not(n[j+A+1] in numbers):
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 9116
#include "bits/stdc++.h"
#define int long long
using namespace std;

bool dp[100100];
int32_t main() {
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (a[j] <= i && !dp[i - a[j]]) {
                dp[i] = true;
            }
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int cnt[30],s[10000];
bool b[10000];
int n,m,tot;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	  {
	  	char c=getchar();
	  	while(c<'a'||c>'z') c=getchar();
	  	cnt[c-'a'+1]++;
	  }
	for(int i=1;i<=n>>1;i++)
	  for(int j=1;j<=m>>1;j++)
	    s[++tot]=4;
	if(n&1) for(int i=1;i<=m>>1;i++)
	  s[++tot]=2;
	if(m&1) for(int i=1;i<=n>>1;i++)
	  s[++tot]=2;
	if(n&1&&m&1) s[++tot]=1;
	int odd=0,pos;
	for(int i=1;i<=26;i++)
	  if(cnt[i]&1) odd++,pos=i;
	if(odd>1) return puts("No"),0;
	if(odd==1&&(!(n&1&&m&1))) puts("No"),0;
	if(odd==1) cnt[pos]--,tot--;
	for(int i=1;i<=26;i++)
		if(cnt[i]>=4)
		{
			for(int j=1;j<=tot;j++)
				if(s[j]==4&&!b[j])
				{
					cnt[i]-=4;
					b[j]=1;
					if(cnt[i]<4) break;
				}
		}
	for(int i=1;i<=26;i++)
		if(cnt[i]>=2)
		{
			for(int j=1;j<=tot;j++)
				if(s[j]==2&&!b[j])
				{
					cnt[i]-=2;
					b[j]=1;
					if(cnt[i]<2) break;
				}
		}
	for(int i=1;i<=tot;i++)
	  if(!b[i]) return puts("No"),0;
	puts("Yes");
	return 0;
}

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

using namespace std;

int main()
{
    int n, k, h, ans = 0;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &h);
        if(h >= k)
            ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


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

int x, a, b;
int main()
{
    cin >> a >> b >> x;
    if (x > a + b)
    {
        cout << "NO" << endl;
    }
    else
    {
        if (x < a)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
        }
        
    }
    
}

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

public class Main {

    public static void main(String[] args) throws IOException, NumberFormatException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().trim().split("\\s+");
        int n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);
        int[] arr = new int[n];
        s = br.readLine().trim().split("\\s+");
        for(int i=0 ; i<n ; i++)
            arr[i] = Integer.parseInt(s[i]);

        int[] dp = new int[n];
        dp[0] = 0;
        for(int i=1 ; i<n ; i++)
        {
            int min = Integer.MAX_VALUE;
            for(int j=1 ; j<=k && (i-j)>= 0; j++)
            {
                int temp = dp[i-j] + Math.abs(arr[i] - arr[i-j]);
                min = Math.min(temp, min);
            }

            dp[i] = min;
        }

        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 34896
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [0] * D
for i in range(D):
    t[i] = int(input())
M = int(input())   
day = [0] * M
q = [0] * M
for i in range(M):
    day[i], q[i] = map(int, input().split())
    
    
m=[0]*D

a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
mmm=m[D-1]
#print(mmm)
#for i in a:
 #   print(i)
for p in range(M):
    new_type=q[p]
    old_type=t[day[p]-1]
    A=0
    B=0
    C=s[day[p]-1][old_type-1]-s[day[p]-1][new_type-1]
    for d in range(D):
        A+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    xday=day[p]
    if xday>1:
        before_new=a[xday-2][new_type-1]
        before_old=a[xday-2][old_type-1]
        now_new=a[day[p]-1][new_type-1]
        now_old=a[day[p]-1][old_type-1]
        for d in range(day[p]-1,D):
            if a[d][new_type-1]==now_new:
                a[d][new_type-1]=xday
            if a[d][old_type-1]==now_old:
                a[d][old_type-1]=before_old
    else:
        for d in range(day[p]-1,D):
            if a[d][old_type-1]==1:
                a[d][old_type-1]=0
            if a[d][new_type-1]==0:
                a[d][new_type-1]=1
 
        #a[d][new_type-1]+=1
        #a[d][old_type-1]-=1
    
    t[day[p]-1]=new_type
    for d in range(D):
        B+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    #for i in a:
     #   print(i,A,B,C)
    mmm=mmm-(B-A+C)
    print(mmm)

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

public class Main {

	public static void main(String[] args) {
		int field[][] = setField();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		while (true) {
			try {
				input = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (input == null || input.isEmpty()) {
				break;
			}
			String[] inputs = input.split(",");
			drop(field, Integer.parseInt(inputs[0]),
					Integer.parseInt(inputs[1]),
					Integer.parseInt(inputs[2]));
		}
		amountOfWhite(field);
		maxDepth(field);

	}

	private static int[][] setField() {
		int field[][] = new int[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				field[i][j] = 0;
			}
		}
		return field;
	}

	private static void drop(int[][] field, int x, int y, int size) {
		switch (size) {
		case 1:
			dropSmall(field, x, y);
			break;

		case 2:
			dropMiddle(field, x, y);
			break;
		case 3:
			dropLarge(field, x, y);
			break;
		}

	}

	private static void dropLarge(int[][] field, int x, int y) {

		dropMiddle(field, x, y);

		int dropX[] = { -2, 0, 2, 0 };
		int dropY[] = { 0, -2, 0, 2 };

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static void dropMiddle(int[][] field, int x, int y) {

		dropSmall(field, x, y);

		int dropX[] = { -1, -1, 1, 1 };
		int dropY[] = { 1, -1, 1, -1 };

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static void dropSmall(int[][] field, int x, int y) {
		int dropX[] = { -1, 0, 1, 0 };
		int dropY[] = { 0, -1, 0, 1 };
		dropping(field, x, y);

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static int[][] dropping(int[][] field, int x, int y) {
		if (0 <= x && x < 10 && 0 <= y && y < 10) {
			field[x][y] += 1;
		}
		return field;
	}

	private static void amountOfWhite(int[][] field) {
		int count = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (field[i][j] == 0) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static void maxDepth(int[][] field) {
		int maxDepth = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (maxDepth < field[i][j]) {
					maxDepth = field[i][j];
				}
			}
		}
		System.out.println(maxDepth);
	}
}

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

int main() {
  int R, C, k;
  cin >> R >> C >> k;
  vector<int> r(k,0), c(k,0), v(k,0);
  rep(i,k) cin >> r[i] >> c[i] >> v[i];
  vector<vector<int>> arr(R,vector<int>(C));
  rep(i,k) arr[r[i]-1][c[i]-1] = v[i];
  vector<vector<vector<ll>>> dp(R+1,vector<vector<ll>>(C+1,vector<ll>(4,0)));

  rep(i,R) rep(j,C) {
    for (int k = 2; k >= 0; k--) {
      dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + arr[i][j]);
    }
    rep(k, 4) {
      dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
      dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
    }
  }
  ll ans = 0;
  rep(k,4) ans = max(ans,dp[R-1][C-1][k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 674156
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		StringBuilder ans =new StringBuilder(S);
		if(S.charAt(K-1)=='A'){		
			ans.setCharAt((K-1), 'a');
		}
		if(S.charAt(K-1)=='B'){		
			ans.setCharAt((K-1), 'b');
		}
		if(S.charAt(K-1)=='C'){		
			ans.setCharAt((K-1), 'c');
		}

		System.out.println(ans);	
		}
	}


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

int main(void){
    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    for(int i = 0; i < n/2; i++){
        if (s[i]!=s[n-1-i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define 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 long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    vector<int> A(N), B(N), C(N - 1);
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }

    REP(i, N) cin >> B[i];
    REP(i, N - 1) cin >> C[i];

    ll ans = 0;
    REP(i, N){
        ans += B[A[i]];
        if(i < N - 1 && A[i] + 1 == A[i + 1]) ans += C[A[i]];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


vector<vector<ll>> g1(100001, vector<ll>());
vector<vector<ll>> g2(100001, vector<ll>());
vector<ll> ans(100001, 0);

void dfs(ll u,ll v) {
	ll k = ans[v];
	for (auto a : g1[v]) {
		if (a == u) continue;
		ans[a] = k;
		dfs(v, a);
	}
	k = k ^ 1;
	for (auto a : g2[v]) {
		if (a == u) continue;
		ans[a] = k;
		dfs(v, a);
	}
}


int main() {
	ll n; cin >> n;
	rep(i, n - 1) {
		ll u, v, w; cin >> u >> v >> w;
		if (w % 2 == 0) {
			g1[u].emplace_back(v);
			g1[v].emplace_back(u);
		}
		else {
			g2[u].emplace_back(v);
			g2[v].emplace_back(u);
		}
	}
	dfs(0,1);
	ll q = 1;
	rep(i, n) {
		cout << ans[i+1] << endl;
	}
}

Measured memory_bytes: 13312
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main ()
{
	double a, b, h, m;
	double ax, ay, bx, by;
	double ar, br;
	double pi = 3.141592653589793238;
	double dis;

	cin >> a >> b >> h >> m;

	ar = (((h * 30) + (m * 0.5)) / 180) * pi;
	br = ((m * 6) / 180) * pi;

//	cout << ar << " " << br << endl;

	ax = a * cos(ar);
	ay = a * sin(ar);
	bx = b * cos(br);
	by = b * sin(br);

//	cout << ax << "," << ay << "," << bx << "," << by << endl;

	dis = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));

	cout << std::fixed << std::setprecision(15) << dis << endl;

	return 0;
}


Measured memory_bytes: 4096
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][10^^5] PS;
int[10^^5] MEMO;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        PS[xy[0]-1] ~= xy[1]-1;
    }

    MEMO[0..N] = -1;

    int solve(int from) {
        if (MEMO[from] != -1) return MEMO[from];
        if (PS[from].empty) return MEMO[from] = 0;

        int max_p;
        foreach (to; PS[from]) {
            max_p = max(max_p, solve(to));
        }
        return MEMO[from] = max_p + 1;
    }

    foreach (i; 0..N) solve(i);

    int ret;
    foreach (mp; MEMO[0..N]) ret = max(ret, mp);
    writeln(ret);
}

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

using namespace std;

const int max_n = 100111, max_lev = 17, inf = 1000111222;

struct query {
    int id, c, z;

    query() {
    }

    query(int id, int c, int z): id(id), c(c), z(z) {
    }
};

int n, q, p[max_lev][max_n], tin[max_n], tout[max_n], curt, len[max_n];
vector<int> g[max_n], d[max_n], col[max_n];
vector<query> all[max_n];
int cur_cnt[max_n], cur_len[max_n];
int ans[max_n], cnt[max_n];
int u[max_n], v[max_n], qc[max_n], qlen[max_n];

void dfs(int v) {
    tin[v] = ++curt;
    for (int i = 0; i < g[v].size(); ++i) {
        const int to = g[v][i];
        if (to == p[0][v]) {
            continue;
        }
        p[0][to] = v;
        len[to] = len[v] + d[v][i];
        dfs(to);
    }
    tout[v] = curt;
}

bool is_ancestor(int u, int v) {
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int lca(int u, int v) {
    if (is_ancestor(u, v)) {
        return u;
    }
    for (int lev = max_lev - 1; lev >= 0; --lev) {
        if (!is_ancestor(p[lev][u], v)) {
            u = p[lev][u];
        }
    }
    return p[0][u];
}

void get_all_p() {
    for (int lev = 1; lev < max_lev; ++lev) {
        for (int i = 0; i < n; ++i) {
            p[lev][i] = p[lev - 1][p[lev - 1][i]];
        }
    }
}

void dfs2(int v) {
    for (const query &q : all[v]) {
        cnt[q.id] += q.z * cur_cnt[q.c];
        ans[q.id] -= q.z * cur_len[q.c];
    }
    for (int i = 0; i < g[v].size(); ++i) {
        const int to = g[v][i];
        if (to == p[0][v]) {
            continue;
        }
        ++cur_cnt[col[v][i]];
        cur_len[col[v][i]] += d[v][i];
        dfs2(to);
        --cur_cnt[col[v][i]];
        cur_len[col[v][i]] -= d[v][i];
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &q);
    for (int i = 1; i < n; ++i) {
        int u, v, c, len;
        scanf("%d%d%d%d", &u, &v, &c, &len);
        --u;
        --v;
        g[u].push_back(v);
        d[u].push_back(len);
        col[u].push_back(c);
        g[v].push_back(u);
        d[v].push_back(len);
        col[v].push_back(c);
    }
    dfs(0);
    get_all_p();
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%d%d", &qc[i], &qlen[i], &u[i], &v[i]);
        --u[i];
        --v[i];
        int lc = lca(u[i], v[i]);
        ans[i] = len[u[i]] + len[v[i]] - 2 * len[lc];
        all[u[i]].push_back({i, qc[i], 1});
        all[v[i]].push_back({i, qc[i], 1});
        all[lc].push_back({i, qc[i], -2});
    }
    dfs2(0);
    for (int i = 0; i < q; ++i) {
        ans[i] += cnt[i] * qlen[i];
        printf("%d\n", ans[i]);
    }
    return 0;
}


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

int parent(int i){return i/2;}

int left(int i){return 2*i;}

int right(int i){return 2*i+1;}
int main(){
  int H;
  cin >> H;
  int A[H+1];
  for(int i = 1;i<H+1;i++){
    cin >> A[i];
  }
  for(int i = 1;i<H+1;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i)!=0)cout << "parent key = "<<A[parent(i)] << ", ";
    if(left(i) <= H)cout << "left key = " << A[left(i)]<< ", ";
    if(right(i)<=H)cout << "right key = "<<A[right(i)]<<", ";
    cout << endl;
  }



}



Measured memory_bytes: 3064
n,m=map(int,input().split())
h=list(map(int,input().split()))
AB=[list(map(int,input().split())) for _ in range(m)]
c=[0]*n
for i , j in AB:
    if h[i-1]<=h[j-1]:
        c[i-1]=-10**10
    if h[j-1]<=h[i-1]:
        c[j-1]=-10**10
cnt=0
for i in c:
    if i == 0:
        cnt+=1
print(cnt)


Measured memory_bytes: 93488
import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {1: 0}
pre = 1
for i in range(1, N+1):
    new = A[pre-1]
    if d.get(new):
        roop_start = d[new]
        roop_end = i
        roop_pos = new
        break
    if i==K:
        print(new)
        sys.exit()
    d[new] = i
    pre = new

K -= roop_start
K %= roop_end-roop_start
pre = roop_pos
for i in range(K):
    pre = A[pre-1]
print(pre)



Measured memory_bytes: 106152
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

const ll INF = 200000000;
int main() {
  int n,m,r; in(n),in(m),in(r);
  vector<int> R(r);
  loop(i,0,r) in(R[i]),R[i]--;
  ll G[n][n];
  loop(i,0,n) loop(j,0,n) {
    if (i==j) G[i][j] = 0;
    else G[i][j] = INF;
  }
  loop(i,0,m) {
    int u, v; ll d; in(u),in(v),in(d);
    u--;v--;
    G[u][v] = G[v][u] = d;
  }
  
  loop(k,0,n)
    loop(i,0,n)
      loop(j,0,n)
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
  
  sort(R.begin(), R.end());
  ll ans = INF;
  do {
    ll sum = 0;
    loop(i,0,r-1) {
      int a = R[i];
      int b = R[i+1];
      sum += G[a][b];
    }
    ans = min(ans, sum);
  } while (next_permutation(R.begin(), R.end()));
  print(ans);
  return 0;
}


Measured memory_bytes: 3940
#include<cstdio>
#include<cstring>
#include<cstdlib>
int xxx(int y, int z){
	int w;
	if (y < z){
		if (z%y == 0)return y;
		else {
			w = z / y;
			return xxx(y, z - (w*y));
		}
	}
	else if (z < y){
		if (y%z == 0)return z;
		else {
			w = y / z;
			return xxx(z, y - (w*z));
		}
	}
	else return y;
}
int main(void){
	int a,b,c,d;
	int x;
	int p, q;
	long long s;
	scanf("%d%d %d %d", &a,&b,&c,&d);
	p = c - a;
	q = d - b;
	if (p != 0 && q != 0){
		if (p < 0)p = -p;
		if (q < 0)q = -q;
		x = xxx(p, q);
		p = p / x;
		q = q / x;
		s = (p + q - 1)*x;
		printf("%lld\n", s);
	}
	else printf("0\n");


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
 
vector<vector<int> > G(101010);
int P[101010],L[101010],R[101010];
const int INF=1e7;
 
void bad(){
  cout<<"No\n";
  exit(0);
}
 
void dfs(int v,int p,int d){
  if(P[v]!=INF){
    if(P[v]%2!=d%2) bad();
  }
  for(auto u:G[v]) if(u!=p) dfs(u,v,d+1);
  return;
}
 
void dfs2(int v, int p){
  if(P[v]==INF) L[v]=-INF,R[v]=INF;
  else L[v]=R[v]=P[v];
  for(auto u:G[v]) if(u!=p){
    dfs2(u, v);
    if(P[v]==INF){
      L[v]=max(L[v],L[u]-1);
      R[v]=min(R[v],R[u]+1);
    }
  }
}
 
void dfs3(int v, int p){
  if(p!=-1){
    int ne[2]={P[p]+1,P[p]-1};
    bool flag=1;
    rep(i,2){
      if(L[v]<=ne[i]&&ne[i]<=R[v]){
        P[v]=ne[i];
        flag=0;
      }
    }
    if(flag) bad();
  }
  if(p!=-1){
    if(abs(P[p]-P[v])>1) bad();
  }
  for(auto u:G[v]) if(u!=p) dfs3(u,v);
}
 
int main(){
  int N; cin>>N;
  rep(i,N-1){
    int a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,N) P[i]=INF;
  int K; cin>>K;
  int r=-1;
  rep(i,K){
    int v,p; cin>>v>>p; v--;
    P[v]=p;
    r=v;
  }
  dfs(r,-1,P[r]);
  dfs2(r,-1);
  dfs3(r,-1);
  cout<<"Yes\n";
  rep(i,N) cout<<P[i]<<endl;
  return 0;
}

Measured memory_bytes: 13824
import java.util.Scanner;
import java.math.*;
import java.math.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		//s.charAt(i); for String
		// 出力
		//System.out.println("");
		//int count=0;
		int N=sc.nextInt();
		int K=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		int count=0;
		if(N==K){
			System.out.println("1");
		}else{
			N=N-K;
			count++;
			while(N>0){
				N=N-(K-1);
				count++;
			}
		System.out.println(count);
		}
		
		// 7549236815
	}
}

Measured memory_bytes: 50440
fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val x = readLine()!!.toInt()

    var ans = 0
    for (i in 0..a) {
        for (j in 0..b) {
            for (k in 0..c) {
                if (500 * i + 100 * j + 50 * k == x) ans++
            }
        }
    }
    println(ans)
}


Measured memory_bytes: 31708
# Problem https://atcoder.jp/contests/abc081/tasks/abc081_b
# Python 1st Try
import sys


def solve(allNumber,eachNum):
    answer = 0
    counter = [0]*allNumber
    for j in range(len(eachNum)):
        cnt = 0
        while eachNum[j] % 2 == 0:
            counter[j] = counter[j] + 1
            eachNum[j] = eachNum[j] / 2
#    print(counter)


#   TODO: ここに最大値を設定してcounter配列を回す
#   NOTE: 最小値はどこか→Python3で整数型の最大値はsys.maxsizeとして定義

    answer = sys.maxsize
    for j in range(0, allNumber):
        if counter[j] <= answer:
            answer = counter[j]
    return answer

if __name__ == "__main__":
    input=sys.stdin.readline
    N = list(map(int, input().split()))
    Ai = list(map(int, input().split()))
    print(solve(N[0], Ai))



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

constexpr int INF = std::numeric_limits<int>::max();

class DisjointSet {
public:
    vector<int> rank, p;
    int size = 0;
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

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

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }

    int calcSize() {
        int size = 0;
        for (int i = 0; i < p.size(); i++) {
            if (i == p[i]) {
                size++;
            }
        }
        return size;
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    DisjointSet s(N);

    while (M--) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x > y) {
            swap(x, y);
        }
        x--;
        y--;

        s.unite(x, y);
    }

    int ans = s.calcSize();
    cout << ans << endl;
}

Measured memory_bytes: 1024