akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};


int H,W;

int bfs(vector<string> field, int sx, int sy, int gx, int gy)
{
    vector<vector<int> > dist(H, vector<int>(W, -1)); 
    dist[sx][sy] = 0; // スタートを 0 に
    queue<pair<int, int> > que;
    que.push(make_pair(sx, sy));

    vector<vector<int> > prev_x(H, vector<int>(W, -1));
    vector<vector<int> > prev_y(H, vector<int>(W, -1));

    while (!que.empty()) {
        pair<int, int> current_pos = que.front(); // キューの先頭を見る (C++ ではこれをしても pop しない)
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop(); // キューから pop を忘れずに

        // 隣接頂点を探索
        for (int direction = 0; direction < 4; ++direction) {
            int next_x = x + dx[direction];
            int next_y = y + dy[direction];
            if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue; // 場外アウトならダメ
            if (field[next_x][next_y] == '#') continue; // 壁はダメ

            // まだ見ていない頂点なら push
            if (dist[next_x][next_y] == -1) {
                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1; // (next_x, next_y) の距離も更新
                prev_x[next_x][next_y] = x;  // どの頂点から情報が伝播して来たか、縦方向の座標をメモ
                prev_y[next_x][next_y] = y;  // どの頂点から情報が伝播して来たか、横方向の座標をメモ
            }
        }
    }
    
    return dist[gx][gy];
}

