akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int side = 0;
		int[] sides = new int[3];

		while ((line = br.readLine()) != null) {
			try {
				side = Integer.parseInt(line.split(" ")[0]);
				sides[0] = side * side;
				side = Integer.parseInt(line.split(" ")[1]);
				sides[1] = side * side;
				side = Integer.parseInt(line.split(" ")[2]);
				sides[2] = side * side;
				Arrays.sort(sides);
				if (sides[2] == sides[0] + sides[1]) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} catch (ArrayIndexOutOfBoundsException e) {
				continue;
			}
		}
	}
}

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

int main() {

    int n;

    cin >> n;

    int a,b,c,d;

    d = n%10;
    n /= 10;
    c = n%10;
    n /= 10;
    b = n%10;
    n /= 10;
    a = n%10;
    char op[3];

    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);

    for(int i=0; i<8; i++){
        for(int j=0; j<3; j++){
            if(i>>j & 1){
                v[0] += v[j+1];
                op[j] = '+';
            }
            else{
                v[0] -= v[j+1];
                op[j] = '-';
            }
        }
        if(v[0] == 7){
            break;
        }
        v[0] = a;
    }

    cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()
    char_cnt = Counter(s)

    res = INF
    for c in char_cnt.keys():
        r = s[:]
        cnt = 0
        while len(set(r)) != 1:
            t = ''
            for ss in zip(r[:-1], r[1:]):
                if c in ss:
                    t += c
                else:
                    t += ss[0]
            cnt += 1
            r = t
            # print(r)
        res = min(res, cnt)

    return res


print(main())


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

int main(){

	int x1,y1,x2,y2;
	
  	cin >> x1 >> y1 >> x2 >> y2;
  	
  	int diffx = x1 - x2;
  	int diffy = y1 - y2;
	
  	int x3 = x2 + diffy;
    int y3 = y2 - diffx;
    int x4 = x3 + diffx;
  	int y4 = y3 + diffy;
      
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {

	int r, g, b,num;

	cin >> r >> g >> b;

	num = 100 * r + 10 * g + b;

	if (num % 4 == 0)
		cout << "YES" << endl;

	else
		cout << "NO" << endl;

}

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

using namespace std;

#define DATA_MAX 10000
#define QUERY_MAX 100000

template<class T, class S, class U>
struct trio{
    T first;
    S second;
    U third;
};

void MakeData(vector<vector<int> >&, int);
int ReadQuery(vector<vector<int> >&, int, int);
void FindAndUnite(vector<vector<int> >&, int, int, int);

int main(){
    int n, q;
    vector<vector<int> > data;
    
    cin >> n >> q;
    if(!((1 <= n && n <= DATA_MAX) && (1 <= q && q <= QUERY_MAX)))
        return -1;
    
    MakeData(data, n);
    if(ReadQuery(data, q, n) == -1)
        return -1;
    
    return 0;
}

void FindAndUnite(vector<vector<int> > &data, int com, int x, int y){
    bool find = false;
    trio<int, int, bool> Xkey, Ykey;
    
    Xkey.third = false;
    Ykey.third = false;
    
    for(vector<vector<int> >::size_type i = 0;i < data.size();i++){
        for(vector<int>::size_type j = 0;j < data[i].size();j++){
            if(data[i][j] == x){
                Xkey.first = i;
                Xkey.second = j;
                Xkey.third = true;
            }
            else if(data[i][j] == y){
                Ykey.first = i;
                Ykey.second = j;
                Ykey.third = true;
            }
            
            if(Xkey.third && Ykey.third){
                find = true;
                break;
            }
        }
        
        if(find)
            break;
    }
    
    if(com){
        if(Xkey.first == Ykey.first)
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
    else{
        if(Xkey.first != Ykey.first){
            copy(data[Ykey.first].begin(), data[Ykey.first].end(), back_inserter(data[Xkey.first]));
            data.erase(data.begin() + Ykey.first);
        }
    }
}

int ReadQuery(vector<vector<int> > &data, int q, int n){
    int com, x, y;
    
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;
        
        if((com != 0 && com != 1) || x == y || !(0 <= x && x < n) || !(0 <= y && y < n))
            return -1;
        
        FindAndUnite(data, com, x, y);
    }
    
    return 0;
}

void MakeData(vector<vector<int> > &data, int n){
    for(int i = 0;i < n;i++)
        data.emplace_back(1, i);
}



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

#define ll long long int
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define nl '\n'
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
const ll N=1e6+9;
const ll mod=1e9+7;

vector<ll> v[N];
ll vis[N],parent[N],level[N];

ll find(ll x)
{
	if(x==parent[x])return x;
	else return find(parent[x]);
}

ll dfs(ll x, ll l)
{
	vis[x]=1;
	//cout<<x<<"<<";
	//level[x]=max(level[x],l);
	if(v[x].size()==0){level[x]=0;return 1;}
	for(auto it: v[x])
	{
		if(!vis[it])
		level[x] = max(level[x] ,dfs(it,l+1));
		else level[x]= max(level[x],level[it]+1);
	}
	//cout<<x<<" "<<level[x]<<nl;
	return level[x]+1;

}

void solve()
{
	ll n,m;
	cin>>n>>m;
	rep(i,1,n)parent[i]=i;
	rep(i,1,m)
	{
		ll x,y;
		cin>>x>>y;
		v[x].pb(y);
		parent[y]=x;
	}
	ll maxm=0;
	rep(i,1,n)
	{
		if(!vis[i])
		{
			ll x= find(i);
			//cout<<x<<" ";
			x= dfs(x,0);
			x--;
			if(maxm<x)maxm=x;
		}
	}
	cout<<maxm;

}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    //if(t^1)exit(0);
    while(t--)
       solve();
}

