akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans=INF;
    rp(i,2*max(x,y)+1){
        ll price=c*i;
        price+=a*max(0ll,(x-i/2));
        price+=b*max(0ll,(y-i/2));
        chmin(ans,price);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

using namespace std;

class UnionFind{
    public:
        UnionFind(){
            UnionFind();
        }

        UnionFind(int N){
            par.resize(N);
            rnk.resize(N);
            for(int i=0;i<N;i++){
                par[i] = i;
                rnk[i] = 0;
            }
        }

        int root(int x){
            return par[x] = (par[x] == x ? x : root(par[x]));
        }

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

        void unite(int x, int y){
            x = root(x);
            y = root(y);

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

    private:
        vector<int> par, rnk;
};

class edge{
    public:
        int to, from, cost;
        edge(){};
        edge(int t, int f, int c):
        to(t), from(f), cost(c){};
        bool operator < (const edge &e) const{
            return cost < e.cost;
        }
};

class node{
    public:
        int x, y, id;
        node(){};
        node(int x, int y, int i):
        x(x), y(y), id(i){};
};

bool compX(const node &a, const node &b) {return a.x < b.x;}
bool compY(const node &a, const node &b) {return a.y < b.y;}

long long kruskal(int N, vector<edge> &es){
    long long totalCost = 0ll;
    sort(es.begin(), es.end());

    UnionFind uf = UnionFind(N);
    for(int i=0;i<es.size();i++){
        edge e = es[i];
        if(!uf.same(e.from, e.to)){
            totalCost += e.cost;
            uf.unite(e.from, e.to);
        }
    }
    return totalCost;
}

int main(){
    int N; cin >> N;
    vector<node> ns(N);
    int x,y;
    for(int i=0;i<N;i++){
        cin >> x >> y;
        ns[i] = node(x,y,i);
    }

    vector<edge> es;
    // sort X
    sort(ns.begin(), ns.end(), compX);
    for(int i=0;i<N-1;i++){
        edge e = edge(ns[i].id, ns[i+1].id, abs(ns[i].x - ns[i+1].x));
        es.push_back(e);
    }
    // sort Y
    sort(ns.begin(), ns.end(), compY);
    for(int i=0;i<N-1;i++){
        edge e = edge(ns[i].id, ns[i+1].id, abs(ns[i].y - ns[i+1].y));
        es.push_back(e);
    }

    cout << kruskal(N, es) << endl;
    return 0;
}

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

void solver() {
  long long n;
  cin >> n;

  vector<vector<long long> > m(10, vector<long long>(10));

  long long div = 1;
  for (long long i = 0; i <= n; i++) {
    if (i / div >= 10 and i != 0) {
      div *= 10;
    }

    long long minDigit = i % 10;
    long long maxDigit = i / div;

    m[minDigit][maxDigit]++;
  }

  long long ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += m[i][j] * m[j][i];
    }
  }

  cout << ans << "\n";
}

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


Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/01/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,K; cin>>N>>K;
  set<int> D;
  for (int i = 0; i < K; i++) {
    int d; cin>>d;
    D.insert(d);
  }
  int ans = N;
  while (true) {
    bool end = true;
    int c = ans;
    while (c) {
      auto b = c%10;
      if (D.count(b)) {
        end = false;
        break;
      }
      c /= 10;
    }
    if (end) {
      break;
    }
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    vector<vector<int>> t(h+1,vector<int>(w+1));
    rep(i,h) {
        cin >> s[i];
        rep(j,w) t[i+1][j+1]=s[i][j]-'0';
    }
    repr(i,1,h+1) {
        repr(j,1,w+1) t[i][j]+=t[i-1][j]+t[i][j-1]-t[i-1][j-1];
    }
    int ans=(h-1)*(w-1);
    rep(bit,(1<<(h-1))) {
        int tans=0;
        int l=0;
        vector<vector<int>> tt;
        vector<int> u(w+1);
        rep(i,h-1) {
            if (bit & (1<<i)) {
                ++tans;
                repr(j,1,w+1) u[j]=t[i+1][j]-t[l][j];
                l=i+1;
                tt.push_back(u);
            }
        }
        repr(j,1,w+1) u[j]=t[h][j]-t[l][j];
        tt.push_back(u);
        l=0;
        bool isans=1;
        repr(j,1,w+1) {
            bool isover=0;
            rep(i,tt.size()) {
                if (tt[i][j]-tt[i][l]>k) isover=1;
            }
            if (isover) {
                if (l==j-1) isans=0;
                else {
                    l=j-1;
                    ++tans;
                }
            }
        }
        if (isans) ans=min(tans,ans);
    }
    cout << ans << endl;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n, p;
  while (true) {
    cin >> n >> p;
    if (n == 0 && p == 0) break;
    vector<int> v(n, 0);
    int i = 0, pp = p;
    while (true) {
      if (pp != 0) {
        pp--;
        v[i]++;
        if (v[i] == p) {
          cout << i << "\n";
          break;
        }
      } else {
        if (v[i] != 0) {
          pp = v[i];
          v[i] = 0;
        }
      }

      i = (i + 1) % n;
    }
  }

  return 0;
}