int main()
{
    cin >> H >> W;
    vector<string> field(H);
    for (int h = 0; h < H; ++h) cin >> field[h];

    // int sx, sy, gx, gy;
    // int ans=0;
    // for (int sy = 0; sy < H; ++sy) {
    //     for (int sx = 0; sx < W; ++sx) {
    //         for (int gy = 0; gy<H; ++gy)
    //         {
    //             for (int gx = 0; gx<W; ++gx)
    //             {
    //                 if(field[sy][sx]=='#' || field[gy][gx]=='#') continue;
    //                 int tmp = bfs(field,sx,sy,gx,gy);
    //                 if(ans<tmp) ans = tmp;
    //             }
    //         }
    //     }
    // }

    int sx, sy, gx, gy;
    int ans=0;
    for (int sx = 0; sx < H; ++sx) {
        for (int sy = 0; sy < W; ++sy) {
            for (int gx = 0; gx<H; ++gx)
            {
                for (int gy = 0; gy<W; ++gy)
                {
                    if(field[sx][sy]=='#' || field[gx][gy]=='#') continue;
                    int tmp = bfs(field,sx,sy,gx,gy);
                    if(ans<tmp) ans = tmp;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll N;
	
	cin >> N;

	ll tmp = N;
	std::vector<int> v;

	while(tmp)
	{
		ll t;
		//cout << tmp << endl;
		if (tmp < 0)
		{
			if ((-tmp) % 2 )
			{
				t = (-tmp+1) / 2 ;
			}
			else
			{
				t = (-tmp) / 2 ;
			}
		}
		else
		{
			t = (tmp) / 2 * -1;
		}

		v.pb(tmp - t * (-2));
		tmp = t;
	}

	if (v.size() == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		for(int i = v.size()-1; i >= 0; i--)
		{
			cout << v[i];
		}

		cout << endl;
	}
	

	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;

int h,w;
inline bool inside(int x,int y)
{
	return 1<=x && x+2<=h && 1<=y && y+2<=w;
}

long long cnt[10];

map<pair<int,int>,int> m;

int main()
{
	int n;
    scanf("%d %d %d",&h,&w,&n);

    long long total = (h-2)*1ll*(w-2);

    for(int i=1,a,b;i<=n;i++)
    {
		scanf("%d %d",&a,&b);
		for(int x=a-2;x<=a;x++)
			for(int y=b-2;y<=b;y++)
				if(inside(x,y)) m[make_pair(x,y)]++;
    }

    for(auto it=m.begin();it!=m.end();it++)
    {
        cnt[it->second]++;
        total--;
    }

    cnt[0]=total;
    for(int i=0;i<10;i++)
		printf("%lld\n",cnt[i]);
	return 0;
}


Measured memory_bytes: 56448
import numpy as np
import copy
from itertools import combinations
H,W,K=list(map(int,input().split()))
C1=[list(input()) for i in range(H)]
C1=np.array(C1)
listH=[i for i in range(H)]
listW=[i for i in range(W)]
listH2=[]
listW2=[]
for i in range(0,H+1):
    listH2.append(list(combinations(listH,i)))
listH2=[flat for i in listH2 for flat in i]

for i in range(0,W+1):
    listW2.append(list(combinations(listW,i)))
listW2=[flat for i in listW2 for flat in i]

ans=0
for h in listH2:
    for w in listW2:
        ans2=0
        C=copy.deepcopy(C1)
        if h!=():
            for i in h:
                C[i]='.'
        if w!=():
            for j in w:
                C[:,j]='.'
        for i in C:
            for j in i:
                if j=='#':
                    ans2+=1
        if ans2==K:
            ans+=1
print(ans)
                

Measured memory_bytes: 27160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N, Q;
	while(cin >> N >> Q, N) {
		vs name(N);
		vvi year(N, vi(2));

		REP(i, N) {
			cin >> name[i] >> year[i][0] >> year[i][1];
			year[i][0] = year[i][1]-year[i][0]+1;
		}

		REP(i, Q) {
			int y;
			cin >> y;
			REP(j, N) {
				if(year[j][0] <= y && y <= year[j][1]) {
					cout << name[j] << " " << y-year[j][0]+1 << endl;
					goto next;
				}
			}
			cout << "Unknown" << endl;
			next:;
		}
	}

	return 0;
}

Measured memory_bytes: 1348
n, l = map(int, input().split())

a = []
for i in range(n) :
    a.append(l+i)

n_sum = sum(a)
answer = 0    
calc = []
for i in range(n) :
    diff = n_sum - a[i]
    calc.append((diff,abs(n_sum-diff)))    

from operator import itemgetter
calc = sorted(calc, key=itemgetter(1), reverse=False)    
    
print(calc[0][0])

Measured memory_bytes: 3064
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str1=Console.ReadLine().Split(' ');
     int N =int.Parse(str1[0]);
      int K=int.Parse(str1[1]);
      int ans=0;
     string[] str2=Console.ReadLine().Split(' ');
      int[] height=str2.Select(int.Parse).ToArray();
      
      for(int i=0;i<N;i++)
      {
        if(height[i]>=K){
          ans++;
        }
      }
      Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 35272
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> cards(N + 1, 0);
  rep(i, M)
  {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cards[l]++;
    cards[r + 1]--;
  }

  int sum = 0;
  int count = 0;
  rep(i, N)
  {
    sum += cards[i];
    if (sum == M)
    {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


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

int main() { 
    long long n, ans = 0;
    cin >> n;
    long long a[n];
    int cntm = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(a[i] == 0) cntm = -1;
        else if(a[i] < 0 && cntm != -1) cntm++;
    }
    if(cntm == -1) cntm = 0;
    if(cntm%2 == 1) {
        for(int i = 0; i < n; ++i) {
            if(a[i] < 0) a[i] *= -1;
        }
        sort(a, a+n);
        ans -= a[0];
        for(int i = 1; i < n; ++i) ans += a[i];
    } else {
        for(int i = 0; i < n; ++i) {
            if(a[i] > 0) ans += a[i];
            else ans += a[i]*-1;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    int L = s.size();
    // i : 削る回数
    FOR(i, 1, L/2){
        int len = L - 2 * i;
        int half = len/2;
        string s0 = s.substr(0, half);
        string s1 = s.substr(half, half);
        if(s0==s1){
            p(len);
            return 0;
        }
    }    
    return 0;
}

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

ll MOD=1000000007;

signed main() {
	llin(n);
	vll a(n);
	vll b(n);
	vpl4 c(n);
	FOR(i,0,n-1){
		cin >>a[i];
		cin >>b[i];
		c[i].se=i;
		c[i].fi=a[i]+b[i];
	}
	rSORT(c);
	ll t=0;
	ll u=0;
	while(t<n){
		u+=a[c[t].se];
		t++;
		if(t==n) break;
		u-=b[c[t].se];
		t++;
	}
	sal(u);
}


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

template <typename T>
vector<T>& operator += (vector<T>& a, vector<T> b) {
	for (auto x : b) {
		a.push_back(x);
	}
	return a;
}
template <typename T>
vector<T> operator ~ (vector<T> a) {
  reverse(a.begin(), a.end());
  return a;
}

typedef class Point {
  public:
    int x, y;

    Point() { }
    Point(int x, int y) : x(x), y(y) {  }

    bool operator == (Point b) {
      return x == b.x && y == b.y;
    }
} Point;

typedef class Data {
  public:
    char dir;
    int num;

    Data() {  }
    Data(char dir, int num) : dir(dir), num(num) {  }
} Data;

int n, N;

vector<Point> _export(vector<Data> vd) {
  vector<Point> ret {Point(n, 1)};
  for (auto t : vd) {
    auto lst = ret.back();
    if (t.dir == 'd' && lst.y == 1) {
      ret.emplace_back(lst.x, 0);
    } else if (t.dir == 'u' && lst.y == 0) {
      ret.emplace_back(lst.x, 1);
    }
    lst = ret.back();
    if (lst.x == t.num) {
      lst.x--;
    } else if (lst.x == t.num - 1) {
      lst.x++;
    } else {
      assert(false);
    }
    ret.push_back(lst);
  }
  if (ret[0] == ret.back()) {
    ret.pop_back();
  }
  return ret;
}
vector<Point> _export(vector<Data> vd, vector<int> pos) {
  for (auto& t : vd) {
    t.num = pos[t.num - 1] + 1;
  }
  vector<Data> nvd;
  for (int i = n; i > vd[0].num; i--) {
      nvd.emplace_back('d', i);
  }
  for (auto t : vd) {
    if (!nvd.empty()) {
      auto& lst = nvd.back();
      for (int i = lst.num + 1; i < t.num; i++) {
        nvd.emplace_back('d', i);
      }
      for (int i = lst.num - 1; i > t.num; i--) {
        nvd.emplace_back('d', i);
      }
    }
    nvd.push_back(t);
  }
  for (int i = nvd.back().num + 1; i <= n; i++) {
    nvd.emplace_back('d', i);
  }
  return _export(nvd);
}

char A[530];
vector<Data> df[10];

#define NO do puts("Impossible"), exit(0); while (0)

int main() {
  scanf("%d", &n);
  N = 1 << n;
  scanf("%s", A);
  if (A[0] != '1') {
    NO;
  }
	for (int s = 0; s < N; s++) {
    if (A[s] == '1') {
      for (int i = 0; i < n; i++) {
        if (((s >> i) & 1) && A[s ^ (1 << i)] == '0') {
          NO;
        }
      }
    }
  }
  df[1].emplace_back('d', 1);
  df[1].emplace_back('u', 1);
  for (int i = 2; i <= n; i++) {
    df[i].emplace_back('u', i);
    df[i] += df[i - 1];
    df[i].emplace_back('u', i);
    df[i].emplace_back('d', i);
    df[i] += ~df[i - 1];
    df[i].emplace_back('d', i);
  }
  vector<Point> ans;
  for (int s = 1; s < N; s++) {
    if (A[s] == '0') {
      vector<int> pos;
      int bit = 0;
      for (int i = 0; i < n; i++) {
        if ((s >> i) & 1) {
          pos.push_back(i);
          bit++;
        }
      }
      ans += _export(df[bit], pos);
    }
  }
  puts("Possible");
  printf("%d\n", (signed) ans.size());
  if (ans.empty()) {
    ans.emplace_back(0, 0);
  } else {
    ans.push_back(ans[0]);
  }
  for (auto p : ans) {
    printf("%d %d\n", p.x, p.y);
  }
  return 0;
}


Measured memory_bytes: 904
#![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);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let (s, t): (String, String) = read();
    if s < t {
        println!("<");
    } else if s > t {
        println!(">");
    } else {
        println!("=");
    }
}


Measured memory_bytes: 4352
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int[][] A = new int[3][3];
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				A[i][j] = sc.nextInt();
            }
        }
		int N = sc.nextInt();
		//int[] B = new int[N];
		for(int i=0; i<N; i++){
			int b = sc.nextInt();
			for(int j=0; j<3; j++){
				for(int k=0; k<3; k++){
					if(b == A[j][k]){
						A[j][k] = 0;
						break;
                    }
				}
			}
        }

		if(A[0][0]==0){
			if(A[0][1]==0&&A[0][2]==0){
				System.out.println("Yes");
				return;
			}else if(A[1][1]==0&&A[2][2]==0){
				System.out.println("Yes");
				return;
			}else if(A[1][0]==0&&A[2][0]==0){
				System.out.println("Yes");
				return;
			}
		}else if(A[0][1]==0&&A[1][1]==0&&A[2][1]==0){
			System.out.println("Yes");
				return;
		}else if(A[1][0]==0&&A[1][1]==0&&A[1][2]==0){
			System.out.println("Yes");
				return;
		}else if(A[0][2]==0&&A[1][1]==0&&A[2][0]==0){
			System.out.println("Yes");
				return;
		}else if(A[2][2]==0){
			if(A[2][1]==0&&A[2][0]==0){
				System.out.println("Yes");
				return;
			}else if(A[1][2]==0&&A[0][2]==0){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  int a,b,t;
  cin >> a >> b >> t;
  cout << (t/a)*b << endl;
}

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

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    int total = 0;
    int a[n]; for (auto &ai:a) {
        cin >> ai;
        total ^= ai;
    }
    for (auto &ai:a) {
        cout << (ai ^ total) << ' ';
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 4364
#include<iostream>
#include<algorithm>
#include<cstdio>

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

using namespace std;

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
char grid[12][12];

void rec(int x,int y){
	grid[y][x]='0';
	
	rep(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0 || ny<0 || 12<=nx || 12<=ny || grid[ny][nx]=='0')continue;
		rec(nx,ny);
	}
}

int main(void){
	
	while(true){
		rep(i,12)rep(j,12)if(scanf(" %c",&grid[i][j])==EOF)return 0;
		
		int ans=0;
		rep(i,12)rep(j,12)
			if(grid[i][j]=='1')rec(j,i),ans++;
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1156
import statistics
n = int(input())
a = []
b = []

for i in range(n):
    p,q = map(int,input().split())
    a.append(p)
    b.append(q)

med_a = statistics.median(a)
med_b = statistics.median(b)

if n % 2 == 1:
    print(abs(med_b - med_a) + 1)
if n % 2 == 0:
    print(int(abs(2 * med_b - 2 * med_a) + 1))

Measured memory_bytes: 28864
#include<iostream>
using namespace std;
int main(){
    int l_1, l_2, r_1, r_2;
    cin>>l_1>>l_2>>r_1>>r_2;
    if (l_1+l_2>r_1+r_2)
        cout<<"Left\n";
    else if(l_1 +l_2==r_1+r_2) cout<<"Balanced\n";
    else cout<<"Right\n";
    return 0;
}

Measured memory_bytes: 256
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import  java.io.*;
import  java.math.*;
import java.nio.Buffer;
import java.sql.SQLSyntaxErrorException;
import  java.util.*;
import  java.text.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class Main {
    public static boolean gcd(int a,int b){
        if(a==1||b==1){
            return false;
        }
        while(1>0){
            int t = a%b;
            if(t == 0){
                break;
            }
            else{
                a=b;
                b=t;
            }

        }
        if(b>1)	return true;
        else{
            return  false;
        }
    }
    static class kNight implements Comparable<kNight>{
        int p;
        int c;
        kNight(int p,int c){
            this.p=p;
            this.c=c;
        }
        @Override
        public int compareTo(kNight k) {
            if(p==k.p){
                return c-k.c;
            }
            else{
                return p-k.p;
            }
        }


    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) {
        FastReader cin=new FastReader();
        long n=cin.nextLong();
        long sum=0;
        for(long i=1;i<=n;i++){
            if(i%3==0||i%5==0){
                continue;
            }
            sum+=i;
        }
        System.out.println(sum);

    }
}


Measured memory_bytes: 32864
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int R[MAX], N;

main(){
  cin >> N;
  for (int i = 0; i < N; i++ ) cin >> R[i];
  
  int minv =R[0];
  int ans =-2000000000;

  for ( int i=1; i<N; i++ ){
    ans = max(ans, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1940
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int i;
        int num[] = new int[w];
        for(i=0;i<w;i++){
            num[i] = i+1;
        }
        for(i=0;i<n;i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]);
            int b = Integer.parseInt(ab[1]);
            int r = num[a-1];
            num[a-1] = num[b-1];
            num[b-1] = r;
        }
        for(i=0;i<w;i++){
            System.out.println(num[i]);
        }
    }
}



Measured memory_bytes: 26068
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    lt = []
    for _ in range(n):
        a, b = rli()
        lt.append((b, a))
    t = 0
    lt.sort()
    for b, a in lt:
        t += a
        if t > b:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 29416
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

// 区間加算に対応しないBIT
// 1 originなので注意!!
class BitSimple
{
private:
    int m_n;
    vector<int> m_bit;
    
public:
    void init(int n) {
        m_n = n;
        m_bit.resize(n + 1);
    }

    // 要素1から要素iまでの和
    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += m_bit[i];
            i -= i & -i;
        }
        return s;
    }
    
    void add(int i, int x) {
        while (i <= m_n) {
            m_bit[i] += x;
            i += i & -i;
        }
    }
};

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    string S;
    cin >> N;
    cin >> S;

    vector<BitSimple> bits(26);
    for(auto& bit: bits) {
        bit.init(N + 10);
    }

    REP(i, N) {
        auto idx = S[i] - 'a';
        bits[idx].add(i + 1, 1);
    }

    int Q;
    cin >> Q;
    REP(q, Q) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char ch_after;
            cin >> i >> ch_after;
            char ch_before = S[i - 1];

            bits[ch_after - 'a'].add(i, 1);
            bits[ch_before - 'a'].add(i, -1);
            S[i - 1] = ch_after;  // 忘れていた
        }
        else {
            int l, r;
            cin >> l >> r;
            ll sum = 0;
            REP(ch_idx, 26) {
                auto tmp = bits[ch_idx].sum(r) - bits[ch_idx].sum(l - 1);
                sum += (tmp > 0);
            }
            cout << sum << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 53788
#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <tuple>
#include <vector>
#include <map>

using namespace std;
using tii = tuple<int, int>;

#ifdef NDEBUG
#  define debug(...)
#else
#  include "debug.hh"
#endif

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  map<int, int> c[2];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    c[i%2][v]++;
  }
  vector<pair<int, int>> f0(c[0].begin(), c[0].end()), f1(c[1].begin(), c[1].end());
  auto greater_by_count = [](pair<int, int> & x, pair<int, int> & y) {
    return x.second > y.second;
  };
  sort(f0.begin(), f0.end(), greater_by_count);
  sort(f1.begin(), f1.end(), greater_by_count);
  debug(f0);
  debug(f1);
  int ans;
  if (f0[0].first != f1[0].first) {
    ans = f0[0].second + f1[0].second;
  } else {
    int ans0 = f0[0].second + (f1.size() > 1 ? f1[1].second : 0);
    int ans1 = f1[0].second + (f0.size() > 1 ? f0[1].second : 0);
    ans = max(ans0, ans1);
  }
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 5760
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int N = scan.nextInt();
                
                int[] c = new int[N+1];
                
                for(int i=0; i<=N; i++){
                    c[i]=0;
                }
                
                for(long x=1; x<=100; x++){
                    for(long y=1; y<=100; y++){
                        for(long z=1; z<=100; z++){
                            long n = x*x+y*y+z*z+x*y+y*z+z*x;
                            
                            if(n<=N){
                                int p = (int)n;
                                c[p]++;
                            }
                        }
                    }
                }
                for(int i=1; i<=N; i++){
                    System.out.println(c[i]);
                }
        }               
}

Measured memory_bytes: 38820
#include<iostream>
#include<utility>
#include<queue>

using namespace std;

typedef struct
{
	int x;
	int y;
}Point;

const Point DIRE4[4] = {
	{0, -1},
	{-1, 0},
	{0, 1},
	{1, 0}
};

char field[100][101];
int H, W;
int ans = 0;

void draw(int x, int y)
{
	char target = field[y][x];
	field[y][x] = '0';
	
	queue<Point> pointQ;
	
	Point center = {x, y};
	pointQ.push(center);
	
	while(!pointQ.empty())
	{
		Point p = pointQ.front();
		pointQ.pop();
		
		for(int i = 0;i < 4;i++)
		{
			int tx = p.x + DIRE4[i].x;
			int ty = p.y + DIRE4[i].y;
			
			if(0 <= tx && tx < W && 0 <= ty && ty < H && target == field[ty][tx])
			{
				field[ty][tx] = '0';
				
				Point set = {tx, ty};
				pointQ.push(set);
			}
		}
	}
}

int main()
{
	while(1)
	{
		ans = 0;
		
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int y = 0;y < H;y++)
		{
			cin >> field[y];
		}
		
		for(int y = 0;y < H;y++)
		{
			for(int x = 0;x < W;x++)
			{
				if(field[y][x] != '0')
				{
					draw(x, y);
					ans++;
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,x,m;
    cin >> n >> x >> m;
    ll t=x,ans=0,sum=0,cnt=0;
    vector<ll> p;
    vector<int> id(m,-1);
    while(1){
        if(id[t]==0){
            break;
        }
        id[t]=0;
        ans+=t;
        --n;
        if(n==0){
            cout << ans << "\n";
            return 0;
        }
        p.push_back(t);
        t=(t*t)%m;
    }
    bool go=false;
    int s=0;
    for(auto u:p){
        if(u==t) go=true;
        if(go){
            ++cnt;
            sum+=u;
        }else{
            ++s;
        }
    }
    ans+=(n/cnt)*sum;
    int y=n%cnt;
    rep(i,y){
        ans+=p[i+s];
    }
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 4244
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            if (input.Equals("ABC"))
            {
                Console.WriteLine("ARC");
                return;
            }

            Console.WriteLine("ABC");
        }
    }
}


Measured memory_bytes: 25680
import java.util.Scanner;

import java.util.*;

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

		String n  = scan.next();

		List<Boolean> l = new ArrayList<>();

		int t = 0;
		int f = 0;
		for(int i = 0; i < n.length() ; i++){
			//l.add(new Boolean(n.charAt(i) == '0'));
			if(n.charAt(i) == '0'){
				t++;
			}else{
				f++;
			}
		}
		if(t < f) {
			System.out.println(t*2);
		}else{
			System.out.println(f*2);
		}

		// int remove = 0;
		// while(true){
		// 	int ret = remove(l);
		// 	if(ret == 0){
		// 		System.out.println(remove);
		// 		return;
		// 	}else{
		// 		remove += ret;
		// 	}
		// }
	}


	static int remove(List<Boolean> l){
		Boolean p = null;
		int ret = 0;
		for(int i = 0 ; i < l.size(); i++){
			Boolean c = l.get(i);
			if(p != null && p.booleanValue() != c.booleanValue()){
				l.remove(i);
				l.remove(i-1);
				ret += 2;
				p = null;
			}else{
				p = c;
			}
		}
		return ret;
		
	}

}


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