Measured memory_bytes: 41344
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1<<28;

int main(){

    string s; cin >> s;

    cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14, 5) << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, ans, dp[10000][10000];
string s;
int main(){
    cin >> n >> s;
    for (int i=1; i<=n; i++){
        for (int j=i+1; j<=n; j++){
            if (s[i-1] == s[j-1]){
                if (j - dp[i-1][j-1] == i)dp[i][j] = 0;
                else{
                    dp[i][j] = dp[i-1][j-1] + 1;
                    ans = max(ans, dp[i][j]);
                }
            }
        }
    }
cout << ans;
return 0;
}

Measured memory_bytes: 195968
function main(data){
    input = data.split("");
    len = input.length;
    temp = []
    for(i = 0; i<len; i+=1){
        if(temp.indexOf(input[i]) === -1){
            temp.push(input[i]);
        }else{
            console.log("no");
            return;
        }
    }
    console.log("yes");
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
//pragma GCC optimize("Ofast")
//pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" )
#include <queue>
#define endl "\n";
#define int long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;

void solve() {
	int a[5], ans;
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
		if (!a[i]) ans = i + 1;
	}
	cout << ans;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
 
int main()
{
  int n,i;
  long int a=0;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    if(i%3==0||i%5==0){}
    else 
      a+=i;
  }
  
  printf("%ld\n",a);
  
  return 0;
}

Measured memory_bytes: 1732
#include <cstdio>

