akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	char a[2];
	int b[2];
	cin >> a[0] >> a[1];
	for (int i = 0; i < 2;i++) {
		if (a[i] == 'H')b[i] = 1;
		else b[i] = -1;
	}
	if (b[0] == -1) b[1] *= -1;
	if (b[1] == 1) {
		cout << "H" << endl;
	}
	else {
		cout << "D" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        while (tan.hasNext()){
            int n,a=0;
            n=tan.nextInt();
            a=n%1000;
            if (a==0)
                a=1000;
            System.out.println(1000-a);
        }
    }
}


Measured memory_bytes: 35672
#include <string.h>

int main(void) {
  int n,m,i,x,p=0,s=0;
  int a[100001]={};
  char w[2];
  
  scanf("%d %d",&n,&m);
  
  for(i = 0; i < m; i ++) {
    scanf("%d %s",&x, w);
    if(strcmp(w,"AC") == 0)
      if(a[x] != -1) p += a[x], s ++, a[x] = -1;
    if(strcmp(w,"WA") == 0)
      if(a[x] != -1) a[x] ++ ;
  } 
  printf("%d %d",s,p);
}
   

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int S,h,m,s;
    h=0;
    m=0;
    s=0;
    scanf("%d",&S);
    if((S>=0)&&(S<86400)){
        if(S>=3600){
            h=S/3600;
            S=S%3600;
        }
        if(S>=60){
                m=S/60;
                S=S%60;
        }
        s=S;
    }
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef vector< bool > vb;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in(a,b) ( (b).find(a) != (b).end())


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

	int n, mw;
	cin >> n >> mw;

	vl w(n), v(n);
    LL maxv = 0;
	rep(i, n) {
        cin >> w[i] >> v[i];
        maxv += v[i];
    }

    LL INF = 99999999999;
    vl sac(maxv+1, INF);
    sac[0] = 0;

    auto valid = [mw](LL x) -> bool {return x <= mw;};
    rep(oi, n){
        for(LL j = maxv-v[oi]; j>=0; --j ) {
            if (sac[j] < INF && valid(sac[j] + w[oi])) {
                sac[j+v[oi]] = min(sac[j+v[oi]], sac[j] + w[oi]);
            }
        }
    }
    
    int sol = 0;
    rep(j, maxv+1)
        if (sac[j] < INF)
            sol = max(sol, j);

	cout << sol;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

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

#define MAX 105
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
int color[MAX], d[MAX], f[MAX], timer;
int nt[MAX];