int main(){
    long double w, h, x, y;
    cin >> w >> h >> x >> y;

    int multi = 0;
    if(x == w / 2.0 && y == h / 2.0){
        multi = 1;
    }

    cout << fixed << setprecision(10) << w * h / 2.0 << " " << multi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,ans,flag,len;
int bgn[N],nxt[N<<1],to[N<<1],E;
int dp[N],f[N],dis[N];
multiset<int>G[N];
multiset<int>::iterator gt,gtt;
inline void add_edge(int u,int v){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;}
inline void dfs(int u,int f)
{
	int son=0;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		dfs(v,u);
		son++;
		dp[u]+=dp[v];
	}
	dp[u]+=(son+(u==1))/2;
}
inline int dfs_ans(int u,int f)
{
	int son=0;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		int x=dfs_ans(v,u)+1;
		G[u].insert(x);
		if(!x)flag=0;
		if(x>len)flag=0;
		if(!flag)return 0;
		son++;
	}
	int res=u==1?son&1:son&1?1:2;
	//printf("%d %d\n",u,res);
	while(!G[u].empty())
	{
		gt=G[u].end();--gt;
		gtt=G[u].upper_bound(len-*gt);
		if(gtt==G[u].begin()||SZ(G[u])==1)
		{
			if(!res){flag=0;return 0;}
			dis[u]=*gt;
			res--;
			G[u].erase(gt);
			continue;
		}
		--gtt;
		if(gt==gtt)gtt--;
		G[u].erase(gtt);
		gt=G[u].end();--gt;
		G[u].erase(gt);
	}
	return dis[u];
}
inline bool check(int x)
{
	//printf("%d:\n",x);
	For(i,1,n){G[i].clear();dis[i]=0;}
	flag=1;
	len=x;
	dfs_ans(1,0);
	return flag;
}
int main()
{
	int x,y;
	read(n);
	For(i,2,n)
	{
		read(x),read(y);
		add_edge(x,y),add_edge(y,x);
	}
	dfs(1,0);
	int l=1,r=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d %d\n",dp[1],ans);
	return 0;
}