inline int read(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

const int mod=1e9+7;
const int N=5e3+5;
int n,h[N],edge_cnt,sz[N],g[N],f[N][N],tmp[N];
struct Edge{ int to,nex; }e[N<<1];

inline void add_edge(int u,int v){
	e[++edge_cnt]=(Edge){v,h[u]}; h[u]=edge_cnt;
	e[++edge_cnt]=(Edge){u,h[v]}; h[v]=edge_cnt;
}

void dfs(int u,int pre){
	sz[u]=f[u][1]=1;
	for(int i=h[u];i;i=e[i].nex){
		int v=e[i].to; if(v==pre) continue;
		dfs(v,u); for(int j=0;j<=sz[u]+sz[v];++j) tmp[j]=0;
		for(int j=0;j<=sz[u];++j) for(int k=0;k<=sz[v];++k){
			tmp[j+k]=(tmp[j+k]+1ll*f[u][j]*f[v][k])%mod;
		}
		sz[u]+=sz[v]; for(int j=0;j<=sz[u];++j) f[u][j]=tmp[j];
	}
	for(int j=2;j<=sz[u];j+=2){
		f[u][0]=(f[u][0]+mod-1ll*f[u][j]*g[j]%mod)%mod;
	}
}

int main(){
	n=read(); for(int i=1;i<n;++i) add_edge(read(),read());
	g[0]=1; for(int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
	dfs(1,0); printf("%d\n",(mod-f[1][0])%mod); return 0;
}

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

import static java.lang.Integer.parseInt;

/**
 * Grid Mori
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int n, a, b, c, d;

		n = parseInt(br.readLine());

		line = br.readLine();
		a = parseInt(line.substring(0, line.indexOf(' ')));
		b = parseInt(line.substring(line.indexOf(' ') + 1));

		line = br.readLine();
		c = parseInt(line.substring(0, line.indexOf(' ')));
		d = parseInt(line.substring(line.indexOf(' ') + 1));

		a--;
		b--;
		c--;
		d--;

		int min = Integer.MAX_VALUE;

		for (int w = 1; w <= n; w++) {
			int[] pa = new int[]{a % w, a / w};
			int[] pb = new int[]{b % w, b / w};
			int[] pc = new int[]{c % w, c / w};
			int[] pd = new int[]{d % w, d / w};
			int _min = 0;
			_min += Math.abs(pa[0] - pb[0]);
			_min += Math.abs(pa[1] - pb[1]);
			_min += Math.abs(pc[0] - pd[0]);
			_min += Math.abs(pc[1] - pd[1]);
			min = Math.min(min, _min);
		}

		System.out.println(min);
	}
}

Measured memory_bytes: 24348
#include <iostream>
using namespace std;
int main(){
  string str;
  while(getline(cin,str)){
    if(str == "END OF INPUT")break;
    int cnt = 0;
    for(int i = 0 ; i < str.size() ; i++ ){
      if(str[i] == ' '){
	cout << cnt;
	cnt = 0;
      }else cnt++;
    }
      cout << cnt << endl;
  }
}

Measured memory_bytes: 1184
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    int N,M;
    cin >> N >> M;
    vector<int> G[123456];
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> path;
    vector<bool> used(N+1,false);
    int cur = 0;
    rep(i,0,N+1){
        if(G[i].size() > 0){
            cur = i;
            break;
        }
    }
    used[cur] = true;
    path.push_back(cur);
    while(true){
        bool flag = false;
        rep(i,0,G[cur].size()){
            if(!used[G[cur][i]]){
                cur = G[cur][i];
                used[cur] = true;
                path.push_back(cur);
                flag = true;
                break;
            }
        }
        if(!flag) break;
    }
    cur = path[0];
    reverse(all(path));
    while(true){
        bool flag = false;
        rep(i,0,G[cur].size()){
            if(!used[G[cur][i]]){
                cur = G[cur][i];
                used[cur] = true;
                path.push_back(cur);
                flag = true;
                break;
            }
        }
        if(!flag) break;
    }
    cout << path.size() << endl;
    rep(i,0,path.size()){
        cout << path[i];
        if(i == path.size() - 1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h.at(i);
    }

    vector<int> dp(n, 0);
    rep(i, n - 1)
    {
        int min_num = 1000000000;
        for (int j = 0; j < k; j++)
        {
            if (i - j >= 0)
            {
                // j+1個前からのジャンプ
                int cj = dp.at(i - j) + abs(h.at(i + 1) - h.at(i - j));
                min_num = min(min_num, cj);
            }
        }
        dp.at(i + 1) = min_num;
    }

    cout << dp.at(n - 1);
}


Measured memory_bytes: 1024
var n;
var x = [];

function main(){
	n = scan();
	rep(n, function(i){
		x[i] = scan();
	});
	var p = [0, 0, -Infinity, -Infinity, -Infinity, -Infinity];
	var ans = 0;
	rep(n, function(i){
		var a = x[i];
		var b = 1 - a;
		var q = [];
		q[a] = p[b] + 1;
		q[b] = 0;
		q[2 + b] = Math.max(p[a], p[2 + a]) + 1;
		q[2 + a] = 0;
		q[4 + a] = Math.max(p[2 + b], p[4 + b]) + 1;
		q[4 + b] = 0;
		ans = Math.max(Math.max.apply(null, q), ans);
		p = q;
	});
	print(ans);
}
 
function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/);
	main();
});

Measured memory_bytes: 27468
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200000;
int main()
{
  int n,k,i;
  long long s=0,h[N_MAX];
  cin >> n >> k;
  for(i=0;i<n;i++)
    cin >> h[i];
  sort(h,h+n);
  for(i=0;i<n-k;i++)
    s+=h[i];
  cout << s << endl;
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> X(N, 0);
	repeat(i, N) {
		cin >> X[i];
	}
	int result = 100000000;

	for(int i = 1; i <= 100; i++) {
		int temp = 0;
		repeat(j, N) {
			temp += (X[j] - i) * (X[j] - i);
		}
		if (temp < result) result = temp;
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int a,b;
    cin>>a>>b;
    int y[3];
    y[0]=a-b;
    y[1]=a+b;
    y[2]=a*b;
    sort(y,y+3);
    cout<<y[2];
    return 0;
}


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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

void dfs(vector<string> &m, int x, int y, char c) {

    if (x < 0 or x >= 100) return;
    if (y < 0 or y >= 100) return;

    if (m[x][y] != c) return;

    m[x][y] = 'x';

    REP(i, 4) {
        dfs(m, x + dx[i], y + dy[i], c);
    }
}

int main() {
    
    int A, B; cin >> A >> B;
    vector<string> m(100);
    REP(i, 50) {
        m[i]    = "####################################################################################################";
        m[i+50] = "....................................................................................................";
    } 
    
    REP(i, A-1) {
        m[ i/50*2 ][(i%50)*2] = '.';
    }

    REP(i, B-1) {
        m[ 51 + i/50*2 ][(i%50)*2] = '#';
    }

    cout << 100 << " " << 100 << endl;
    REP(i, m.size()) cout << m[i] << endl;

    /*
    int x = 0, y = 0;
    REP(i, 100) REP(j, 100) {
        if (m[i][j] == '.') {
            x++;
            dfs(m, i, j, '.');
        }
        if (m[i][j] == '#') {
            y++;
            dfs(m, i, j, '#');
        }
    }
    cout << x << " " << y << endl;
    */

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int X, Y, A, B, C, D, P, r, R;
 scanf( "%d", &A );
 scanf( "%d", &B );
 scanf( "%d", &C );
 scanf( "%d", &D );
 scanf( "%d", &P );
 X = A * P;
 if( P <= C ) {
   Y = B;
 } else {
   r = ( P - C ) * D;
   Y = B + r;
 }
 if( X > Y ){
   R = Y;
 } else {
   R = X;
 }
 printf( "%d\n", R );
 return 0;
}

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

#define ll long long
#define ull unsigned long long 

int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i].first >> a[i].second;

    sort(a.begin(), a.end());

    ll t=0;
    for(int i=0; i<n && m>0; ++i){
        t += a[i].first * ((a[i].second > m)?m:a[i].second);
        m -= a[i].second;
    }
    cout << t;
}