Measured memory_bytes: 3084
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

ll A[N];
ll nCk[N];

ll power(ll a,ll n,ll m=M){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*a;
        a=a*a;
        n=n>>1;
        ans=ans%m;
        a=a%m;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	rep(i,0,n)	cin>>A[i];
	sort(A,A+n);
	if(k==1){
		cout<<0<<endl;
		return 0;
	}
	nCk[k-1] = 1;
	rep(i,k,n){
		nCk[i] = ((nCk[i-1] * (i))%M * power(i-k+1, M-2))%M; 
	}
	ll mi=0, ma=0;
	rep(i,0,n){
		ma = ((ma + A[i]*nCk[i])%M+M)%M;
		mi = ((mi + A[i]*nCk[n-1-i])%M+M)%M;
	}
	ll ans = ((ma-mi)%M+M)%M;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 
int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  printf("%lld",a+b/2);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        final long a = 26;
        System.out.println(convertTenRadixTo(a, n));
    }

    public static String convertTenRadixTo(long radix, long value) {

        List<Long> list = new ArrayList<>();
        if (radix == 0 || value == 0) {
            return "0";
        }

        while (value > 0) {
            if (value % radix == 0) {
                list.add(radix);
                value = (value / radix) -1;
            } else {
                list.add(value % radix);
                value = (value / radix);
            }
        }
        StringBuilder builder = new StringBuilder();

        for (long number : list) {
            builder.append(RADIX_MAP.get(String.valueOf(number)));
        }

        return builder.reverse().toString();
    }

    /**
     * 手抜きのMap
     */
    private static final Map<String, String> RADIX_MAP = new HashMap<String, String>() {
        {
            // put("", "a");
            put("1", "a");
            put("2", "b");
            put("3", "c");
            put("4", "d");
            put("5", "e");
            put("6", "f");
            put("7", "g");
            put("8", "h");
            put("9", "i");
            put("10", "j");
            put("11", "k");
            put("12", "l");
            put("13", "m");
            put("14", "n");
            put("15", "o");
            put("16", "p");
            put("17", "q");
            put("18", "r");
            put("19", "s");
            put("20", "t");
            put("21", "u");
            put("22", "v");
            put("23", "w");
            put("24", "x");
            put("25", "y");
            put("26", "z");
        }
    };
}

Measured memory_bytes: 27044
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
 
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int H = cin.nextInt();
        int A = cin.nextInt();
      	int l = 0;
      while(H>0){
        	l++;
        	H -=A;
        }
      Console.WriteLine(l);
    }
}
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
	  for(;;) {
		  int a=sc.nextInt();
		  String op=sc.next();
		  int b=sc.nextInt();
		  if(op.equals("+")) {
			 System.out.println(a+b);
		  }
		  else if(op.equals("-")) {
			  System.out.println(a-b);
		  }
		  else if(op.equals("*")) {
			  System.out.println(a*b);
		  }
		  else if(op.equals("/")) {
			  System.out.println(a/b);
		  }
		  else break;

	  } sc.close();
  }


}


Measured memory_bytes: 26408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  long long m = 1;
  int f = 0;
  int f2 = 0;
  vector<long long> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    if(vec.at(i)==0){
        f = 1;
        break;
    }
    if(vec.at(i)>1000000000){
        f2 = f2 + 1;
    }
  }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
  if(f==0){
    for (int i = 0; i < n; i++) {
      m = m*vec.at(i);
      if(m>1000000000000000000){
          f = 2;
          break;
      }
    }
  }
  if(f==0&&f2 <=1){
  cout << m << endl;
  }else if(f==1){
  cout << 0 << endl;
  }else if(f==2 || f2>=2){
  cout << -1 << endl;
  }
} 

