akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
   int a,b,c;
   cin >>a>>b>>c;
   if(a <= b && b <= c)
        cout <<a<<" "<<b<<" "<<c<<endl;
   else if(c <= b && b <= a)
        cout <<c<<" "<<b<<" "<<a<<endl;
   else if(b <= c && c <= a)
        cout <<b<<" "<<c<<" "<<a<<endl;
   else if(b <= a && a <= c)
        cout <<b<<" "<<a<<" "<<c<<endl;
    else if(c <= a && a <= b)
        cout <<c<<" "<<a<<" "<<b<<endl;
    else if(a <= c && c <= b)
        cout <<a<<" "<<c<<" "<<b<<endl;
}




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

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
#define pii pair<int,int> 
#define mii map<int,int>
#define vi vector<int>
#define umii unordered_map<int,int>
#define mod 998244353
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

#define repo(i,o,e) for(int i = o ; i < e ; i++)
#define rep(n) for(int i = 0 ; i < n ; i++)
const ll sz = 1e5+5;
//C'mon
void solve(){
	char c;cin >> c;
	if(c == 'A')cout << 'T';
	else if(c == 'T')cout << 'A';
	else if(c == 'C') cout << 'G';
	else cout << 'C';
}

int main(){
    FIO;
    int t = 1;
	//cin >> t;
    while(t--){
        solve();
    }
    cout << endl << endl;
    return 0;
}


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

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();}
template<class T> inline T sqr(T x) {return x*x;}

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 pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int k[110];
char seq[52];

int main(void){
	rep(i,26) seq[i]=('a'+i),seq[i+26]=('A'+i);
	int n;
	while(cin >> n){
		if(n==0)
			break;
		rep(i,n) cin >> k[i];
		string s;
		cin >> s;
		rep(i,s.size()){
			int cur;
			for(cur=0;cur<52;++cur)
				if(s[i]==seq[cur])
					break;
			cur=(cur-k[i%n]+52)%52;
			s[i]=seq[cur];
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;
int A,B,C,K;

void input(){
	cin>>A>>B>>C>>K;
}

int main(){

	input();

	if(A>=K){
		cout<<K<<endl;
	}
	if(A<K&&K<=A+B){
		cout<<A<<endl;
	}
	if(A+B<K){
		cout<<2*A+B-K<<endl;
	}
}


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

int main(){
    int n;cin>>n;
    int k;cin>>k;
    int arr[n];

    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }

    int r=0;
    for(int i=0;i<n;i++){
        r += min(vec.at(i)*2,(k-vec.at(i))*2);
    }

    cout << r << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>

#define true (1)
#define false (0)

int prime_number(int);
int main(void)
{
    int n,a;
    int i;
    int sum;

    sum = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &a);
        sum +=prime_number(a);
    }
    printf("%d\n", sum);

    return (0);
}
int prime_number(int a){
    int i,j;

    if (a == 2){
        return true;
    }else if (a < 2 || a % 2 == 0){
        return false;
    }else{
        i = 3;
        while (i <= sqrt((double)a)){
            if (a % i == 0){
                return false;
            }
            i = i + 2;
        }
    }
    return true;
}


Measured memory_bytes: 2036
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vi v(n, k);
    int x;
    map<int, int> a;
    for(int i = 0; i < q; i++){
        cin >> x;
        a[x]++; 
    }
    vi b;
    vi c;
    map<int, int> :: iterator it;
    for(it=a.begin(); it!=a.end(); it++){
            c.pb(it->first);
            b.pb(it->second);
    }
    for(int i = 0; i < b.size(); i++){
        v[c[i]-1]+=b[i];
    }
    for(int i = 0; i < v.size(); i++){
        v[i]-=q;
    }
    for(int i = 0; i < v.size(); i++){
        if(v[i]<=0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    ll n;
    cin >> n;

    vector<pair<ll, int>> primes;
    ll t = n;
    for (ll i = 2; i * i <= t; i++) {
        int cnt = 0;
        while (t % i == 0) {
            cnt++;
            t /= i;
        }
        if (cnt) primes.eb(i, cnt);
    }
    if (t != 1) primes.eb(t, 1);

    int cnt = 0;
    function<void(int, ll)> solve = [&](int i, ll cur) {
        if (i != sz(primes)) {
            ll a = 1;
            rep(j, primes[i].se + 1) {
                solve(i + 1, cur * a);
                a *= primes[i].fi;
            }
        } else if (cur != 1) {
            ll n1 = n;
            while (n1 % cur == 0) n1 /= cur;
            if ((n1 - 1) % cur == 0) cnt++;
        }
    };
    solve(0, 1);

    vector<pair<ll, int>> primes2;
    ll t2 = n - 1;
    for (ll i = 2; i * i <= t2; i++) {
        int cnt = 0;
        while (t2 % i == 0) {
            cnt++;
            t2 /= i;
        }
        if (cnt) primes2.eb(i, cnt);
    }
    if (t2 != 1) primes2.eb(t2, 1);

    ll cur = 1;
    for (auto& i : primes2) {
        cur *= i.se + 1;
    }
    cnt += cur - 1;

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define LL long long
#define INF 1e18
#define MAXN 100005
 
LL min(LL x, LL y) {if(x<y) return x; return y;}
 
int n, m, s, t, u, v;
LL a, b, f=1e15, ans[MAXN];
 
struct Graph
{
	int cnt, head[MAXN], vis[MAXN];
	LL dis[MAXN];
	
	struct Edge {int next, to; LL dis;} edge[MAXN*2];
	
	std::queue<int> q;
	
	void addedge(int from, int to, LL dis)
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	
	void spfa(int s)
	{
		for(int i=1; i<=n; i++) dis[i]=INF;
		memset(vis, 0, sizeof(vis));
		q.push(s); vis[s]=1; dis[s]=0;
		while(!q.empty())
		{
			int x=q.front(); q.pop();
			vis[x]=0;
			for(int i=head[x]; i; i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>dis[x]+edge[i].dis)
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to]) q.push(to), vis[to]=1;
				}
			}
		}
	}
} g1, g2;
 