Measured memory_bytes: 4840
#include<iostream>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x-r>=0&&y-r>=0&&x+r<=w&&y+r<=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;

int func2(int *temp) {
    int n = 0;
    
    n += (temp[0] * 1000);
    n += (temp[1] * 100);
    n += (temp[2] * 10);
    n += temp[3];
       
    return n;
}

int main() {
    while (true) {
        int N = 0, Nm[4] = {0};
        unsigned int count = 0;
        int judge = 0;
        int Lm[4] = {0}, Sm[4]={0};
        int S = 0, L = 0;
        
	cin >> N;
        
        Nm[0] = N / 1000;
        N %= 1000;
        Nm[1] = N / 100;
        N %= 100;
        Nm[2] = N / 10;
        N %= 10;
        Nm[3] = N;
        
        if((Nm[0] == 0 && Nm[1] == 0) && (Nm[2] == 0 && Nm[3] == 0))          break;
        
        for(int i = 0; i < 4; i++) {
            if (Nm[i] == Nm[0]) judge++;
        }
        
        if (judge != 4) {
            while (true) {
                if ((Nm[0] == 6 && Nm[1] == 1) && (Nm[2] == 7 && Nm[3] == 4)) break;
                
                //Sを作成
                sort(Nm, Nm + 4);
                for (int i = 0; i < 4; i++) {   
                    Sm[i] = Nm[i];
                    //cout << Sm[i] << endl;
                }   
                S = func2(Sm);

                //Lを作成
                sort(Nm, Nm + 4, greater<int>());
                for (int i = 0; i < 4; i++) {
                    Lm[i] = Nm[i];
                }
                L = func2(Lm);

                N = L - S;
                count++;

                Nm[0] = N / 1000;
                N %= 1000;
                Nm[1] = N / 100;
                N %= 100;
                Nm[2] = N / 10;
                N %= 10;
                Nm[3] = N;
            }
            cout << count << endl;
        }
        
        if(judge == 4) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1176
n,x=map(int,raw_input().split())
a=(map(int,raw_input().split()))

a.sort()
count=0
for i in range(n):
    x-=a[i]
    if x < 0:
        break
    count+=1

if x == 0:
    print(n)
elif x > 0:
    print(n-1)
else:
    print(count)



Measured memory_bytes: 2568
# 入力は全て整数である。
# 1<N<20
# 1<C<,V<50

n = gets.chomp.to_i
v_ary = gets.chomp.split.map(&:to_i)
c_ary = gets.chomp.split.map(&:to_i)
ans = 0
n.times do |i|
  num = v_ary[i] - c_ary[i]
  ans += num if num > 0
end
puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (a < c) {
                System.out.printf("%d %d %d\n", a, c, b);
            } else {
                System.out.printf("%d %d %d\n", c, a, b);
            }
        } else {
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            }else if (b < c){
                System.out.printf("%d %d %d\n", b, c, a);
            }else {
                System.out.printf("%d %d %d\n", c, b, a);
            }
        }

        }
    }


Measured memory_bytes: 26204
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int n;

    while (1) {
        cin >> n;
        if (n == 0) break;
        int score[1000] = {0,};
        int sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> score[i];
            sum += score[i];
        }
        double mean = sum / (double)(n);

        double Sigma = 0;
        for (int i = 0; i < n; i++) {
            Sigma += (score[i]-mean)*(score[i]-mean);
        }
        printf("%lf\n", sqrt(Sigma/n));
    }

    return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <stdlib.h>
int d[100000];
int asc(const void *a, const void *b);

int main(void){
    int i, n;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &d[i]);
    }
    /* for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(d[i]>d[j]){
                tmp = d[i];
                d[i] = d[j];
                d[j] = d[i];
            }
        }
    }*/
    qsort(d, n, sizeof(int), asc);
    if(d[n/2-1]==d[n/2])printf("0\n");
    else
    printf("%d\n", d[n/2]-d[n/2-1]);
    return 0;
}

int asc(const void *a, const void *b){
    return *(int *)a - *(int *)b;
}

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

using namespace std;