Measured memory_bytes: 14592
n,m=map(int,input().split())
e=[[] for _ in range(n+1)]
eab=[]
for i in range(m):
    a,b=map(int,input().split())
    e[a].append(b)
    e[b].append(a)
    eab.append([a,b])

def dfs(used,count,v):

    used[v]=True
    c=count+1
    ev=e[v]
    for ei in ev:
        if(used[ei]):
            continue
        else:
            c=dfs(used,c,ei)
    return c

ans=0
for i in range(m):
    a,b=eab[i]
    e[a].remove(b)
    e[b].remove(a)
    ci=dfs([False for _ in range(n+1)],0,1)
    if(ci!=n):
        ans+=1
    e[a].append(b)
    e[b].append(a)
print(ans)


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

ll dp[110][10];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll h,w,k,mod=1e9+7;
    cin>>h>>w>>k;
    vector<ll>combi{1,1,1,2,3,5,8,13,21};

    
    dp[0][1]=1;
    rep(i,h+1){
        forx(j,1,w+1){
            dp[i][j]%=mod;

            dp[i+1][j]+=dp[i][j]*combi[j]*combi[w+1-j];
            dp[i+1][j-1]+=dp[i][j]*combi[j-1]*combi[w+1-j];
            dp[i+1][j+1]+=dp[i][j]*combi[j]*combi[w-j];

            dp[i+1][j]%=mod;
            dp[i+1][j-1]%=mod;
            dp[i+1][j+1]%=mod;
        }
    }

    cout<<dp[h][k]<<endl;

    return 0;
}


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