int main()
{
	
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i=1; i<=m; i++)//m列车 
	{
		scanf("%d%d%lld%lld", &u, &v, &a, &b);//日元，美元 
		g1.addedge(u, v, a); g1.addedge(v, u, a);
		g2.addedge(v, u, b); g2.addedge(u, v, b);
	}
	g1.spfa(s);  g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n; i>=1; i--) ans[i]=min(ans[i+1], g1.dis[i]+g2.dis[i]);
	for(int i=1; i<=n; i++) printf("%lld\n", f-ans[i]);
}


Measured memory_bytes: 12032
X,Y =input().split()


alphabet =["A","B","C","D","E","F"]
numX = 0
numY = 0
for i in range(6):
    if X == alphabet[i]:
        numX = i
    if Y == alphabet[i]:
        numY = i

if numX > numY:
    print(">")
elif numX == numY:
    print("=")
else:
    print("<")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    string s1;
    int a,b;
    cin>>s>>s1>>a>>b;
    string u;
    cin>>u;
    if(u==s){
        a--;
    }
    else b--;
    cout<<a<<" "<<b;
    
}


Measured memory_bytes: 3656
from operator import itemgetter
n,k=map(int,input().split())
td=[list(map(int,input().split())) for _ in range(n)]
td.sort(key=itemgetter(1),reverse=True)
ans=0
kind=0
flg=[False]*n
sing,comp=[],[]
for i in range(n):
    t,d=td[i]
    t-=1
    if i<k:
        ans+=d
        if flg[t]:
            comp.append(d)
        else:
            flg[t]=True
            kind+=1
    else:
        if not flg[t]:
            sing.append(d)
            flg[t]=True
comp=comp[::-1]
cnt=ans
ans+=kind**2
#print(comp)
#print(sing)
if len(comp)>len(sing):
    for i in range(len(sing)):
        dc,ds=comp[i],sing[i]
        cnt+=ds-dc
        kind+=1
        ans=max(ans,cnt+kind**2)
else:
    for i in range(len(comp)):
        dc,ds=comp[i],sing[i]
        cnt+=ds-dc
        kind+=1
        ans=max(ans,cnt+kind**2)
print(ans)

Measured memory_bytes: 29156
import java.util.*;

public class Main {
	int [][] sumdata;
	int sum,c;
	int [][][][] group, y;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int h = sc.nextInt();
			int w = sc.nextInt();
			c = sc.nextInt();
			if(h == 0 && w == 0 && c == 0) break;
			int [][]data = new int[h][w];
			sumdata = new int[h+2][w+2];
			group = new int[h][w][h][w];
			y = new int[h][w][h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = sc.nextInt();
					sumdata[i+1][j+1] = data[i][j] + sumdata[i][j+1] + sumdata[i+1][j] - sumdata[i][j];
				}
			}
			sum = sumdata[h][w];
			//System.out.println(sum);
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					group[i][j][i][j] = 1;
					y[i][j][i][j] = getY(data[i][j]);
				}
			}