long long func(long long b,long long n){
	if(n < b) return n;
	else{
		return func(b,n/b)+n%b;
	}
}
int main(void)
{
	long long n,s; cin>>n>>s;
	if(n < s){
		cout<<-1<<endl;
		return 0;
	}
	else if(s == n){
		cout<<n+1<<endl;
		return 0;
	}
	for(long long i = 2; i*i <= n; i++){
		if(s == func(i,n)){
			cout<<i<<endl;
			return 0;
		}
	}
	long long p, q,b;
	long long ans = 1e12;
	for(long long i = 1; i*i < n;i++){
		p = i;
		b = (n-s)/p+1;
		if(b < 2) continue;
		if(s == func(b,n)){
			ans = min(ans,b);
		}
	}
	if(ans != 1e12) cout<<ans<<endl;
	else cout<<-1<<endl;
	/*
	int ans = func(10,87654);
	cout<<ans<<endl;
	ans = func(100,87654);
	cout<<ans<<endl;
	*/
	//cout<<sqrt(87654)<<endl;
	
	//cout<<sqrt(3145926535)<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 
int main(void) {
  int n, m, i, a;
  scanf("%d %d", &n, &m);
  for(i=0; i<m; i++) {
    scanf("%d", &a);
    n-=a;
  }
  if(n<0) {
    n = -1;
  }
  printf("%d\n", n);
  
  return 0;
}

Measured memory_bytes: 1732
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Set<Character> okSet = new HashSet<>();
			IntStream.range(0, 10).forEach(i -> okSet.add((char) ('0' + i)));
			int k = scanner.nextInt();
			IntStream.range(0, k).forEach(i -> okSet.remove(Character.valueOf((char) ('0' + scanner.nextInt()))));
			int result = 0;
			main: for (int i = n; i < 10 * n; i++) {
				char[] array = String.valueOf(i).toCharArray();
				for (char c : array) {
					if (!okSet.contains(c)) {
						continue main;
					}
				}
				result = i;
				break;
			}
			System.out.println(result);
		}
	}
}


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

int main(void){
   int A,B,C;
   cin>>A>>B>>C;
   for(int i=1;i<=B;i++){
      if(A*i%B==C){
         cout<<"YES"<<endl;
         return 0;
      }
   }
   cout<<"NO"<<endl;
   return 0;
}



Measured memory_bytes: 256
function f(A,F,X)
	T=0
	for (a,b)=zip(A,F)
		t=a*b-X
		if t>0
			T+=cld(t,b)
		end
	end
	T
end
function main()
	N,K=map(x->parse(Int,x),split(readline()))
	A=sort(map(x->parse(Int,x),split(readline())))
	F=reverse(sort(map(x->parse(Int,x),split(readline()))))
	L=-1
	R=2^40
	while R-L>1
		M=(L+R)>>1
		if f(A,F,M)<=K
			R=M
		else
			L=M
		end
	end
	println(R)
end
main()


Measured memory_bytes: 144556
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

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

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  int n, m; cin >> n >> m; 
  vector<ll> w(n), v(n);
  forall(i,0,n){ cin >> w[i] >> v[i]; }
  vector<ll> dp(m+1, -1);
  dp[0] = 0;
  forall(i,0,n){
    int val = v[i], wei = w[i];
    for(int j = max(0,m-wei); j >= 0; --j){
      if( dp[j] == -1 ) continue;
      dp[j+wei] = max( dp[j+wei], dp[j] + val );
    }
    trace(i, val, wei);
    print_(dp);

  }
  cout << *max_element(all(dp)) << '\n';


  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a + b == c ||
		b + c == a ||
		a + c == b)
		cout << "Yes";
	else
		cout << "No";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = (int)1e9 + 7;