int d[31][31];
int cij[500][500];
int sum[3][31];

int main() {
	int n, c;
	cin >> n >> c;
	for (int i = 1;i <= c;i++) {
		for (int j = 1;j <= c;j++) {
			cin >> d[i][j];
		}
	}
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			cin >> cij[i][j];
		}
	}

	for (int i = 0;i < 3;i++) {
		for (int j = 1;j <= c;j++) {
			sum[i][j] = 0;
		}
	}
	for (int j = 1;j <= c;j++) {
		for (int x = 0;x < n;x++) {
			for (int y = 0;y < n;y++) {
				sum[(x+y+2)%3][j] += d[cij[x][y]][j];
			}
		}
	}

	int ans = 1000000000;
	for (int i = 1;i <= c;i++) {
		for (int j = 1;j <= c;j++) {
			if (j == i)
				continue;
			for (int k = 1;k <= c;k++) {
				if (k == j || k == i)
					continue;
				ans = min(ans, sum[0][i] + sum[1][j] + sum[2][k]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define BR "\n"
#define SP " "

int main() {

  while(1) {
    ll H, W;
    cin >> H >> W;

    if (H + W == 0) break;

    string s = "";
    for (int i = 0; i < W; i++) {
      s += "#";
    }
    for (int i = 0; i < H; i++) {
      cout << s << BR;
    }
    cout << BR;
  }

  return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},dp[257][257];
		char map[257][257];
		for(int y=0;y<257;y++){
			for(int x=0;x<257;x++){
				map[x][y] = '0';
			}
		}
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				cin >> map[x][y];
			}
		}

		for(int i=0;i<4;i++){
			memset(dp,0,sizeof(dp));
			//cout << "--------------------" << endl;//Test
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k]-'0'?map[j][k] - '0' + dp[j+v[i][0]][k+v[i][1]]:0;
					//cout << dp[j][k];//Test
					m = max(m,dp[j][k]);
				}
				//cout << endl;//Test
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1188
#include <stdio.h>
int main(void)
{
    int n;
    scanf("%d",&n);

    int mim_count['z' - 'a' + 1];

    for (int i = 0; i < n; i++){
        char str[51];
        scanf("\n%s",str);
        int count['z'-'a' + 1] = {0};
        for (char *ch = str; *ch; ch++){
            count[*ch - 'a']++;
        }

        if(i == 0){
            for (int j = 0; j <= 'z' - 'a'; j++){
                mim_count[j] = count[j];
            }
        } else {
            for (int j = 0; j <= 'z' - 'a'; j++){
                mim_count[j] = (mim_count[j] < count[j]) ? mim_count[j] : count[j];
            }
        }
    }

    for (int j = 0; j <= 'z' - 'a'; j++){
        for (int i = 0; i < mim_count[j]; i++) {
            printf("%c",'a' + j);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    fast
    int n;
    cin>>n;

    vector<int>arr(n);

    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(arr[i]==arr[j] || arr[j]==arr[k] || arr[i]==arr[k])continue;
                if(arr[i]+arr[j]>arr[k] && arr[j]+arr[k]>arr[i] && arr[i]+arr[k]>arr[j]){
                    ans++;
                }
            }
        }
    }
    cout<<ans;


    return 0;
}