//			for(int i=0; i < h; i++){
//				for(int j = 0; j < w; j++){
//					System.out.printf("%2d ",y[i][j][i][j]);
//				}
//				System.out.println();
//			}

			int [] res = dfs(0,0,w-1,h-1);
			//System.out.print("ANS=");
			System.out.println(res[0] + " " + res[1]);
		}
	}
	private int[] dfs(int sx, int sy, int ex, int ey) {
		int [] res = new int[2];
		if(group [sy][sx][ey][ex] > 0){
			res[0] = group[sy][sx][ey][ex];
			res[1] = y [sy][sx][ey][ex];
			return res;
		}
		res[0] = 1;
		res[1] = getY(getSeg(sx+1,sy+1,ex+1,ey+1));
		for(int i=sy; i < ey; i++){
			//System.out.println("pass2");
			int [] temp = dfs(sx,sy,ex,i);
			int [] temp2 = dfs(sx,i+1,ex,ey);
			if(temp[1] < 0 || temp2[1] < 0) continue;
			int gsum = temp[0] + temp2[0];
			int ysum = Math.min(temp[1],temp2[1]);
			//System.out.println("ygsum= "+gsum + " " + ysum);
			if(res[0] < gsum){
				res[0] = gsum;
				res[1] = ysum;
			}
			else if(res[0] == gsum && res[1] < ysum ){
				res[0] = gsum;
				res[1] = ysum;
			}
		}
		
		for(int i=sx; i < ex; i++){
			//System.out.println("pass1 = " + sx + " " + sy + " " + ex + " " + ey + " i= " + i);
			int [] temp = dfs(sx,sy,i,ey);
			int [] temp2 = dfs(i+1,sy,ex,ey);
			if(temp[1] < 0 || temp2[1] < 0) continue;
			int gsum = temp[0] + temp2[0];
			int ysum = Math.min(temp[1],temp2[1]);
			if(res[0] < gsum){
				res[0] = gsum;
				res[1] = ysum;
			}
			else if(res[0] == gsum && res[1] < ysum ){
				res[0] = gsum;
				res[1] = ysum;
			}
		}
		group[sy][sx][ey][ex] = res[0];
		y[sy][sx][ey][ex] = res[1];
		//System.out.println(res[0] + " " + res[1]);
		return res;
	}
	private int getY(int a) {
		int res = c - (sum - a);
		return res;
	}
	private int getSeg(int sx, int sy, int ex, int ey) {
		int res = sumdata[ey][ex] - sumdata[ey][sx-1] - sumdata[sy-1][ex] + sumdata[sy-1][sx-1];
		return res;
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 28000
#include<bits/stdc++.h>
    using namespace std;
     
int solve(vector<vector<int>> v, int n){
     
           int dp[n+1][4];

           dp[0][0]=0;
           dp[0][1]=0;
           dp[0][2]=0;

           for(int i=1;i<=n;i++){

                dp[i][0]=v[i-1][0]+max(dp[i-1][1],dp[i-1][2]);
                dp[i][1]=v[i-1][1]+max(dp[i-1][0],dp[i-1][2]);
                dp[i][2]=v[i-1][2]+max(dp[i-1][1],dp[i-1][0]);

           }

           return max(dp[n][0],max(dp[n][1],dp[n][2]));

     
        }


    int main() {
        int n;
        cin>>n;
        vector<vector<int>> v;

        for(int i=0;i<n;i++){
     
            vector<int> temp;
     
            int a,b,c;
            cin>>a>>b>>c;
            temp.push_back(a);
            temp.push_back(b);
            temp.push_back(c);
            v.push_back(temp);
     
        }
     
         cout<<solve(v,n);
     
         return 0;
     
    }

Measured memory_bytes: 13232
# coding: utf-8
# Here your code !
n = input()
s = list(str(n))


d = {}
    
def solve(l):
    if len(l) == 1:
        return int(l[0])
    # if str(l) in d:
        # return d[str(l)]
    sum = int("".join(l))
    for i in xrange(1,len(l)):
        # print  l[:i],l[i:]
        # print int("".join(l[:i]))*2**(len(l[i:])-1)
        d[str(l)]= int("".join(l[:i]))*2**(len(l[i:])-1) + solve(l[i:])
        sum += d[str(l)]
    return sum
        
print solve(s)

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

using namespace std;

int main(){
  string S;
  cin >> S;
  
  int n = S.size();
  int K = n;
  
  for(int i = 1; i < n; i++){
    if(S[i] != S[i - 1]) K = min(max(i, n - i), K);
  }
  
  cout << K << endl;
  
  return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Mod = 1e9 + 7

var H, W int
var grid []string

func main() {
	H, W = ReadInt(), ReadInt()
	grid = make([]string, H)
	for i := 0; i < H; i++ {
		grid[i] = ReadString()
	}

	memo = make([][]int, H)
	for i := 0; i < H; i++ {
		memo[i] = make([]int, W)
		for j := 0; j < W; j++ {
			memo[i][j] = -1
		}
	}
	fmt.Println(dfs(0, 0))
}

var memo [][]int

func dfs(i, j int) int {
	if i < 0 || i >= H || j < 0 || j >= W {
		return 0
	}
	if grid[i][j] == '#' {
		return 0
	}
	if i == H-1 && j == W-1 {
		return 1
	}
	if memo[i][j] >= 0 {
		return memo[i][j]
	}
	memo[i][j] = (dfs(i+1, j) + dfs(i, j+1)) % Mod
	return memo[i][j]
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 11664
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i;
   cin>>n;
   double l=0,x;
   double a[n];
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       l=l+1/a[i];
   }
   x=1/l;
   cout<<x;


}


Measured memory_bytes: 256
// CPP program to to find ways to arrange K green 
// balls among N balls such that we need 
// exactly i moves to collect all K green balls 
#include<bits/stdc++.h>
using namespace std; 
#define N 100005
#define mod (int)(1e9+7)

// To store factorial and factorial mod inverse of a number
int factorial[N], modinverse[N];

// Function to find (a ^ m1)%mod
int power(int a,int m1)
{
    if(m1==0)
        return 1;
    else if(m1==1)
        return a;
    else if(m1==2)
        return (1LL*a*a)%mod;
    else if(m1&1)
        return (1LL*a*power(power(a,m1/2),2))%mod;
    else 
        return power(power(a,m1/2),2)%mod;
}

// Function to find factorial of all numbers
void factorialfun()
{
    factorial[0]=1;
    for(int i = 1; i < N; i++)
        factorial[i] = (1LL * factorial[i-1] *i)%mod;
}

// Function to find factorial modinverse of all numbers
void modinversefun()
{
    modinverse[N-1] = power(factorial[N-1], mod-2)%mod;
    
    for(int i = N - 2;i>=0;i--)
        modinverse[i] = (1LL * 
                         modinverse[i+1] * (i+1))%mod;
}

// Function to find nCr
int binomial(int n,int r)
{
    if(r>n)
        return 0;

    int a = (1LL * factorial[n] * 
                         modinverse[n-r]) % mod;
        
    a = (1LL* a * modinverse[r]) % mod;
    return a;
}

// Function to find ways to arrange K green 
// balls among N balls such that we need 
// exactly i moves to collect all K green balls 
void arrange_balls(int n, int k)
{
    factorialfun();
    modinversefun();
    
    for(int i = 1; i <= k; i++)
        cout << (1LL * binomial(n - k + 1, i) * 
                   binomial(k - 1, i - 1)) % mod << endl;
}

// Driver code
int main()
{
    int n = 100, k = 5;
    cin >> n >> k;
    
    // Function call
    arrange_balls(n, k);

    return 0;
}

Measured memory_bytes: 1024
n, x, y = map(int, input().split())
ans = {x: 0 for x in range(1, n)}

for i in range(1, n):
    for j in range(i+1, n+1):
        res = min((j-i, abs(x-i)+1+abs(j-y)))
        ans[res] += 1

for v in ans.values():
    print(v)


Measured memory_bytes: 3700
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

ll N, K;
string S;

ll sum = 0;

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> X(x), Y(y), Z(z);
    REP(i, x)cin >> X[i];
    REP(i, y)cin >> Y[i];
    REP(i, z)cin >> Z[i];
    sort(X.begin(), X.end(), greater<ll>());
    sort(Y.begin(), Y.end(), greater<ll>());
    sort(Z.begin(), Z.end(), greater<ll>());
    priority_queue<ll> Q;
    REP(i, x)
        REP(j, y)
            REP(l, z) {
                if ((i + 1) * (j + 1) * (l + 1) <= k)Q.push(X[i] + Y[j] + Z[l]);
                else break;
            }
    REP(i, k) {
        if (!Q.empty()) {
            cout << Q.top() << endl;
            Q.pop();
        }
    }
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 1404
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int a[3];
	rep (i, 3) cin >> a[i];

	sort(a, a + 3);

	int ans = 0;
	while (a[0] < a[2] - 1) {
		a[0] += 2;
		ans++;
	}

	while (a[1] < a[2] - 1) {
		a[1] += 2;
		ans++;
	}

	if (a[0] == a[1] && a[1] == a[2]) cout << ans << endl;
	else if (a[0] == a[1]) cout << ans + 1 << endl;
	else cout << ans + 2 << endl;

	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,M;
int a[55],b[55];
int d[55][55];
int ans;

int main(){
	cin >> N >> M;
	repp(i,0,M){
		cin >> a[i] >> b[i];
	}
	repp(i,0,M){
		repp(z,0,55) fill(d[z],d[z]+55,12345678);
		repp(z,0,55) d[z][z] = 0;
		repp(j,0,M){
			if(i == j) continue;
			d[a[j]][b[j]] = 1;
			d[b[j]][a[j]] = 1;
		}
		repp(z,1,N+1) repp(x,1,N+1) repp(y,1,N+1) d[x][y] = min(d[x][y] , d[x][z]+d[z][y]);
		repp(x,1,N+1) repp(y,1,N+1){
			if(d[x][y] > N){
				++ans;
				x = y = N+2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
    int N;
    long long sum_A = 0;
    long long min_A = INT64_MAX;
    int minus_count = 0;
    cin >> N;
    rep(i, N)
    {
        long long A;
        cin >> A;
        if (A < 0)
            minus_count++;
        sum_A += abs(A);
        min_A = min(abs(A), min_A);
    }

    long long ans = sum_A;
    if (minus_count % 2 == 1)
        ans -= 2 * min_A;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void sit_a(char* chair,int chair_num) {
	int i;
	for(i=0;i<chair_num;i++) {
		if(chair[i]=='#') {
			chair[i]='A';
			break;
		}
	}
}

void sit_b(char* chair,int chair_num) {
	int i;
	for(i=chair_num-1;i>=0;i--) {
		if(chair[i]=='#' && chair[i-1]!='A' && chair[i+1]!='A') {
			chair[i]='B';
			return;
		}
	}
	for(i=0;i<chair_num;i++) {
		if(chair[i]=='#') {
			chair[i]='B';
			break;
		}
	}
}

void sit_c(char* chair,int chair_num) {
	int i;
	for(i=0;i<chair_num;i++) {
		if(chair[i]!='#') {
			if(chair[i+1]=='#') {
				chair[i+1]='C';
				return;
			} else if(i>0 && chair[i-1]=='#') {
				chair[i-1]='C';
				return;
			}
		}
	}
	if(chair[chair_num/2]=='#')chair[chair_num/2]='C';
}

void sit_d(char* chair,int chair_num) {
	int dist_list[200];
	int i;
	int now_dist;
	int no_sit=1;
	int max_dist,max_pos;
	for(i=0,now_dist=0;i<chair_num;i++) {
		if(chair[i]!='#') {
			no_sit=0;
			now_dist=0;
		}
		if(!no_sit) {
			dist_list[i]=now_dist++;
		} else {
			dist_list[i]=0x7fffffff;
		}
	}
	if(no_sit) {
		chair[0]='D';
		return;
	}
	no_sit=1;
	for(i=chair_num-1,now_dist=0;i>=0;i--) {
		if(chair[i]!='#') {
			no_sit=0;
			now_dist=0;
		}
		if(!no_sit) {
			if(dist_list[i]>now_dist)dist_list[i]=now_dist;
			now_dist++;
		}
	}
	max_dist=0;
	max_pos=0;
	for(i=0;i<chair_num;i++) {
		if(dist_list[i]>max_dist) {
			max_dist=dist_list[i];
			max_pos=i;
		}
	}
	chair[max_pos]='D';
}

int main(void) {
	int chair_num,people_num;
	char chair[204];
	char person[4];
	int i;
	while(1) {
		scanf("%d%d",&chair_num,&people_num);
		if(chair_num==0 && people_num==0)break;
		for(i=0;i<chair_num;i++)chair[i]='#';
		chair[chair_num]=0;
		for(i=0;i<people_num;i++) {
			scanf("%s",person);
			switch(person[0]) {
				case 'A':
					sit_a(chair,chair_num);
					break;
				case 'B':
					sit_b(chair,chair_num);
					break;
				case 'C':
					sit_c(chair,chair_num);
					break;
				case 'D':
					sit_d(chair,chair_num);
					break;
			}
		}
		puts(chair);
	}
	return 0;
}

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

int main(void) {
 while(1) {
   int H, W;
   cin >> H >> W;

   if (H == 0 && W == 0) break;

   for(int i = 0; i < H; i++){
     for(int j = 0; j < W; j++){
       cout << "#";
     }
     cout << "\n";
   }
   cout << "\n";
 }
 return 0;
}


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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    if(N == 100000) N = 99999;
    if(N >= 10000){
        ans = ans + N - 9999;
    }
    if(N >= 1000) N = 999;
    if(N >= 100){
        ans = ans + N - 99;
    }
    if(N >= 10) N = 9;
    ans = ans + N;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
vector<vector<bool> >table;
int h,w;
const long long mod=1000000007;
int main()
{
    int i,j;
    cin>>h>>w;
    vector<bool>tmp(w+1);
    table.resize(h+1,tmp);
    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++)
        {
            char ch;    cin>>ch;
            table[i][j]=(ch=='.'?true:false);
        }
    vector<long long>tmp1(w+1);
    vector<vector<long long> >memo(h+1,tmp1);
    bool flag=true;
    for(j=w;j>=1;j--)
    {
        if(!table[h][j]) flag=false;
        memo[h][j]=(flag?1:0);
    }
    flag=true;
    for(i=h;i>=1;i--)
    {
        if(!table[i][w]) flag=false;
        memo[i][w]=(flag?1:0);
    }
    for(i=h-1;i>=1;i--)
    {
        for(j=w-1;j>=1;j--)
        {
            memo[i][j]=(memo[i+1][j]+memo[i][j+1])%mod;
            if(!table[i][j]) memo[i][j]=0;
        }
    }
    cout<<memo[1][1];
}


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

typedef long long ll;

ll gcd(ll a, ll b){
	  return (a%b==0)? b: gcd(b,a%b);
}
ll lcm(ll a, ll b){
	  return a/gcd(a,b)*b;
}
//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 n; cin >> n;
	  int a[n];
	  for(int i=0; i<n; i++) cin >> a[i];

	  int ans = a[0];
	  for(int i=0; i<n; i++) ans = lcm(ans,a[i]);
	  cout << ans << endl;
	  

}

Measured memory_bytes: 1164
#include<cstdio>
#include<vector>

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

using namespace std;

bool is_valid(const char *a,const char *b,int hit,int blow){
	rep(i,4) rep(j,4) if(a[i]==b[j]) {
		if(i==j) hit--;
		else     blow--;
	}
	return hit==0 && blow==0;
}

int main(){
	vector<int> cand0; // どの桁の数字も異なるような 4 桁の数
	rep(i,10000){
		char s[5]; sprintf(s,"%04d",i);
		if(!(s[0]==s[1] || s[0]==s[2] || s[0]==s[3] || s[1]==s[2] || s[1]==s[3] || s[2]==s[3]))
			cand0.push_back(i);
	}

	for(int n;scanf("%d",&n),n;){
		vector<int> in(n),hit(n),blow(n);
		rep(i,n) scanf("%d%d%d",&in[i],&hit[i],&blow[i]);

		// 入力された質問に矛盾しない数全体
		vector<int> cand;
		rep(j,cand0.size()){
			char s[5]; sprintf(s,"%04d",cand0[j]);
			bool ok=true;
			rep(i,n){
				char t[5]; sprintf(t,"%04d",in[i]);
				if(!is_valid(s,t,hit[i],blow[i])){ ok=false; break; }
			}
			if(ok) cand.push_back(cand0[j]);
		}

		if(cand.size()==1){
			printf("%04d\n",cand[0]);
			continue;
		}

		if(cand.size()>16){
			puts("????");
			continue;
		}

		int ans=-1;
		rep(i,cand0.size()){
			char s[5]; sprintf(s,"%04d",cand0[i]); // 最後の 1 回に発言するべき数

			bool ok=true;
			vector<int> reply(cand.size());
			rep(j,cand.size()){
				char t[5]; sprintf(t,"%04d",cand[j]);
				int hit=0,blow=0;
				rep(k,4) rep(l,4) if(s[k]==t[l]) {
					if(k==l) hit++;
					else     blow++;
				}
				reply[j]=hit*10+blow;
				rep(k,j) if(reply[k]==reply[j]) { ok=false; break; }
			}

			if(ok){ // 真の解がどれであったとしても特定できるとき
				if(ans==-1){ ans=cand0[i]; break; }
			}
		}

		if(ans!=-1) printf("%04d\n",ans);
		else        puts("????");
	}

	return 0;
}

Measured memory_bytes: 876
def main():
    N = int(input())
    A = list(map(int, input().split()))
    max_height = A[0]
    ans = 0
    for a in A:
        if a > max_height:
            max_height = a
        ans += max_height - a
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 105292
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int x; cin >> x;
  int d = x % 100;
  int dd = x / 100;
  if(d > 5 * dd){
    cout << 0 << endl;
  }else
    cout << 1 << endl;
}


Measured memory_bytes: 256
<?php
$arr1=array();
$arr2=array();
$count=0;
//1行目の空白までのデータをもらって$n1に入れる
fscanf(STDIN,'%d',$n1);
//2行目の文字列をもらう
  $temp_arr1=fgets(STDIN);
//文字列から空白のスペースを取り除く
  $temp_arr1=trim($temp_arr1);
//空白を境目にして、文字列から配列を作る
  $arr1=explode(' ',$temp_arr1);
  // v($arr1);
  //2つめのデータの1行目の空白までのデータをもらって$n1に入れる
  fscanf(STDIN,'%d',$n2);
  //$arr1を作ったのと同じ作業を1行で済ませる
  $arr2=explode(' ',trim(fgets(STDIN)));


  foreach($arr2 as $a){
    if(in_array($a,$arr1)){
      $count++;
    }
  }
  echo $count . PHP_EOL;



Measured memory_bytes: 11108
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	int next4Rand(int seed){

		return ((seed*seed)/100)%10000;

	}

	void run(){

		int n = sc.nextInt();

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

			System.out.println("Case "+(i+1)+":");

			int seed  = sc.nextInt();

			for(int j =0 ; j < 10;j++){

				seed = next4Rand(seed);

				System.out.println(seed);

			}

		}

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int x;
int main(){
    string s;
    cin>>s;
    int a=s.at(0)-'0',b=s.at(1)-'0',c=s.at(2)-'0',d=s.at(3)-'0';
    char sign[3];
    for(int i=0;i<2;i++){
        if(i==0)sign[0]='+';
        else sign[0]='-';
        for(int j=0;j<2;j++){
            if(j==0)sign[1]='+';
            else sign[1]='-';
            for(int k=0;k<2;k++){
                if(k==0)sign[2]='+';
                else sign[2]='-';
                    int result=0;
                    sign[0]=='+'?result=a+b:result=a-b;
                    sign[1]=='+'?result+=c:result-=c;
                    sign[2]=='+'?result+=d:result-=d;
                if(result==7){
                    cout<<a<<sign[0]<<b<<sign[1]<<c<<sign[2]<<d<<"="<<result<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}




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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> xs(n), ys(n);
  for (int i = 0; i < n; ++i)
    cin >> xs[i] >> ys[i];

  int vmax = 0;
  map<pair<int, int>, int> mp;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j)
        continue;
      int p = xs[j] - xs[i];
      int q = ys[j] - ys[i];
      if (mp.find(make_pair(p, q)) == mp.end())
        mp[make_pair(p, q)] = 1;
      else
        ++mp[make_pair(p, q)];
      vmax = max(vmax, mp[make_pair(p, q)]);
    }
  }
  cout << n - vmax << endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;

ll get_upper(vector<ll> &l, ll st, ll end, ll sum){
	ll idx = st;
	while(st <= end){
		ll mid = st + (end - st)/2;
		// cout << st << " " << mid << " " << end << endl;
		if (l[mid] < sum){
			idx = max(idx, mid);
			st = mid+1;
		}
		else{
			end = mid - 1;
		}
	}
	return idx;
}

int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	ll n;
	cin >> n;
	vector<ll> l(n);
	for(int i = 0; i < n; i++)
		cin >> l[i];
	sort(l.begin(), l.end());

	ll ans = 0;
	for(ll i = 0; i < n; i++){
		// cout << i << endl;
		for(ll j = i+1; j < n; j++){
			ll sum = l[i] + l[j];
			ll idx = get_upper(l, j, n-1, sum);
			// trace4(j, sum, idx,idx-j)
			ans += (idx-j);
		}
	}

	cout << ans << endl;
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5)
anslist = []
def sarch(i, j, visited):

    if 0 < i:
        if visited[i - 1][j] == 0:
            visited[i - 1][j] = 1
            sarch(i - 1, j, visited)
        if 0 < j:
            if visited[i - 1][j - 1] == 0:
                visited[i - 1][j - 1] = 1
                sarch(i - 1, j - 1, visited)
        if j < len(visited[0]) - 1:
            if visited[i - 1][j + 1] == 0:
                visited[i - 1][j + 1] = 1
                sarch(i - 1, j + 1, visited)

    if i < len(visited) - 1:
        if visited[i + 1][j] == 0:
            visited[i + 1][j] = 1
            sarch(i + 1, j, visited)
        if 0 < j:
            if visited[i + 1][j - 1] == 0:
                visited[i + 1][j - 1] = 1
                sarch(i + 1, j - 1, visited)
        if j < len(visited[0]) - 1:
            if visited[i + 1][j + 1] == 0:
                visited[i + 1][j + 1] = 1
                sarch(i + 1, j + 1, visited)

    if 0 < j:
        if visited[i][j - 1] == 0:
            visited[i][j - 1] = 1
            sarch(i, j - 1, visited)
    if j < len(visited[0]) - 1:
        if visited[i][j + 1] == 0:
            visited[i][j + 1] = 1
            sarch(i, j + 1, visited)
    return visited


while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    grid = [list(map(int, input().split())) for j in range(h)]
    visited = [[0 for i in range(w)] for j in range(h)]
    starti = 0
    startj = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == 0:
                visited[i][j] = -1
            else:
                visited[i][j] = 0

    i = 0
    j = 0
    cnt = 0
    ans = 0
    #print(visited)
    while True:
        if i >= h:
            i = 0
            j = 0
        while True:
            cnt += 1
            if j >= w:
                j = 0
                break
            #print(visited[i][j], 100100)
            if visited[i][j] == 0:
                ans += 1
                visited[i][j] = 1
                visited = sarch(i, j, visited)
                cnt = 0
            j += 1
        i += 1
        #print(cnt, visited)
        if cnt > w * h:
            #print(10)
            break
    anslist.append(ans)

for i in anslist:
    print(i)


Measured memory_bytes: 7920
#include<stdio.h>
#include<stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
Node head, tail;
void inorder(Node node){
  if(node != tail){
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
  }
}
void preorder(Node node){
  if(node != tail){
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){
    y = x;
    if (z->key < x->key)x = x->left;
    else x = x->right ;
    z->parent = y;
  }
  if (y == NIL)root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}
Node find ( Node A, int x){
  while(A!=NIL && x!=A->key){
    if(x < A->key)
      A=A->left;
    else A=A->right;
  }
  return A;
}

int main(){
  int n, i, x;
  char com[20];
  Node a;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'f' ){
      scanf("%d",&x);
      a=find(root,x);
      if(a==NIL)printf("no\n");
      else printf("yes\n");
    }

  }

  return 0;
}