//uに隣接するvを小さい方から取得
int next(int u){
    for(int v=nt[u]; v<=n; v++){
        nt[u] = v+1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r){
    for(int u=1; u<=n; u++) nt[u] = 1;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    timer++;
    d[r] = timer;

    while(!(S.empty())){
        int u = S.top();
        int v = next(u);
        if(v != -1){
            //隣接してて行けるところがある
            if(color[v] == WHITE){
                color[v] = GRAY;
                timer++;
                d[v] = timer;
                S.push(v);
            }
        }else{
            //もう隣接してて行けるところがない
            S.pop();
            color[u] == BLACK;
            timer++;
            f[u] = timer;
        }
    }
}

void dfs(){
    //初期化
    for(int u=1; u<=n; u++){
        color[u] = WHITE;
        nt[u] = 1;
    }
    timer = 0;

    //各頂点に対して白なら訪問する。
    for(int u=1; u<=n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    //出力
    for(int u=1; u<=n; u++){
        printf("%d %d %d\n", u, d[u], f[u]);
    }
}

//グラフの深さ優先探索(再帰を用いる)
int main(){
    cin >> n;
    //隣接リスト表現→隣接行列表現への変換
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            M[i][j] = 0;
        }
    }
    for(int i=1; i<=n; i++){
        int u, k;
        cin >> u >> k;
        for(int j=1; j<=k; j++){
            int v;
            cin >> v;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

bool check(int s, const vector<vector<pair<int, int>>>& v) {
  dbg(s);
  int n = v.size();
  rep(i, n) {
    bool honest = (s >> i) & 1;
    if (!honest) continue;
    for (const auto& p : v[i]) {
      int j = p.first;
      bool honest_j = (s >> j) & 1;
      if (p.second == 1 && !honest_j ||
          p.second == 0 && honest_j) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  in(int, n);
  vector<vector<pair<int, int>>> v(n);
  rep(i, n) {
    in(int, a);
    rep(j, a) {
      in(int, x, y);
      v[i].push_back({x - 1, y});
    }
  }
  int ans = 0;
  for (int s = 0; s < (1 << n); ++s) {
    if (check(s, v)) {
      ans = max(ans, __builtin_popcount(s));
    }
  }
  out(ans);
}


Measured memory_bytes: 256
def func():
    A, B, C = map(int, input().split())
    cand1 = A * 10 + B + C
    cand2 = B * 10 + A + C
    cand3 = C * 10 + A + B
    print(max(cand1, cand2, cand3))


if __name__ == '__main__':
    func()


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

int main() {
    int n, x;
    while(1){
        cin >> n >> x;
        int count = 0;
        if (n == 0 && x == 0) {
            break;
        } else {
            for (int i = 1; i <= n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    for (int k = j + 1; k <= n; k++){
                        if (i + j + k == x) {
                            count++;
                        }
                    }
                }
            }
        }
        cout << count << endl;
        
        
    }
    
    return 0;
}



Measured memory_bytes: 3100
import sys
n, m, *ab = (int(x) for x in sys.stdin.read().split())
from_1, to_n = set(), set()
for a, b in zip(*[iter(ab)] * 2): 
    if a == 1: from_1.add(b)
    elif b == n: to_n.add(a)
print('POSSIBLE' if from_1 & to_n else "IMPOSSIBLE")
# & は bloolean operator and ではなく set間で使われるoperator、 
# intersections が存在すればそれらのsetを返す。

Measured memory_bytes: 46660
#include <bits/stdc++.h>
using namespace std;
int main () {

 int c=3,a,b;
 cin>>a>>b;
 int f=a*b*c;
 if(f%2==0){
    cout<<"No"<<endl;
 }
 else{
    cout<<"Yes"<<endl;
 }

   return(0);
}


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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    char board[h][w];
    int count = 0;
    int ans = 0;
    rep(i,h){
        rep(j,w){
            char a;
            cin >> a;
            board[i][j] = a;
            if(a == '#') count++;
        }
    }

    for (int bit = 0; bit < (1<<h); ++bit) {
        vector<int> tate;
        for (int i = 0; i < h; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
            tate.push_back(i);
            }
        }
        for (int bit2 = 0; bit2 < (1<<w); ++bit2) {
        vector<int> yoko;
        int hoge = count;
        for (int j = 0; j < w; ++j) {
            if (bit2 & (1<<j)) { // 列挙に i が含まれるか
            yoko.push_back(j);
            }
        }
        rep(k,h){
            rep(l,w){
                if(board[k][l] == '#' && (find(tate.begin(),tate.end(),k) == tate.end() || find(yoko.begin(),yoko.end(),l) == yoko.end()) ){
                    hoge--;
                }

            }
        }
        if(hoge == k) ans++;
        
    }


    }
    cout << ans << endl;

}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int N, M;

    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            break;
        vector<vector<int>> v(M + 1);
        for (int i = 0; i < N; ++i)
        {
            int d, t;
            cin >> d >> t;
            v[d].push_back(t);
        }

        for (int i = 1; i <= M; ++i)
        {
            sort(v[i].begin(), v[i].end(), greater<int>());
        }
        int ans = 0;
        for (int i = 1; i <= M; ++i)
        {
            ans += v[i][0];
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3128
#include <stdio.h>

#define N 100
#define INF 1000000000

int dp[N+1][N+1];
int C[N][N];
int A[N+1];

int min(int a, int b){
  if(a<b) return a;
  else return b;
}

void print_solution(int l, int r){
  if(l+1==r) printf("M%d", l);
  else{
    printf("(");
    print_solution(l,C[l][r]);
    printf(" ");
    print_solution(C[l][r],r);
    printf(")");
  }
}

int q(int l, int r){
  if(dp[l][r]!=INF) return dp[l][r];
  
  if(l+1==r) dp[l][r] = 0;
  else{
    for(int m=l+1;m<r;m++){
      if(dp[l][r]>q(l,m)+q(m,r)+A[l]*A[m]*A[r]){
        dp[l][r] = q(l,m)+q(m,r)+A[l]*A[m]*A[r];
        C[l][r] = m;
      }
    }
  }
  return dp[l][r];
}

int main(){
  int n, i, j ,k;

  scanf("%d", &n);
  for(i=0; i<n; i++){
      scanf("%d %d", &A[i], &A[i+1]);
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      dp[i][j] = INF;
    }
  }

  printf("%d\n", q(0,n));
  //print_solution(0,n);
  //printf("\n");


  return 0;
}



Measured memory_bytes: 2104
import math
dish = [int(input()) for _ in range(5)]
sm = 9
smin = 0
for cnt, item in enumerate(dish):
  r = item % 10
  if 1 <= r <= 9:
    if sm > r:
      sm = r
      smin = cnt
ans = 0    
for cnt, item in enumerate(dish):
  if cnt == smin:
    ans += item
  else:
    r = item % 10
    if 1 <= r <= 9:
      ans += item + 10 - r
    else:
      ans += item
print(ans)    

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
const int MAXN = 100000 + 7;
const int NIL = -1;

vector<int> G[MAXN];
int status[MAXN];
int N;

void dfs( int  r, int c )
{
    stack<int> S;
    S.push(r);
    status[r] = c;
    while ( !S.empty() ) {
        int u = S.top(); S.pop();
        for ( int i = 0; i < G[u].size(); i++ ) {
            int v = G[u][i];
            if ( status[v] == NIL ) {
                status[v] = c;
                S.push(v);
            }
        }
    }
}

void set_status()
{
    int id = 1;
    memset( status, -1, sizeof(status) );
    for ( int u = 0; u < N; u++ ) {
        if ( status[u] == NIL )
            dfs( u, id++ );
    }
}

int main()
{
    int m, s, t, q;
    cin>>N>>m;
    for ( int i = 0; i < m; i++ ) {
        cin>>s>>t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    set_status();

    cin>>q;
    for ( int i = 0; i < q; i++ ) {
        cin>>s>>t;
        if ( status[s] == status[t] ) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 2e5+10;
int N;
vector<vector<int> > Tree(N_MAX);
vector<vector<int> > G(N_MAX);
vector<int> counter(N_MAX,0);
vector<int> ans(N_MAX,0);

void dfs(int v, int p){
  ans[v] = counter[v] + ans[p];
  for(const int &u:Tree[v]) dfs(u,v);
}

void makeTree(int v,int p){
  for(const int &u:G[v]) if(u != p){
    Tree[v].push_back(u);
    makeTree(u,v);
  }
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int Q;cin >> N >> Q;
  set<int> st;
  st.insert(1);
  //木の構築
  rep(i,N-1){
    int x,y;cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  //Counterの変更
  while(Q--){
    int p,x;cin >> p >> x;
    counter[p] += x;
  }
  //根に近いほうから計算する
  makeTree(1,0);
  dfs(1,0);
  rep(i,N) cout << ans[i+1] SPF;
  cout << endl;
  return 0;
}


Measured memory_bytes: 35200
#!/usr/bin/env python3
import numpy
import sys

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0

if sum(a[0]) == 0:
    print("Yes")
    sys.exit()
elif sum(a[1]) == 0:
    print("Yes")
    sys.exit()
elif sum(a[2]) == 0:
    print("Yes")
    sys.exit()
else:
    a_t = numpy.array(a).T
    if sum(a_t[0]) == 0:
        print("Yes")
        sys.exit()
    elif sum(a_t[1]) == 0:
        print("Yes")
        sys.exit()
    elif sum(a_t[2]) == 0:
        print("Yes")
        sys.exit()
    else:
        if a[0][0] + a[1][1] + a[2][2] == 0:
            print("Yes")
            sys.exit()
        elif a[0][2] + a[1][1] + a[2][0] == 0:
            print("Yes")
            sys.exit()
print("No")


Measured memory_bytes: 27176
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a < b){
      System.out.println(0);
    }else{
      System.out.println(10);      
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>

int gcd(int a1,int a2)
{
	int r=1;
	while(r!=0){
		r=a1%a2;
		a1=a2;
		a2=r;
	}
	return a1;
}

int main(void)
{
	int i,n,a1,a2;
	scanf("%d%d",&n,&a1);
	for(i=1;i<n;i++)
	{
		scanf("%d",&a2);
		a1=gcd(a1,a2);
	}
	printf("%d",a1);
	return 0;
}
	

Measured memory_bytes: 128
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i64> = readnc();

    let mut imos: Vec<i64> = vec![];
    imos.push(0);
    for i in 0..n {
        let sum = imos[i] + a[i];
        imos.push(sum);
    }

    let mut best: i64 = 1e15 as i64;
    for i in 2..n-1 {
        let ((al, bl),(cl, dl)) = split(0, i, &imos);
        let ((ar, br),(cr, dr)) = split(i, n, &imos);

        best = min(best, diff(al, bl, ar, br));
        best = min(best, diff(al, bl, cr, dr));
        best = min(best, diff(cl, dl, ar, br));
        best = min(best, diff(cl, dl, cr, dr));
    }
    println!("{}", best);
}

fn diff(a: i64, b: i64, c: i64, d: i64) -> i64 {
    let min = min(min(a, b), min(c, d));
    let max = max(max(a, b), max(c, d));
    return max - min;
}

fn split(f: usize, t: usize, imos: &Vec<i64>) -> ((i64, i64), (i64, i64)) {
    let sum = imos[t] - imos[f];
    if t - f <= 2 {
        let one = imos[f+1] - imos[f];
        let two = imos[f+2] - imos[f+1];
        return ((one, two), (one, two));
    }

    let mut low = f;
    let mut high = t;
    while (high - low > 1) {
        let med = (low + high) / 2;
        let left = imos[med] - imos[f];
        let right = imos[t] - imos[med];
        if left < sum / 2 {
            low = med;
        } else {
            high = med;
        }
    }
    let one = imos[low] - imos[f];
    let two = imos[t] - imos[low];

    if low+1 == t {
        return ((one, two), (one, two))
    } else {
        let onen = imos[low+1] - imos[f];
        let twon = imos[t] - imos[low+1];
        return ((one, two), (onen, twon));
    }
}


Measured memory_bytes: 12528
import java.io.*;
 
class Main{ 
public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[ ] str_div = br.readLine().split(" ");
        int x = Integer.parseInt(str_div[0]);
        int y = Integer.parseInt(str_div[1]);
        int z = Integer.parseInt(str_div[2]);
        if(x < y && y< z )
        System.out.println("Yes");
        else
        System.out.println("No");
 }
}
   

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

const int MAX_D = 10;
const int INF = 100000000;
int D, G;
int p[MAX_D], c[MAX_D];
int ans = INF;

int main() {
  cin >> D >> G;
  for (int i = 0; i < D; i++)
    cin >> p[i] >> c[i];
  for (int bit = 0; bit < (1<<D); bit++) {
    int points = 0;
    int problems = 0;
    for (int i = 0; i < D; i++) {
      if (bit & (1<<i)) { 
        points += 100 * (i+1) * p[i] + c[i];
        problems += p[i];
      }
    }
    if (points >= G) {
      for (int i = 0; i < D; i++) {
        int pb = problems;
        if (bit & (1<<i)) {
          int pt = points - c[i];
          int a = (pt - G) / (100 * (i+1));
          if (0 <= a && a < p[i]) {
            pb -= a;
          }
          ans = min(ans, pb);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}        

Measured memory_bytes: 256
module Main where

import Data.List
import Control.Monad
import Control.Monad.ST (runST)
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import Data.Function (fix)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [(Int, Int)] -> [(Int, Int)] -> [Int]
solve n abList pxList = runST $ do
        graph <- MV.replicate (n + 1) []
        forM_ abList $ \(a, b) -> do 
            MV.modify graph (a:) b
            MV.modify graph (b:) a
        points <- UMV.replicate (n + 1) 0
        forM_ pxList $ \(p, x) -> UMV.modify points (+x) p
        let dfs = fix $ \next point parent -> do
                myPoint <- UMV.read points point
                sons <- MV.read graph point
                forM_ sons $ \son ->
                    if son == parent then return ()
                    else do 
                        UMV.modify points (+myPoint) son
                        next son point
        dfs 1 (negate 1)
        frozenAns <- UV.freeze points
        pure . tail $  UV.toList frozenAns


main = do
    (n, q) <- readTuple2
    abList <- replicateM (n - 1) readTuple2
    pxList <- replicateM q readTuple2
    putStrLn $ unwords  $ show <$> solve n abList pxList


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

using namespace std;
const int MAXN = 1000005; //1000005; change
int xAxis[MAXN];
int diffs[MAXN];
vector<int> trip;

int main()
{
    //freopen("in","r",stdin);

    int Npoints, partial_value = 0;

    cin >> Npoints;

    for(int i = 1; i <= Npoints; ++i)
    {
        int value;
        cin >> value;
        xAxis[i] = value;
    }

    for(int i=1; i<Npoints;++i)
    {
        diffs[i-1] =  abs(xAxis[i]-xAxis[i+1]);
        partial_value += abs(xAxis[i]-xAxis[i+1]);
    }

    //ignoring the trip to ith point

    for(int i = 1; i <= Npoints; i++)
    {
        int ans = partial_value;

        if(i != 1 && i != Npoints)
        {
            ans -= diffs[i-2];
            ans -= diffs[i-1];

            ans += abs(xAxis[i-1] - xAxis[i+1]);
            ans += abs(xAxis[1]);
            ans += abs(xAxis[Npoints]);
            cout << ans << endl;
        }
        else
        {
            if(i == 1)
            {
                ans -= diffs[0];
                ans += abs(xAxis[i+1]);
                ans += abs(xAxis[Npoints]);
                cout << ans << endl;
            }
            else if ( i == Npoints)
            {
                ans -= diffs[i-2];
                ans += abs(xAxis[i-1]);
                ans += abs(xAxis[1]);
                cout << ans << endl;
            }
        }



//        cout << ans << endl;
    }


}


Measured memory_bytes: 5760
#include <stdio.h>

int main(void){
    int n,bunsi=0;
    scanf("%d", &n);
    if(n%2==0){
        bunsi=n/2;
    }else{
        bunsi=n/2+1;
    }
    printf("%f\n",(double)bunsi/n );
    return 0;

}


Measured memory_bytes: 128
void main()
{
    long h = rdElem;
    long w = rdElem;
    long n = rdElem;

    long a = max(h, w);
    writeln((n + a - 1) / a);
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
from collections import deque
n, c = map(int, raw_input().split())
l = deque()
for _ in xrange(n):
    s, t, c = map(int, raw_input().split())
    l.append((s, t, c))
def comp(t1, t2):
    if t1[0] == t2[0]:
        return cmp(t1[1], t2[1])
    return cmp(t1[0], t2[0])
l, cnt, rec = sorted(l, cmp = comp), 0, deque()
for s, t, c in l:
    f = False
    for i, (rt, rc) in enumerate(rec):
        if c == rc:
            if s >= rt:
                rec[i] = (t, c)
                f = True
                break
        else:
            if s > rt:
                rec[i] = (t, rc)
                f = True
                break
    if not f:
        rec.append((t, c))
print len(rec)

Measured memory_bytes: 17728
//
// Created by Myabu on 2020/01/14.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>

using namespace std;


int main(void){
    int N,A;

    cin>>N>>A;

    if(N%500-A <= 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

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


ll dp[105][100005];


int main(){

  ll n,W;
  cin>>n>>W;
  vector<ll> v(n);
  vector<ll> w(n);

  rep(i,n){
    cin>>w[i];
    cin>>v[i];
  }
  rep(i,105)rep(j,100005)dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,n)rep(j,100001){
    dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    if (j>=v[i]){
      dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
    }
  //  if (dp[i+1][j]!=INF)cout<<dp[i+1][j]<<endl;
  }
  ll ans=0;
  rep(i,100001){
    if (dp[n][i]>W)continue;
    ans=max(ans,i);
  //  cout<<ans<<endl;
  }
  cout<<ans;

}


Measured memory_bytes: 85636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int N;
    cin>>N;
    vint A(N);
    rep(i,N)
    {
        cin>>A[i];
    }
    int M = *max_element(all(A));
    vint C = A;
    C.erase(max_element(all(C)));
    int M2 = *max_element(all(C));
    int dis = distance(A.begin(),max_element(all(A)));
    rep(i,N)
    {
        if((i) != dis)
        {
            cout<<M<<endl;
            continue;
        }
        else if(M == M2)
        {
            cout << M <<endl;
            continue;
        }
        else {
        cout<<M2 << endl;
    }
    }
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string card = Console.ReadLine();
                if (card == "-")
                    break;

                int shuffle_count = int.Parse(Console.ReadLine());
                for (int i = 0; i < shuffle_count; i++)
                {
                    int h = int.Parse(Console.ReadLine());
                    card = card.Substring(h) + card.Substring(0, h);
                }
                Console.WriteLine(card);
            }
        }
    }
}

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

using namespace std;

typedef long long ll;
vector<int> dt[26];
int dp[200001][26];
int nx[200001][26];
int n;
string s;
int solve(int in, int c){
  if(in == n)
    return 1;
  if(dp[in][c] != -1)
    return dp[in][c];
  auto it = lower_bound(dt[c].begin(), dt[c].end(), in);
  if(it == dt[c].end())
    return 1;
  int mn = 1000000;
  for(int i = 0;i < 26;i++){
    if(1 + solve(*it + 1, i) < mn){
      mn = 1 + solve(*it + 1, i);
      nx[in][c] = i;
    }
  }
  return dp[in][c] = mn;
}
void recon(int in, int c){
  cout << char(c + 'a');
  auto it = lower_bound(dt[c].begin(), dt[c].end(), in);
  if(it == dt[c].end())
    return;
  recon(*it + 1, nx[in][c]);
}
signed main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  memset(dp, -1, sizeof(dp));
  memset(nx, -1, sizeof(nx));
  cin >> s;
  n = s.size();
  for(int i = 0;i < n;i++)
    dt[s[i] - 'a'].push_back(i);
  int ans = 10000000;
  int ain = 0;
  for(int i = 0;i < 26;i++){
    int x = solve(0, i);
    if(x < ans){
      ans = x;
      ain = i;
    }
  }
  recon(0, ain);
}


Measured memory_bytes: 42500
#include <stdio.h>
 
int main ()
{
  char s[3];
  int ans;
  
  scanf("%s", s);
  
  if(s[0]=='1')
    ans++;
  if(s[1]=='1')
    ans++;
  if(s[2]=='1')
    ans++;
    
  printf("%d", ans);
  
  return 0 ;
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N=2002,M=1e9+7;
int n,m,k,f[N*N],F[N*N],g[N][N];
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=1LL*a*a%M)if(b&1)s=1LL*s*a%M;
	return s;
}
int main(){
	cin>>n>>k;m=n*k;
	if(k==1){puts("1");return 0;}
	f[0]=1;
	for(int i=1;i<=m;++i)f[i]=1LL*f[i-1]*i%M;
	F[m]=mi(f[m],M-2);
	for(int i=m;i>=1;--i)F[i-1]=1LL*F[i]*i%M;
	g[0][0]=1;
	for(int i=0,I=k-1;i<=n;++i,I+=k-1)for(int j=0;j<=i;++j){
		(g[i+1][j]+=1LL*g[i][j]*f[I+j-1]%M*F[I+j-k+1]%M*F[k-2]%M)%=M;
		(g[i][j+1]+=g[i][j])%=M;
	}
	cout<<1LL*g[n][n]*f[n]%M<<endl;
}

Measured memory_bytes: 46336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	void solve(){

		ini(morty);
		ini(morty1);
		ini(mortyhalf);
		ini(x);
		ini(x1);
		if(x<x1){
			swap(x,x1);
			swap(morty,morty1);
		}
		int rick = inf;
		int tmp = 0;
		tmp = x1*2*mortyhalf+(x-x1)*morty;
		rick = min(rick,tmp);
		tmp = x*2*mortyhalf;
		rick = min(rick,tmp);
		tmp = x*morty+x1*morty1;
		rick = min(rick,tmp);
		out(rick);

		
		
		








	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


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

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

signed main(){

  int d;
  vector<int> c(26);
  cin>>d;
  for(auto& ci:c)cin>>ci;
  vector<vector<int>> s(d,vector<int>(26));
  for(auto& si:s)for(auto& sij:si)cin>>sij;

  auto calc_satisfaction_level = [&s,&c](int d,int i,auto last){
    int64_t res = s[d][i];
    for(int j=0;j<26;++j){
      if(i==j)continue;
      res -= c[j]*(d-last[j]+1);
    }
    return res;
  };

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

  int k = 5;
  vector<vector<int>> last(k,vector<int>(26));
  vector<vector<int>> ans(k,vector<int>(d));
  vector<int64_t> top_k_val(k);

  auto test_all_get_max = [&](int di,auto last){
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    vector<pair<int,int>> valtype_max(26);
    for(int type=0;type<26;++type){
      valtype_max[type] = {calc_satisfaction_level(di,type,last),type};
    }
    sort(begin(valtype_max),end(valtype_max),greater<>());
    valtype_max.erase(begin(valtype_max)+k,end(valtype_max));
    assert(size(valtype_max)==k);
    return valtype_max;
  };

  rep(di,d){
    vector<tuple<int,int,int>> next_top_k;
    next_top_k.reserve(k*26);
    rep(ki,k){
      auto tmp = test_all_get_max(di,last[ki]);
      for(int i=0;i<26;++i)next_top_k.emplace_back(tmp[i].first+top_k_val[ki],tmp[i].second,ki);
    }
    sort(begin(next_top_k),end(next_top_k),greater<>());
    next_top_k.erase(begin(next_top_k)+k,end(next_top_k));
    vector<vector<int>> nxt_last(k,vector<int>(26));
    vector<vector<int>> nxt_ans(k,vector<int>(d));
    vector<int64_t> nxt_top_k_val(k);
    rep(i,k){
      auto [val,type,prv_ki] = next_top_k[i];
      nxt_last[i] = last[prv_ki];
      nxt_last[i][type] = di+1;
      nxt_ans[i] = ans[prv_ki];
      nxt_ans[i][di] = type;
      nxt_top_k_val[i] = val;
    }
    last = nxt_last;
    ans = nxt_ans;
    top_k_val = nxt_top_k_val;
  }

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

  for(int i=0;i<d;++i)cout<<ans[0][i]+1<<endl;

}

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

using ll = long long;
int main() {
    #ifdef LU_SERIOUS
        freopen( "in.txt", "r", stdin );
    #endif // LU_SERIOUS
    string s;
    string s1 = "dream", s2="dreamer", s3="erase", s4="eraser", ss;
    reverse( s1.begin(), s1.end() );
    reverse( s2.begin(), s2.end() );
    reverse( s3.begin(), s3.end() );
    reverse( s4.begin(), s4.end() );
    while( cin >> s ) {
        bool fl = 1;
        ss = "";
        for( int i=s.size()-1; i>=0; i-- ) {
            ss += s[i];
//            cerr << ss << "\n";
            if( ss == s1 ) ss = "";
            if( ss == s2 ) ss = "";
            if( ss == s3 ) ss = "";
            if( ss == s4 ) ss = "";
            if( ss.size() > 7 ) {
                fl = 0;
                break;
            }
        }
        if( ss.size() )  fl = 0;
        puts( fl ? "YES" : "NO" );
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int n; cin >> n;
    vector<double> x(n), y(n);
    vector<double> d(n);
    rep(i,n) { d[i] = i; }
    double ans = 0;

    rep(i,n) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    int cnt = 0;
    do {
        rep(i, d.size()-1) {
            double t= 0;
            t += (x[d[i]] - x[d[i+1]]) * (x[d[i]] - x[d[i+1]]);
            t += (y[d[i]] - y[d[i+1]]) * (y[d[i]] - y[d[i+1]]);
            ans += sqrt(t);
        }
        cnt++;

    } while (next_permutation(d.begin(), d.end()));

    printf("%.8f\n", ans/cnt);

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
       char c[10];
        int all=700;
	gets(c);
	//scanf_s("%s", c);
	for (int i = 0; i < 3; i++)
	{
		if (c[i] == 'o')
			all += 100;
	}
	printf("%d", all);
 
    return 0;
}
 

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

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

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll arr[18][18],dp[1<<18],cost[1<<18];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N; cin >> N;

    F0R(i,N) F0R(j,N) {
        cin >> arr[i][j];
    }

    memset(dp,-1,sizeof dp);
    F0R(i,N) dp[i] = 0;

    F0R(mask,1<<N) {
        F0R(i,N) {
            FOR(j,i+1,N) {
                if (mask&(1<<i) && mask&(1<<j)) {
                    cost[mask] += arr[i][j];
                }
            }
        }
    }

    F0R(mask,1<<N) {
        for (int smask = mask; smask; smask = (smask-1)&mask) {
            dp[mask] = max(dp[mask],dp[mask^smask]+cost[smask]);
        }
    }

    cout << dp[(1<<N)-1] << "\n";

}


Measured memory_bytes: 2816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

long long gcd(long long a,long long b){
    long long m,n,gcdans;
    m=fmax(a,b);
    n=fmin(a,b);
    if(n==0){
        gcdans=m;
    } else {
        gcdans=gcd(n,m%n);
    }
    return (gcdans) ;
}

int main(void){
    long long n,x,ans;
    scanf("%lld%lld",&n,&x);
    long long a,y[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&a);
        y[i]=llabs(a-x);
    }
    if (n==1){
        ans=y[0];
    } else {
        ans=gcd(y[0],y[1]);
        for (int i=1; i<n-1; i++){
            ans=gcd(ans,y[i]);
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}


Measured memory_bytes: 896
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int num = 0;
		int ans = 0;
		for(int i = 1;i <= n;i++){
			String[] str = Integer.toString(i).split("");
			num = 0;
			for(int j =0;j < str.length;j++){
				num += Integer.parseInt(str[j]);
			}
			if(a <= num && num <= b){
				ans += i;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 33236
#include <stdio.h>

int A[500001], H;

void maxHeapify(int);

int main()
{
  int i;

  scanf("%d",&H);

  for(i = 1; i <= H; i++)
    {
      scanf("%d",&A[i]);
    }

  for(i = H/2; i > 0; i--)
    {
      maxHeapify(i);
    }

  for(i = 1; i <= H; i++)
    {
      printf(" %d",A[i]);
    }

  printf("\n");
  
  return 0;
}


void maxHeapify(int i)
{
  int l, r, largest, temp;

  l = 2*i;
  r = 2*i+1;

  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;

  if(l <= H && A[r] > A[largest])largest = r;

  if(largest != i)
    {
      temp = A[i];
      A[i] = A[largest];
      A[largest] = temp;

      maxHeapify(largest);
    }
}



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

LL ans;
LL dfs(LL x,LL y){
	if(!y)return x;
	ans+=x/y*y*2;
	return dfs(y,x%y);
}
int main()
{
	LL n,x,y;
	scanf("%lld%lld",&n,&x);
	ans=n;
	y=dfs(max(x,n-x),min(x,n-x));
	cout<<ans-y;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int N;
  int A;
  int i;
  int count = 0;

  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d", &A);
    if(A%2 == 1) {
      count++;
    }
  }

  if(count%2 == 0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		char[] input = sc.next().toCharArray();
		char[] keyence = {'k', 'e', 'y', 'e', 'n', 'c', 'e', '_'};
		int select_keyence = 0;
		int wrong_char=-1;
		int after_wrong_char=0;
		boolean char_flag=true;
		boolean flag = true;
		String ans;
		for(int i=0; i<input.length; i++){

			if (input[i]!=keyence[select_keyence]){
				if(!char_flag && select_keyence==7){
					select_keyence = after_wrong_char;
					if(input[i]==keyence[select_keyence]){
						select_keyence++;
					}
					
				}
				if(char_flag){
					char_flag = false;
					after_wrong_char = select_keyence;
				}
				if (i-wrong_char>1){
					select_keyence = after_wrong_char;
					if(input[i]==keyence[select_keyence]){
						select_keyence++;
					}
				}
				wrong_char=i;
			}else{
				select_keyence++;
			}
			/*
			System.out.println("select_keyence:"+select_keyence);
			System.out.println("wrong_char:"+wrong_char);
			System.out.println("after_wrong_char:"+after_wrong_char);
			 */
		}
		if(!(select_keyence==7))flag=false;
		
		if(!flag){
			ans = "NO";
		}else{
			ans ="YES";
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N,M; cin>>N>>M;
    vector<ll>a(M);
    ll sm=0;
    rep(i,M){
        cin>>a[i];
        sm+=a[i];
    }
    if(sm>N)cout<<-1<<endl;
    else cout<<N-sm<<endl;
}




Measured memory_bytes: 3700
N=int(input())
a=[int(i) for i in input().split()]
b=list(set(a))
if len(b)==1:
    if b[0]==0:
        print("Yes")
    else:
        print("No")
else:
    if N%3==0 and len(b)==3:
        D={b[0]:0,b[1]:0,b[2]:0}
        for i in range(N):
            D[a[i]]+=1
        if D[b[0]]==D[b[1]] and D[b[1]]==D[b[2]] and b[0]^b[1]==b[2]:
            print("Yes")
        else:
            print("No")
    else:
        if N%3==0 and len(b)==2:
            D={b[0]:0,b[1]:0}
            for i in range(N):
                D[a[i]]+=1
            if D[b[0]]==D[b[1]]*2:
                if b[0]^b[0]==b[1]:
                    print("Yes")
                else:
                    print("No")
            elif D[b[1]]==D[b[0]]*2:
                if b[1]^b[1]==b[0]:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")


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

int main(int argc, char *argv[])
{
    while (1)
    {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0)
        {
            break;
        }

        int count = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                for (int k = j + 1; k <= n; k++)
                {
                    if (i + j + k == x)
                    {
                        count++;
                    }
                }
            }
        }

        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]

AB.sort(key=lambda x: x[1])
worktime = 0
ndat = 0
for i in range(N):
    worktime += AB[i][0]
    if worktime > AB[i][1]:
        print('No')
        break
    ndat += 1
if ndat == N:
    print('Yes')

Measured memory_bytes: 53728
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
///-------------------------------------------


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

int main(){
    int N;
    cin>>N;
    if(N%10==9||N/10==9) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}





















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll> a(N),b(N);
	rep(i,N)cin >> a[i];
	rep(i,N){
		if(i==0)b[i] = a[i];
		else b[i] = a[i] + b[i-1];
	}
	ll ans = INF;
	rep(i,N){
		if(b[i]==b[N-1]-b[i]){
			cout << 0 << endl;
			return 0;
		}else{
			ans = min(ans,abs(b[N-1]-b[i] - b[i]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3456