Measured memory_bytes: 3656
#include<stdio.h>
#include<limits.h>
#define min(rhs,lhs) ((rhs)<(lhs)?(rhs):(lhs))

typedef struct{
    long f,s;
    long long t;
}three;

static inline void swap(three *rhs,three *lhs){
    three tmp = *rhs;
    *rhs = *lhs;
    *lhs = tmp;
}

three pq[1000000]; //pq[0].f == length

static inline void pqinsert(three elem){
    pq[0].f++;
    pq[pq[0].f] = elem;
    long i = pq[0].f;
    while(i/2){
        if(pq[i].t < pq[i/2].t)swap(&pq[i],&pq[i/2]);
        i/=2;
    }
}

static inline three pqpop(){
    three ret = pq[1];
    pq[1].t = LLONG_MAX;
    swap(&pq[1],&pq[pq[0].f]);
    pq[0].f--;
    long mi,i = 1;
    while(i*2+1 <= pq[0].f+1){
        mi = pq[i*2].t > pq[i*2+1].t ? i*2+1 : i*2; 
        if(pq[mi].t < pq[i].t)swap(&pq[mi],&pq[i]);
        i = mi;
    }
    return ret;
}

int main(void){
    register long i,j;
    int n,m,tu,tv;
    long s,ta,tb;
    scanf("%d%d%ld",&n,&m,&s);
    static three train[50][49];
    static int trarp[50];
    for(i = 0;i < m;i++){
        scanf("%d%d%ld%ld",&tu,&tv,&ta,&tb);
        tu--; tv--;
        train[tu][trarp[tu]] = (three){tv,ta,tb};
        train[tv][trarp[tv]] = (three){tu,ta,tb};
        trarp[tu]++;
        trarp[tv]++;
    }
    static long excm[50],exct[50];
    for(i = 0;i < n;i++)scanf("%ld%ld",&excm[i],&exct[i]);

    static long long dp[50][2501];

    for(i = 0;i < 50;i++)for(j = 0;j <= 2500;j++)dp[i][j] = LLONG_MAX;
    for(i = 1;i < 100000;i++)pq[i] = (three){0,0,LLONG_MAX};
    s = min(s,2500);
    pqinsert((three){0,s,0}); //(city,money,time)

    while(pq[0].f){
        three cur = pqpop();
        if(dp[cur.f][cur.s] <= cur.t)continue;
        dp[cur.f][cur.s] = cur.t;

        for(i = 0;i < trarp[cur.f];i++)if(train[cur.f][i].s <= cur.s) //linked city
            pqinsert((three){train[cur.f][i].f,cur.s - train[cur.f][i].s,cur.t + train[cur.f][i].t});

        if(cur.s == 2500)continue;
        pqinsert((three){cur.f,min(cur.s + excm[cur.f],2500),cur.t + exct[cur.f]});
    }
    static long long mins[50];
    for(i = 0;i < n;i++)mins[i] = LLONG_MAX;
    for(i = 1;i < n;i++)for(j = 0;j < 2501;j++)mins[i] = min(dp[i][j],mins[i]);
    for(i = 1;i < n;i++)printf("%lld\n",mins[i]);
}