const int INF = (int)1e9;
const int N = 2005;
const int MAXA = (int)3e6;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(b * d, max(b * c, max(a * d, a * c)));
    return 0;
}



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

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

    int a = 1, b = 1;
    int ans = 1000000;
    int s = 0, t = 0;
    for (int i = 1; i <= n/2; i++)
    {
        a = i;
        b = n - i;
        while (a > 0)
        {
            s +=  a % 10;
            a /= 10;
        }
        while (b > 0)
        {
            t += b % 10;
            b /= 10;
        }
        ans = min(ans, (s+t));
        s = 0;
        t = 0;   
    }

    printf("%d\n", ans);
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    vector<vector<ll>> v(8);
    int n, m;
    cin >> n >> m;
    for (int x = 0; x < n; ++x) {
        ll a, b, c;
        cin >> a >> b >> c;
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                for (int k = 0; k < 2; ++k) {
                    v[i+j*2+k*4].emplace_back(a*(1-2*i)+b*(1-2*j)+c*(1-2*k));
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < 8; ++i) {
        sort(v[i].begin(), v[i].end(), greater<>());
        ll k = 0;
        for (int j = 0; j < m; ++j) {
            k += v[i][j];
        }
        ans = max(k, ans);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, M;
  cin >> N >> M;
  if (N >= M) {
    cout << 0 << endl;
  }
  else {
    vector<int> X(M);
    for (int i = 0; i < M; i++) {
      cin >> X.at(i);
    }
    sort(X.begin(), X.end());
    vector<int> memo(M - 1);
    for (int i = 1; i < M; i++) {
      memo.at(i - 1) = X.at(i) - X.at(i - 1);
    }
    sort(memo.begin(), memo.end());   
    int ans = 0;
    for (int i = 0; i < M - N; i++) {
      ans += memo.at(i);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3948
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        dv: [usize; n]
    };

    let res = dv
        .into_iter()
        .combinations(2)
        .map(|v| v[0] * v[1])
        .sum::<usize>();
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2196
#include "bits/stdc++.h"

using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const vector<pair<T, U>> p) {
	os << "P(" << p.first << ", " << p.second << endl;
}

/*
template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << P << " ";
	return os << "}";
}
*/

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Insert from here! */
/* Cut from here! */

void Main() {
	int N;
	while (true) {
		cin >> N;
		if (N == 0) break;
		string c; cin >> c;
		vector<int> v(N);
		int ba = 0;
		for (int i = 0; i < c.length(); ++i) {
			int idx = i % N;
			if (c[i] == 'M') v[idx]++;
			else if (c[i] == 'S') {
				ba += v[idx] + 1;
				v[idx] = 0;
			} else {
				v[idx] += ba + 1;
				ba = 0;
			}
		}

		sort(all(v));
		for (int i = 0; i < N; ++i) {
			if (i == 0) cout << v[0];
			else cout << " " << v[i];
		}
		cout << " " << ba << endl;
	}
}


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

using namespace std;

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

	int ans=sum;
	vector<int> v;
	v.push_back(ans);

	for(auto a:hoge){
		int pre=ans-a;
		if(pre%10==0) pre=0;
		v.push_back(pre);
	}

	sort(v.begin(),v.end());

	cout<<(v.at(n)%10!=0 ? v.at(n) : v.at(n-1))<<endl;

	return 0;
}


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

int rnum[4][3][10];

int main(void)
{
	int n;
	int b, f, r, v;
	int i, j, k, l;
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		rnum[b - 1][f - 1][r - 1] += v;
	}
	
	for (i = 0; i < 4; i++){
		for (j = 0; j < 3; j++){
			for (k =  0; k < 10; k++){
				cout << " " <<  rnum[i][j][k];
			}
			cout << endl;
		}
		if (i < 3){
			for (l = 0; l < 20; l++){
				cout << "#";
			}
			cout << endl;
		}
	}
	
	return (0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath> 
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
int main()
{
	int a=0,b=0;
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0||a==0||b==0)
	{
		cout<<"Zero\n";
		return 0;
	}
	else if(a>0&&b>0)
	{
		cout<<"Positive\n";
		return 0;
	}
	else if(a<0&&b<0&&(b-a+1)%2==0)
	{
		cout<<"Positive\n";
		return 0;
	}
	else
	{
		cout<<"Negative\n";
		return 0;
	}
	return 0;
} 

Measured memory_bytes: 256
K = int(input())
global cnt
cnt = 9
def func(cur, d):
    global cnt
    c = cur % 10
    for i in range(0 if c==0 else c-1, 10 if c==9 else c+2):
        if d == 1:
            cnt += 1 
            if cnt == K:
                print(cur*10+i)
                exit()
        else:
            func(cur*10+i, d-1)

if K <= 9:
    print(K)
else:
    for d in range(2, 11):
        for i in range(1, 10):
            func(i, d-1)


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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll m ,n;
    cin>>m>>n;
    ll a[n];
    ll ans = 0;
    if(m==2){
        ll ret = 0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
        }
        for(int i=0;i<n;i++){
            if(a[i] != i%2)ans++;
            else ret++;
        }
        ans = min(ans,ret);
        cout << ans << endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i && a[i]==a[i-1]){
            ans++;
            a[i] = -1;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3916
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define LB lower_bound
#define UP upper_bound
#define INF 999999999999
const double PI = acos(-1.0);
ll x;

ll Pow(ll n, ll cnt){
    ll ret = 1;
    rep2(i,1,cnt) ret *= n;
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> x;
    for(ll i = -200; i <= 200; i++)
        for(ll j = -200; j <= 200; j++){
            ll ret = (i-j)*(Pow(i,4)+Pow(i,3)*j+Pow(i,2)*Pow(j,2)+Pow(j,3)*i+Pow(j,4));
            if(ret == x){
                cout << i << ' ' << j;
                return 0;
            }
        }
    return 0;     
}


Measured memory_bytes: 3644
from math import factorial as fac
def main():
    n,m=map(int,input().split())
    if abs(n-m)>1:
        print(0)
        exit()
    elif n==m:
        print((fac(n)*fac(m)*2)%(10**9+7))
    else:
        print((fac(n)*fac(m))%(10**9+7))
main()

Measured memory_bytes: 5184
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
	int n,m,i,j,k,d[110][110],a[1010],b[1010],c[1010],s=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n*n;i++)d[i%n][i/n]=(i%(n+1))?1e9:0;
	for(i=0;i<m;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		a[i]--;
		b[i]--;
		d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++)d[j][k]=MIN(d[j][k],d[j][i]+d[i][k]);
		}
	}
	for(i=0;i<m;i++){
		if(c[i]-d[a[i]][b[i]])s++;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	float hill[100];
	int i = 0, flag = 0;
	float max = 0.0, min = 1000000.0;
	float ans;
	
	while (scanf("%f", &hill[i]) != EOF){
		if (hill[i] <= min){
			min = hill[i];
		}
		if (max <= hill[i]){
			max = hill[i];
		}
//		printf("** %f ** %f **\n", min, max);
		i++;
	}
	
	ans = max - min;
	
	printf("%.1f\n", ans);
	
	return (0);
}