Measured memory_bytes: 20460
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)

using namespace std;

ll n,m;

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

    cin >> n >> m;
    ll p = n;
    ll cnt = 0;

    if(n%4==2)
    {
        ll i = 0;
        while(cnt < m)
        {
            i++;
            if(i == n/4+1)
                continue;

            cnt++;
            cout << i << " " << p << endl;
            p--;
        }

        return 0;
    }
    else if(n%4==0)
    {
        ll i = 0;
        bool found = false;

        while(cnt < m)
        {
            i++;

            if(2*(p-i) < n && !found)
            {
                found=true;
                continue;
            }
            cnt++;
            cout << i << " " << p << endl;
            p--;
        }

        return 0;
    }

    rep(i,1,m+1)
    {
        cout << i << " " << p << endl;
        p--;
    }
    return 0;
}



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

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N) :
    weight_i,value_i = L[i]
    for weight in range(W+1) :
        if weight - weight_i >= 0 :
            dp[i+1][weight] = max(dp[i][weight], dp[i][weight - weight_i] + value_i)
        else :
            dp[i+1][weight] = dp[i][weight]

ans = dp[N][W]

print(ans)


Measured memory_bytes: 171656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int s=0;
  cin>>n;
  vector<int>vec(n);
  for(int X=0;X<n;X++){
    cin>>vec.at(X);
  }
  int M=vec.at(0);
  for(int X=1;X<n;X++){
    if(M>vec.at(X)){
      M=vec.at(X);
      s++;
    }
  }
  cout<<s+1<<endl;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll a, b, k;
  cin >> a >> b >> k;
  ll aa = max((ll)0, a-k);
  ll r = max((ll)0, k-a);
  ll ab = max((ll)0, b-r);
  cout << aa << " " << ab << endl;

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> x >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
  x = x-a; 
  if(x >= b) x = x%b;
  //else anss = "Odd";

  cout << x << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

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

    ll n=s.length();
    if(n==1){
        cout << 1<<endl;
        return 0;
    }
    ll num=0;
    ll ans=0;
    ll ma=0;
    for(int i=0;i<n;i++){
        if(i==0){
            num++;
        }else if(i==n-1){
            if(s[i]=='<'){
                if(s[i-1]=='>'){
                    ans+=num*(num-1)/2;
                    ans+=max(ma,num);
                    ans++;
                }else{
                    ans+=(num+1)*(num+2)/2;
                }
            }
            else{
                if(s[i-1]=='>'){
                    num++;
                    ans+=max(ma,num);
                    ans+=num*(num-1)/2;
                }
                else{

                    ans+=num*(num+1)/2;
                }
            }
        }
        else if(s[i]==s[i-1]){
            num++;
        }else{
            if(s[i]=='<'){
                ans+=num*(num-1)/2;
                ans+=max(ma,num);
            }else{
                ans+=num*(num-1)/2;
                ma=num;
            }
            num=1;
        }
        
    }
    cout << ans<<endl;
    return 0;
}


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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
  int n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];
  ll sum[n];
  sum[0] = a[0];
  REP(i, n-1) sum[i+1] = sum[i] + a[i+1];
  ll d[n+2];
  d[0] = -INFL;
  REP(i, n) d[i+1] = 2*sum[i];
  d[n+1] = INFL;
  ll ans = INFL;
  FOR(i, 1, n-2){
    ll p, q, r, s;
    auto it1 = upper_bound(d, d+n+2, sum[i]);
    if((sum[i] - *(it1-1)) < (*it1 - sum[i])){
      p = *(it1-1);
      q = d[i+1] - p;
    }
    else{
      p = *it1;
      q = d[i+1] - p;
    }
    p /= 2;
    q /= 2;
    auto it2 = upper_bound(d, d+n+2, sum[n-1]+sum[i]);
    if(*it2 != d[i+1] && (sum[i] + sum[n-1] - *(it2-1)) < (*it2 - sum[i] - sum[n-1])){
      r = *(it2-1) - d[i+1];
      s = d[n] - d[i+1] - r;
    }
    else{
      r = *it2 - d[i+1];
      s = d[n] - d[i+1] - r;
    }
    r /= 2;
    s /= 2;
    ll mx1, mx2, mn1, mn2;
    mx1 = (p>q?p:q);
    mx2 = (r>s?r:s);
    mn1 = (p<q?p:q);
    mn2 = (r<s?r:s);
    ll mx, mn;
    mx = (mx1>mx2?mx1:mx2);
    mn = (mn1<mn2?mn1:mn2);
    ans = (ans > (mx-mn)?mx-mn:ans);
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
		Scanner in = new Scanner(System.in);
		int a[] = {in.nextInt(), in.nextInt(), in.nextInt()};
		int b;
		
		if(a[1] < a[0]){
			b = a[0];
			a[0] = a[1];
			a[1] = b;
		}
		
		if (a[2] < a[1]){
			if(a[2] < a[0]){
				b = a[2];
				a[2] = a[0];
				a[0] = b;
			}
			b = a[2];
			a[2] = a[1];
			a[1] = b;
		}
		
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
		
	}
}

Measured memory_bytes: 26224
s=raw_input()
l=s.split('eraser')
s=''
for i in l:
    s=s+i
l=s.split('erase')
s=''
for i in l:
    s=s+i
l=s.split('dreamer')
s=''
for i in l:
    s=s+i
l=s.split('dream')
if(l.count('')==len(l)):
    print 'YES'
else:
    print 'NO'


Measured memory_bytes: 3076
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

template<typename T>
constexpr T Abs(T a) {
  return a > 0 ? a : -a;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  vector<int> h(N);
  F0R(i, N) {
    cin >> h[i];
  }

  vector<int> dp(N + 1);
  FOR(i, 1, N) {
    dp[i] = INT32_MAX;
    FOR(j, 1, min(K + 1, i + 1)) {
      dp[i] = min(dp[i], dp[i - j] + Abs(h[i] - h[i - j]));
    }
  }
  cout << dp[N - 1];
}
#endif


Measured memory_bytes: 1024