Measured memory_bytes: 8804
fun main(args: Array<String>) {
    val binaryTree = BinaryTree<Int>()
    repeat(readLine()?.toInt() ?: 0) {
        val input = readLine()?.split(" ".toRegex()) ?: return@repeat
        when (input[0]) {
            "insert" -> binaryTree.insert(input[1].toInt())
            "print" -> binaryTree.printTree()
        }
    }
}

class BinaryTree<T: Comparable<T>> {
    private var root: Node? = null

    fun insert(key: T) {
        val newNode = Node(key)
        var x = root
        var y = x?.parent
        while (x != null) {
            y = x
            x = if (key < x.key) {
                x.leftChild
            } else {
                x.rightChild
            }
        }
        newNode.parent = y
        when {
            y == null -> root = newNode
            key < y.key -> y.leftChild = newNode
            else -> y.rightChild = newNode
        }
    }

    fun printTree() {
        println(inorderTreeWalk())
        println(preorderTreeWalk())
    }

    private fun inorderTreeWalk(): String {
        val root = this.root ?: return ""
        return inorderTreeWalk(root)
    }

    private fun inorderTreeWalk(node: Node): String {
        val resultBuilder = StringBuilder()
        if (node.leftChild != null) {
            resultBuilder.append(inorderTreeWalk(node.leftChild!!))
        }
        resultBuilder.append(" ")
        resultBuilder.append(node.key)
        if (node.rightChild != null) {
            resultBuilder.append(inorderTreeWalk(node.rightChild!!))
        }
        return resultBuilder.toString()
    }