Measured memory_bytes: 4032
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
div = 0

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

print(div)

Measured memory_bytes: 21640
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let len = s.chars().count();

    let ans = solve(&s, 0, len as u32, 0);

    println!("{}", ans);
}

fn solve(s: &str, index: u32, len: u32, bit: u32) -> u64 {
    if index == len - 1 {
        let t = calc(s, bit);
        //println!("{}", t);
        return t;

    }
    let bit1 = bit + 2u32.pow(index);
    let bit2 = bit;
    return solve(s, index+1, len, bit1) + solve(s,index+1, len, bit2);
}

fn calc(s: &str, bit: u32) -> u64{
    let mut buf = String::new();
    let mut sum: u64 = 0;
    for (i, ch) in s.chars().enumerate() {
        buf.push(ch);
        if bit & 2u32.pow(i as u32) != 0 {
            sum = sum + buf.parse::<u64>().unwrap();
            //println!("buf {} sum {}", buf, sum);
            buf.clear();
        }
    }
    if !buf.is_empty() {
        sum = sum + buf.parse::<u64>().unwrap();
    }
    sum
}

#[test]
fn calc_test() {
    assert_eq!(calc("123456", 63), 21);
    assert_eq!(calc("123456", 62), 30);
    assert_eq!(calc("125", 0), 125);
}

#[test]
fn solve_test() {
    assert_eq!(solve("125", 0, 3, 0), 176);
    assert_eq!(solve("9999999999", 0, 10, 0), 12656242944);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long
int L;
typedef std::pair<int,int> pii;
std::vector<pii> e[25];
int main(){
	std::cin>>L;
	int lg=0,tmp=L;
	while(tmp) tmp>>=1,++lg;
	int cnt=0;
	rep(i,1,lg-1){
		e[i].emplace_back(i+1,0);
		e[i].emplace_back(i+1,1<<lg-i-1);
		cnt+=2;
	}
	tmp=1<<lg-1;
	_rep(i,lg-1,1){
		if(L>>(i-1)&1){
			e[1].emplace_back(lg-i+1,tmp);
			tmp+=1<<i-1,++cnt;
		}
	}
	std::cout<<lg<<' '<<cnt<<'\n';
	rep(i,1,lg){
		for(pii it:e[i])
			std::cout<<i<<' '<<it.first<<' '<<it.second<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define REP(i,n) for(i=0;i<n;i++)
#define ll long long

int main(void){
    int a,b,c,x;
    int i,j,k;
    int ctr=0;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&x);
    
    REP(i,a+1){
        REP(j,b+1){
            REP(k,c+1){
                if(500*i+100*j+50*k==x){
                    ctr++;
                }
            }
        }
    }

    printf("%d",ctr);
    return 0;
}

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

typedef long long ll;

const int N = 1e5+1;

int main(){
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k%2){
		a *= -1;
		b *= -1;
	}
	cout << a-b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main(void)
{
	priority_queue<int> queue;
	string command;
	int num;

	while(true)
	{
		cin >> command;
		if(command=="end")
		{
			break;
		}

		if(command=="extract")
		{
			cout << queue.top() << endl;
			queue.pop();
		}
		else
		{
			cin >> num;
			queue.push(num);
		}
	}
	return 0;
}

Measured memory_bytes: 6992
using System;

class Program
{
    const int TYPE_NUM = 26;

    static void Main(string[] args)
    {
        int i, j, k;

        int n = int.Parse(Console.ReadLine());

        int satu;
        if (n % 1000 != 0)
        {
            satu = (n / 1000) + 1;
        }
        else
        {
            satu = n / 1000;
        }
        
        int result = (satu * 1000) - n;

        Console.WriteLine(result);

        return;
    }
}

Measured memory_bytes: 27536
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  long X, Y, a, i;
  scanf("%ld%ld", &X, &Y);
  a=Y/X; 
  for(i=1;;i++){
    if(a>>i==0)break;
  }
  printf("%d\n", i);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1<<16;

class RSQ2{
public:
  ll n,dat[2*MAX_N-1],td[2*MAX_N-1];
  RSQ2(){n=MAX_N,memset(dat,0,sizeof(dat)),memset(td,0,sizeof(td));};
  
  ll add(int a,int b,ll x,int k=0,int l=0,int r=-1){
    if(r==-1) r=n;
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b){
      dat[k]+=(r-l)*x; 
      td[k]+=x;
      return dat[k];
    }

    dat[k]+=(min(r,b)-max(l,a))*x;
    ll kl=k*2+1,kr=k*2+2,t=td[k]*(r-l)/2;
    dat[kl]+=t, dat[kr]+=t;
    td[kl]+=td[k], td[kr]+=td[k];
    td[k]=0;
    
    ll vl=add(a,b,x,k*2+1,l,(l+r)/2);
    ll vr=add(a,b,x,k*2+2,(l+r)/2,r);
    return vl+vr;
  }
  
  ll sum(int a,int b){return a>=b? 0:add(a,b,0);}
};


struct data{int l,r;};
struct P{int x,y;};
const int B=30000;

int main(){
  int n;
  while(cin>>n,n){
    vector<vector<data> > LR(MAX_N);
    vector<P> A(n);
    for(int i=0;i<n;i++)cin>>A[i].x>>A[i].y,A[i].x+=B,A[i].y+=B;
    for(int i=1;i<=n;i++)
      if(A[i%n].y==A[i-1].y)
	LR[A[i%n].y].push_back((data){A[i-1].x,A[i%n].x});
    
    map <int,data> C;
    for(int i=0;i<4;i++)cin>>A[i].x>>A[i].y,A[i].x+=B,A[i].y+=B;
    for(int i=1;i<=4;i++)
      if(A[i%4].y==A[i-1].y)C[A[i%4].y]=(data){A[i-1].x,A[i%4].x};
    
    RSQ2 T;
    ll ans=0;
    for(int i=0,cl=0,cr=0;i<MAX_N;i++){
      if(C.count(i)&&!cl&&!cr) cl=C[i].l,cr=C[i].r;
      else if(C.count(i)) cl=cr=0;

      for(int j=0;j<LR[i].size();j++){
	int l = LR[i][j].l,r=LR[i][j].r;
	l<r ? T.add(l,r,1): T.add(r,l,-1);
      }
      ans+=T.sum(0,cl)+T.sum(cr,T.n);
    }
    cout <<ans<<endl;
  }


  return 0;
}

Measured memory_bytes: 6632
import java.util.*;

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

        if(A < 10 && B < 10){
            System.out.println(A * B);
        }
        else System.out.println("-1");

        
    }
}