Measured memory_bytes: 0
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math : abs;

void main()
{
	auto N = to!int(split(readln())[0]);
	int[] A = [0];
	A ~= to!(int[])(split(readln()));
	
	int X = 0;
	
	foreach (i; 0..N) {
		X += abs(A[i] - A[i+1]);
	}
	X += abs ( A[$-1] - A[0] );
	
	foreach ( i; 1..N ) {
		writeln(X - abs(A[i] - A[i-1]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]));
	}
	
	writeln(X - abs(A[N] - A[N-1]) - abs(A[N] - A[0]) + abs(A[N-1] - A[0]));
}

Measured memory_bytes: 5496
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int n, a[1010][1010], idx[1010] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    for (int i = 0; i < 500000; i++) {
        bool v[1010] = {};
        int k = 0;
        for (int j = n - 1; j >= 0; j--) {
            int l = a[j][idx[j]];
            if (idx[j] < n - 1 && idx[l] < n - 1 && !v[j] && !v[l] && j == a[l][idx[l]]) {
                idx[l]++;
                idx[j]++;
                v[j] = v[l] = true;
                k++;
            }
        }
        bool ok = true;
        for (int j = 0; j < n; j++) {
            if (idx[j] != n - 1) ok = false;
        }
        if (ok) {
            cout << i + 1 << endl;
            return 0;
        }
        if (k == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

/* 
g++ -std=c++14 main.cpp
*/

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

void preParse(int u, int L[], int R[]) {
	int l, r;
	if (u == -1) return;
	cout <<" "<< u;
	l = L[u];
	r = R[u];
	preParse(l, L, R);
	preParse(r, L, R);
}
void inParse(int u, int L[], int R[]) {
	int l, r;
	if (u == -1) return;
	l = L[u];
	r = R[u];
	inParse(l, L, R);
	cout << " " << u;
	inParse(r, L, R);
}
void postParse(int u, int L[], int R[]) {
	int l, r;
	if (u == -1) return;
	l = L[u];
	r = R[u];
	postParse(l, L, R);
	postParse(r, L, R);
	cout << " " << u;
}

int main() {
	int i, id, left, right,n,u;
	int I[10000], L[10000], R[10000];

	cin >> n;
	for (i = 0; i < n; i++) I[i] = -1;
	
	for (i = 0; i < n; i++) {
		cin >> id >> left >> right;
		L[id] = left;
		R[id] = right;
		if (left != -1) I[left] = id;
		if (right != -1) I[right] = id;
	}
	for (i = 0; i < n; i++) if (I[i] == -1) u = i;

	cout << "Preorder" << endl;
	preParse(u,L,R);
	cout << endl;
	cout << "Inorder" << endl;
	inParse( u, L,  R);
	cout << endl;
	cout << "Postorder" << endl;
	postParse( u, L, R);
	cout << endl;

}

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

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

#define ira(a, b, c) (a <= b && b < c)

int main(){
    int n, m;
    cin >> n >> m;
    char arr[n][m];
    bool vis[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> arr[i][j];
        }
    }
    int ans = 0;
    for(int x = 0; x < n; x++){
        for(int y = 0; y < m; y++){
            if(arr[x][y] == '#') continue;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    vis[i][j] = (arr[i][j] == '#');
                }
            }
            queue< pair<int,int> > q;
            q.push({ x, y });
            vis[x][y] = 1;
            int r = 0;
            while(q.size()){
                int ps = q.size();
                while(ps--){
                    int vi = q.front().first, vj = q.front().second;
                    q.pop();
                    for(int i = 0; i < 4; i++){
                        if(ira(0, vi+dx[i], n) && ira(0, vj+dy[i], m) && !vis[vi + dx[i]][vj + dy[i]]){
                            vis[vi+dx[i]][vj+dy[i]] = 1;
                            q.push({ vi + dx[i], vj + dy[i] });
                        }
                    }
                }
                r++;
            }
            ans = max(ans, r-1);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define mod 1000000007
#define MAXX  1e18
#define MINN -1e18
 
#define ll long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define add(a, b) (((a)%mod + (b)%mod + mod)%mod)
#define mul(a, b) (((a)%mod * (b)%mod) % mod)
#define endl cout<<"\n";
#define debug(vari) cerr<< "["<< #vari << "" << (vari) << "]";endl;
#define read(a) for(auto &i: a) cin >> i;
#define out(a)  for(auto i: a) cout << i << " ";endl
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
using namespace __gnu_pbds;
using namespace std;
 
int main() {
    fastio
    int n, k; cin >> n >> k;
    vector<int> a(n); read(a);
    int ans = ((n-1)%(k-1) == 0) ? (n-1)/(k-1) : (n-1)/(k-1) + 1;
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair <int, int> node;
template <typename T> inline void read(T &x)
{
	int f = 1; x = 0; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	x *= f;
}
const int N = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int dx[] = { -2, -1, 0, 1, 2 };
const int dy[] = { -2, -1, 0, 1, 2 };
const int ddx[] = { -1, 0, 1, 0 };
const int ddy[] = { 0, 1, 0, -1 };
int n, m, sx, sy, ex, ey, F[N][N];
char str[N][N];
deque <node> q;
inline bool vaild(int x, int y)
{
	if (x < 1 || x > n || y < 1 || y > m) return 0;
	return str[x][y] == '.';
}
inline void spfa()
{
	memset(F, 0x3f, sizeof(F));
	if (str[sx][sy] == '#' || str[ex][ey] == '#') return;
	F[sx][sy] = 0; q.push_back(make_pair(sx, sy));
	
	int x, y;
	while (!q.empty())
	{
		x = q.front().first; y = q.front().second; q.pop_front();
		for (int i = 0; i < 4; i++)
		{
			int tx = x + ddx[i], ty = y + ddy[i];
			if (!vaild(tx, ty)) continue;
			if (F[x][y] < F[tx][ty])
			{
				F[tx][ty] = F[x][y];
				q.push_front(make_pair(tx, ty));
			}
		}
		for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++)
		{
			int tx = x + dx[i], ty = y + dy[j];
			if (!vaild(tx, ty)) continue;
			if (F[x][y] + 1 < F[tx][ty])
			{
				F[tx][ty] = F[x][y] + 1;
				q.push_back(make_pair(tx, ty));
			}
		}
	}
}
int main(){
	read(n); read(m); read(sx); read(sy); read(ex); read(ey);
	for (int i = 1; i <= n; i++) scanf ("%s", str[i] + 1);
	spfa();
	if (F[ex][ey] == inf) puts("-1");
	else printf ("%d\n", F[ex][ey]);
  return 0;
}

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

int main()
{
int t,i;
cin>>t;
int arr[t],arr1[t];
for(i=0;i<t;i++)
{
    cin>>arr[i];
    arr1[i]=arr[i];
}



   sort(arr,arr+t,greater<int>());
for(i=0;i<t;i++)
{
    if(arr1[i]==arr[0])
    cout<<arr[1]<<endl;
   else
    cout<<arr[0]<<endl;
}



 return 0;

}




Measured memory_bytes: 3200
#include<stdio.h>
int main(){
  double x1,x2,x3,x4,y1,y2,y3,y4;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf"
	      ,&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){
    if(((x1<=x3&&x3<=x2)||(x3<=x2&&x2<=x4)||(x1<=x4&&x4<=x2)||(x3<=x1&&x1<=x4))
     &&((y1<=y3&&y3<=y2)||(y3<=y2&&y2<=y4)||(y1<=y4&&y4<=y2)||(y3<=y1&&y1<=y4))){
      printf("YES\n");
    }
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	int d, x;
	cin >> d >> x;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int ans = x;

	
	rep(i, n){
		int t = 1;
		ans++;
		while(t + a[i] <= d){
			t += a[i];
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma") 
 
#include<bits/stdc++.h>
 
#define CFOR(i, str) for(int i = 0; (str)[i]!='\0'; (i)++)
#define FOR(i, s, r) for(int i = (s); i < (r); i++)
#define INF 1e9
#define NINF -1e9
#define SUM(a) accumulate(a.begin(), a.end(), 0)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.rbegin(), v.rend())
#define vmax(v) *max_element(v.begin(), v.end())
#define vmin(v) *min_element(v.begin(), v.end())
#define cnt(v, n) count(v.begin(), v.end(), (n))
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vpic vector<pair<int, char>>
#define mp make_pair
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end()); //+ve = right, -ve = left
#define lld long long int
#define ulld unsigned long long int
typedef long long ll;
using namespace std;
 
ll binpow(ll a, ll b) { 
ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;
}
 
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
 
bool isPrime(ll n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n % 2 == 0 || n % 3 == 0) return false; 
    for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; 
    return true; 
}
void solve(){
      lld n,m;
    cin>>n>>m;
    lld ans=ceil((double)n/m);
    cout<<ans;
}
int main(){
   ios::sync_with_stdio(0);
   cin.tie(0);
   ll t;
   t=1;
   while(t--)
   { 
   solve();
   }
   return 0;
}

Measured memory_bytes: 3616