    private fun preorderTreeWalk(): String {
        val root = this.root ?: return ""
        return preorderTreeWalk(root)
    }

    private fun preorderTreeWalk(node: Node): String {
        val resultBuilder = StringBuilder()
        resultBuilder.append(" ")
        resultBuilder.append(node.key)
        if (node.leftChild != null) {
            resultBuilder.append(preorderTreeWalk(node.leftChild!!))
        }
        if (node.rightChild != null) {
            resultBuilder.append(preorderTreeWalk(node.rightChild!!))
        }
        return resultBuilder.toString()
    }

    inner class Node(val key: T) {
        var parent: Node? = null
        var leftChild: Node? = null
        var rightChild: Node? = null
    }
}


Measured memory_bytes: 603612
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num=new int[10];
		for(int i=0; i<N; i++){
			int l=0;
			int r=0;
			boolean flag=true;
			for(int j=0; j<10; j++){
				num[j]=sc.nextInt();
			}
			for(int j=0; j<10; j++){
				if(l<num[j]){
					l=num[j];
				}else if(r<num[j]){
					r=num[j];
				}else{
					flag=false;
					break;
				}
			}
			if(flag)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 16296
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a != 1 && b != 1) cout << 1;
  else if(a != 2 && b != 2) cout << 2;
  else cout << 3;
  
  return 0;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A == B)
        cout << C << endl;
    else if(B == C)
        cout << A << endl;
    else if(A == C)
        cout << B << endl;

}

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

int main() {
		vector<int> v;
		for(int i = 0; i < 3; i++) {
			int temp;
			cin >> temp;
			v.push_back(temp);
		}
		sort(v.begin(), v.end());
		if(v[0] == v[1] && v[1] != v[2]) {
			cout << "Yes";
		} else if(v[1] == v[2] && v[0] != v[1] ) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int a = in.nextInt()
				,b = in.nextInt()
				,c = in.nextInt();
		int x;
		x = a>=b ? a : b;
		x = x < c ? c : x;
		System.out.println(a+b+c-x);
	}

}


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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int>A(N);
    int sum=0;
    rep(i,N){
        cin>>A.at(i);
        sum+=A.at(i);
    }
    int ans=0;
    rep(i,N){
        if(A.at(i)<sum/(4.0*M)){

        }else{
            ans++;
        }
    }
    if(ans>=M){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
def main():
    footing = int(input())
    height = list(map(int, input().split()))
    answer = [0] * footing
    answer[1] = abs(height[1] - height[0])
    for i in range(2, footing):
        answer[i] = min(answer[i - 2] + abs(height[i] - height[i - 2]), answer[i - 1] + abs(height[i] - height[i - 1]))
    print(answer[-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 13928
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 a[600][600];
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};

void solve() {
	int n;
    while(cin >> n) {
        if(n == 0) break;
        vector<P> pos(n, {-1, -1});
        pos[0] = P{300, 300};
        rep(i, 600) {
            rep(j, 600) {
                a[i][j] = -1;
            }
        }
        a[300][300] = 0;
        rep(i, n - 1) {
            int m, d; cin >> m >> d;
            a[pos[m].fr + dx[d]][pos[m].sc + dy[d]] = i + 1;
            pos[i + 1] = P{pos[m].fr + dx[d], pos[m].sc + dy[d]};
        }
        int xmi = inf, xma = -inf, ymi = inf, yma = -inf;
        rep(i, 600) {
            rep(j, 600) {
                if(a[i][j] != -1) {
                    chmax(xma, i); chmin(xmi, i);
                    chmax(yma, j), chmin(ymi, j);
                }
            }
        }
        cout << yma - ymi + 1 << " " << xma - xmi + 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 4560
k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
for i in range(len(a)):
    if i+1 == k:
        print(a[i])
    

Measured memory_bytes: 3060