Measured memory_bytes: 21844
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n;
    cin>>n;
    int ans=0;
    rep(i,1,n){
        int a;
        cin>>a;
        if(i&1 and a&1) ans++;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3648
def roof(x):
    if x == int(x):
        return int(x)
    else:
        return int(x)+1

n = int(input())
l = [0] * 5
for i in range(0,5):
    l[i] = int(input())

m = min(l)

t = roof(n/m)

print(t + 4)


Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, m = mi()
    print('Yes') if m == n else print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;
// const int imax = 100000;

int main(){
	string s;
	cin >> s;
	int y,m,d;
	y = stoi(s.substr(0,4));
	m = stoi(s.substr(5,2));
	d = stoi(s.substr(8,2));
	if(y < 2019){
		printf("Heisei\n");
		return 0;
	}else if (y == 2019){
		if(m < 5){
			printf("Heisei\n");
			return 0;
		}
	}
	printf("TBD\n");
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int A[3][3];
  int H[3][3] = {};
  rep(i, 3) rep(j, 3) {
    int a;
    cin >> a;
    A[i][j] = a;
  }
  int n;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    rep(j, 3) rep(k, 3) {
      if (A[j][k] == b) H[j][k] = 1;
    }
  }
  rep(i, 3) {
    int cnt = 0;
    rep(j, 3) { cnt += H[i][j]; }
    if (cnt == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i, 3) {
    int cnt = 0;
    rep(j, 3) { cnt += H[j][i]; }
    if (cnt == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (H[0][0] + H[1][1] + H[2][2] == 3) {
    cout << "Yes" << endl;
    return 0;
  }
  if (H[0][2] + H[1][1] + H[2][0] == 3) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> height(N);
  for(int i = 0; i < N; i++){
    cin >> height.at(i);
  }
  height.at(0)--;
  for(int i = 1; i< N;i++){
    if(height.at(i-1) > height.at(i) ){
      cout << "No" ;
      return 0;
    }
    if(height.at(i-1)< height.at(i)){
    	height.at(i) --;
    }
    
  }
  
  cout << "Yes";
  
  return 0;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

/**
 * Returns the least index of elements that are modified, wrapped with Some.
 * If the entire array is reversed, it returns None instead.
 * v's elements must be pairwise distinct.
 */
fn next_permutation<T: Ord>(v: &mut [T]) -> Option<usize> {
    let mut tail_dec: usize = 1;
    let n = v.len();
    while tail_dec < n {
        if v[n - tail_dec - 1] > v[n - tail_dec] {
            tail_dec += 1;
        } else {
            break;
        }
    }
    // v[n - tail_dec .. n] is strictly decreasing
    if tail_dec < n {
        let x = n - tail_dec - 1;
        let mut y = n;
        {
            let pivot = &v[x];
            for i in (n - tail_dec .. n).rev() {
                if v[i] > *pivot {
                    y = i;
                    break;
                }
            }
            assert!(y < n);
        }
        v.swap(x, y);
    }
    v[n - tail_dec .. n].reverse();
    if tail_dec < n {
        Some(n - tail_dec - 1)
    } else {
        None
    }
}


fn solve() {
    let n: usize = get();
    let m = get();
    let rr = get();
    let r: Vec<usize> = (0 .. rr).map(|_| get::<usize>() - 1).collect();
    let mut dist = vec![vec![1 << 29; n]; n];
    for _ in 0 .. m {
        let a = get::<usize>() - 1;
        let b = get::<usize>() - 1;
        let c = get();
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }
    for k in 0 .. n {
        for i in 0 .. n {
            for j in 0 .. n {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    let mut perm = vec![0; rr];
    for i in 0 .. rr {
        perm[i] = r[i];
    }
    perm.sort();
    let mut mi = 1 << 29;
    loop {
        let mut tot = 0;
        for i in 0 .. rr - 1 {
            tot += dist[perm[i]][perm[i + 1]];
        }
        mi = min(mi, tot);
        if next_permutation(&mut perm).is_none() {
            break;
        }
    }
    println!("{}", mi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#defint mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
double arr[305],dp[305][305][305];

double solution(int a,int b,int c){
	if(a<0||b<0||c<0)
		return 0;
		
	if(a==0&&b==0&&c==0)
		return 0;
	
	if(dp[a][b][c]!=0)
		return dp[a][b][c];
	
	double sum = 0;
	int t = 0;
	if(a>0){
		sum = sum + solution(a-1,b,c)*((double)a/(a+b+c));
		t++;
	}
	
	if(b>0){
		t++;
		sum = sum + solution(a+1,b-1,c)*((double)b/(a+b+c));;
	}
	
	if(c>0){
		t++;
		sum = sum + solution(a,b+1,c-1)*((double)c/(a+b+c));
	}
	
	dp[a][b][c] = sum + arr[a+b+c];
	return dp[a][b][c];
}

int main(){
	boost;
	double n;
	int a,b,c;
	cin>>n;
	
	a=b=c=0;
	for(int i = n;i>0;i--){
		arr[i] = n/i;
		//cout<<arr[i]<<endl;
	}
	
	for(int i = 0;i<n;i++){
		int d;
		cin>>d;
		if(d==1){
			a++;
		}else if(d==2){
			b++;
		}else{
			c++;
		}
	}
	
	cout<<prec(10)<<solution(a,b,c);
	return 0;
}

//Total solved problems:- 13


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

int g[15][15];

int main() {
  int n;
  cin >> n;
  rep(i, n) rep(j, n) g[i][j] = -1;

  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      g[i][x - 1] = y;
    }
  }

  int ans = 0;
  rep(i, 1 << n) {
    vector<int> d(n);

    rep(j, n) {
      if (i >> j & 1) {
        d[j] = 1;
      }
    }

    bool ok = true;
    rep(j, n) {
      if (d[j] == 1) {
        rep(k, n) {
          if (g[j][k] == -1)
            continue;
          if (g[j][k] != d[k])
            ok = false;
        }
      }
    }

    if (ok)
      ans = max(ans, __builtin_popcount(i));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
L, R = [int(i) for i in input().split()]
min = 1 << 30
for i in range(L, R + 1):
    if i % 2019 == 0:
        print(0)
        exit()
L %= 2019
R %= 2019
for i in range(L, R):
    for j in range(i + 1, R + 1):
        if i * j % 2019 < min:
            min = i*j % 2019
print(min)


Measured memory_bytes: 9212
#include<bits/stdc++.h>
#pragma GCC optimize(3)
#define ll long long
using namespace std;
int main(){
	ll n,k,a[305];
	cin>>n>>k;
	for(ll i=1;i<=n;i++)cin>>a[i];
	ll dp[305][305];
	for(ll i=1;i<=300;i++){
		for(ll j=1;j<=i;j++)dp[i][j]=10000000000000000;
	}
	dp[0][0]=0;
	for(ll i=1;i<=n;i++)dp[i][1]=a[i];
	for(ll i=2;i<=n;i++){
		for(ll j=2;j<=i;j++){
			for(ll k=j-1;k<i;k++){
				if(a[k]<a[i]){
					dp[i][j]=min(dp[i][j],dp[k][j-1]+a[i]-a[k]);
				}else {
					dp[i][j]=min(dp[i][j],dp[k][j-1]);
				}
			}
		}
	}
	ll ans=10000000000000000;
	for(ll i=n-k;i<=n;i++){
		ans=min(ans,dp[i][n-k]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
let inf = 1000000000
let () =
  Scanf.scanf "%d %d %d" @@ fun n m x ->
  let books = Array.init n @@ fun i ->
    Scanf.scanf " %d" @@ fun c ->
    (c, Array.init m (fun i -> Scanf.scanf " %d" Fun.id)) in

  let ans =
    Array.init (1 lsl n) (fun i ->
      let rs = Array.init n (fun j -> ((1 lsl j) land i) > 0) in
      let ca =
        Array.init n (fun j -> if rs.(j) then fst books.(j) else 0)
        |> Array.fold_left (+) 0 in

      let ua =
        Array.init m (fun j ->
          books |> Array.mapi (fun i (c, us) -> (i, c, us))
          |> Array.fold_left (fun ua (i, _, us) ->
            if rs.(i) then ua + us.(j) else ua) 0)
        |> Array.fold_left min inf in

      let v = if ua < x then inf else ca in
      v)
    |> Array.fold_left min inf in

  Printf.printf "%d\n" (if ans = inf then -1 else ans)


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

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

	string ans = "Yes";
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0) {
			if (s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D') {
				ans = "No";
			}
		} else {
			if (s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D') {
				ans = "No";
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <array>
#include <tuple>
#include <algorithm>

struct edge{ int dest, color, length; };
struct node_param{ int nstep, ncount, length; };
struct euler_param{ int ncount, clength, cnum; };
std::vector<std::vector<edge>> t_arr;
std::vector<std::array<int, 20>> parent_arr;
std::vector<node_param> node_arr;
std::vector<std::vector<euler_param>> color_path_arr;

void dfs(int current, int parent, int nstep, int& ncount, int length, int color, std::vector<int>& current_clength, std::vector<int>& current_cnum){
  parent_arr[current][0] = parent;
  for(int k = 0; k < 20; k++){
    if(parent_arr[current][k] == -1) break;
    parent_arr[current][k+1] = parent_arr[parent_arr[current][k]][k];
  }
  node_arr[current].nstep = nstep;
  node_arr[current].ncount = ncount;
  node_arr[current].length = length;
  for(const auto& it: t_arr.at(current)){
    if(it.dest==parent) continue;
    ncount++;
    current_cnum[it.color]++;
    current_clength[it.color] += it.length;
    color_path_arr[it.color].push_back(euler_param{ncount, current_clength[it.color], current_cnum[it.color]});
    dfs(it.dest, current, nstep+1, ncount, length+it.length, it.color, current_clength, current_cnum);
    ncount++;
    current_cnum[it.color]--;
    current_clength[it.color] -= it.length;
    color_path_arr[it.color].push_back(euler_param{ncount, current_clength[it.color], current_cnum[it.color]});
  }
}

int lca(int node1, int node2){
  if(node_arr[node1].nstep > node_arr[node2].nstep) std::swap(node1, node2);
  int nstep_diff = node_arr[node2].nstep-node_arr[node1].nstep;
  int k = 0;
  while(nstep_diff > 0){
    if(nstep_diff & 1) node2 = parent_arr[node2][k];
    k++;
    nstep_diff >>= 1;
  }
  while(node1 != node2){
    int k2 = 0;
    while(parent_arr[node1][k2] != parent_arr[node2][k2]) k2++;
    k2 = std::max(0, k2-1);
    node1 = parent_arr[node1][k2];
    node2 = parent_arr[node2][k2];
  }
  return node1;
}

auto search_color_root(int color, int node){
  const auto& left = std::upper_bound(color_path_arr[color].begin(), color_path_arr[color].end(), node_arr[node].ncount, [](const int l, const euler_param& r){ return l < r.ncount;})-1;
  return *left;
}

int main(){
  int N,Q;
  scanf("%d%d", &N, &Q);
  t_arr.resize(N);
  for(int i = 0; i < N-1; i++){
    int a,b,c,d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
    a--; b--; c--;
    t_arr[a].push_back(edge({b,c,d}));
    t_arr[b].push_back(edge({a,c,d}));
  }

  parent_arr.resize(N, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} );
  node_arr.resize(N);
  color_path_arr.resize(N, std::vector<euler_param>(1));
  std::vector<int> clength_(N), cnum_(N);
  int ncount;
  dfs(0, -1, 0, ncount, 0, 0, clength_, cnum_);

  for(int i = 0; i < Q; i++){
    int x,y,u,v;
    scanf("%d%d%d%d", &x, &y, &u, &v);
    x--; u--; v--;
    int lcauv = lca(u,v);
    auto color_shift = [&](int node){
      auto cr = search_color_root(x, node);
      return node_arr[node].length + y*cr.cnum-cr.clength;
    };
    int ans = color_shift(u) + color_shift(v) - 2*color_shift(lcauv);
    printf("%d\n", ans);
  }

  return 0;
}




Measured memory_bytes: 32900
//CazadorDivino
#include "bits/stdc++.h"
#include <cmath>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){
	stringstream ss;
	ss << a;
	string str = ss.str();
	return str;
}

int conv(string a){
    stringstream geek(a); 
    int x = 0; 
    geek >> x;   
	return x;
}

vector<int>  graph[10];
bool visited[10], fin = false;
int cont = 0, m = 4;
string ans;

void add(int a, int b){
    graph[a].pb(b);
    graph[b].pb(a);
}

void dfs(int x){
	//~ cout<<fin<<endl;
	if(fin == true)
		return;
		
	visited[x] = true;
	cont++;
	
	rep(i,0,sz(graph[x])-1){
		if(visited[graph[x][i]] == false)
			dfs(graph[x][i]);
	}
	if(cont == m)
		ans = "YES";
	fin = true;
}

int main(){
	clr(visited,false);
	int a, b;
	ans = "NO";
	rep(i,1, 3){
		cin>>a >> b;
		add(a,b);
	}
	dfs(1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let l: usize = sc.read();
    let t: usize = sc.read();

    let mut right_cross = 0;
    let mut left_cross = 0;
    let mut ants = vec![];
    let mut positions = vec![];
    for _ in 0..n {
        let x: usize = sc.read();
        let right = sc.read::<usize>() == 1;
        ants.push((x, right));

        if right {
            right_cross += (t + x - 1) / l;
            positions.push((t + x) % l);
        } else {
            left_cross += (t + l - x) / l;

            let x = l - (t + l - x) % l;
            positions.push(x);
        }
    }
    right_cross %= n;
    left_cross %= n;
    let t = (right_cross + n - left_cross) % n;
    positions.sort();
    for i in 0..n {
        sc.write(positions[(i + t) % n] % l);
        sc.write("\n");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  cout << ((n + 1) / 2) << endl;
}






Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;
#include <string.h>

int main(){
	char s[10], t[10], u[10];
	scanf("%s%s", s, t);
	int a, b, len_s, len_u, i;
	scanf("%d%d", &a, &b);
	scanf("%s", u);
	len_s = strlen(s);
	len_u = strlen(u);
	for(i = 0; i < len_s + 1; i++) if(s[i] != u[i]) break;
	if(i == len_s + 1) a -= 1;
	else b -= 1;
	printf("%d %d", a, b);
	return 0;
}

Measured memory_bytes: 128