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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);

    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h.begin(), h.end());

//    int cnt = n - k + 1;
//    vector<int> k_cnt(k);
    int l = k - 1;
    int tmp;
    int ini = h[l] - h[0];
    for(int j = 0; j < n - l; j++){
        tmp = h[j + l] - h[j];
        if(tmp < ini){
            ini = tmp;
        }
    }
    cout << ini << endl;

}

Measured memory_bytes: 640
package main

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

func solve() {
	type hand struct {
		win, lose rune
	}
	hs := map[rune]hand{
		'r': {win: 's', lose: 'p'},
		's': {win: 'p', lose: 'r'},
		'p': {win: 'r', lose: 's'},
	}

	n, k := getInt(), getInt()
	score := make(map[rune]int)
	score[hs['r'].win] = getInt()
	score[hs['s'].win] = getInt()
	score[hs['p'].win] = getInt()
	t := getRunes()

	ans := 0
	before := make([]rune, n)
	for i := range before {
		before[i] = ' '
	}
	for i, c := range t {
		if before[i] == c {
			continue
		}

		ans += score[c]
		if i+k < n {
			before[i+k] = c
		}
	}
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

using namespace std;
#define N 200200

vector<int> a[N];
int sel[N], freq[N];
void df (int x, int val) {
    ++freq[val];
    sel[x] = 1;
    for (int it = 0; it < a[x].size(); ++it)
    if (!sel[a[x][it]]){
        df(a[x][it], val);
    }
}

int cnt, ans, i, n, m, x, y;
int main(){
    cin >> n >> m;
    for (i = 0; i < m; ++i){
        cin >> x >> y;
        --x; --y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    cnt = 0;
    for (i = 0; i < n; ++i) {
        if (!sel[i]){
            df(i, cnt);
            ans = max(ans, freq[cnt]);
            ++cnt;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 24692
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<int> v;

int main(){
  cin>>N;
  v.push_back(0);
  for(int i=0;i<N;i++){
    int X;cin>>X;
    v.push_back(X);
  }
  v.push_back(0);
  
  int ans = 0;
  while(true){
  	int nnz = 0;
    int vi1 = -1;
    for(int i=0;i<N+2;i++){
      if(v[i]==0&&vi1!=0&&i!=0){
        ans++;// cout<<"** ans++ at "<<i<<endl;
      }
      vi1 = v[i];
      if(v[i]!=0){ v[i]--; nnz++; }
    }
    //for(int i=0;i<N;i++){ cout<<v[i]<<" "; } cout<<endl;
    if(nnz==0){
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), X = ip[0], Y = ip[1], Z = ip[2];
	swap(X, Y);
	swap(X, Z);
	"%d %d %d".writefln(X, Y, Z);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#define ll long long
#define F(i,s,t) for(int i=s;i<=t;i++)
#define DF(i,s,t) for(int i=s;i>=t;i--)
#define mp make_pair
using namespace std;
map<pair<string,string>,ll>sa;
char s[233];
ll sum=0;
int n;
string a,b;

int main(){
	scanf("%d",&n);
    scanf("%s",s);
    F(i,0,(1<<n)-1){
        a="",b="";
        F(j,0,n-1){
            if(i&(1<<j)) a+=s[j];
            else b+=s[j];
        }
        sa[mp(a,b)]++;
    }
    F(i,0,(1<<n)-1){
        a="",b="";
        DF(j,n-1,0){
            if(i&(1<<j)) b+=s[j+n];
            else a+=s[j+n];
        }
        sum+=sa[mp(a,b)];
    }
    printf("%lld\n",sum);
    return 0;
}

/*


*/


Measured memory_bytes: 91904
/*input
5
1 2 3 4 5 
*/

#include <bits/stdc++.h> 

using namespace std;

int n;
deque<int> dq;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x; scanf("%d", &x);
		if ((i & 1) == (n & 1)) dq.push_front(x);
		else dq.push_back(x);
	}
	for (int x : dq) printf("%d ", x);
}

Measured memory_bytes: 2944
import Data.List
main :: IO ()
main = do
  (n:x:_) <- fmap (map read . words) getLine :: IO [Int]
  as <- fmap (map read . words) getLine :: IO [Int]
  print $ solve x as

solve :: Int -> [Int] -> Int
solve x as
  | x == sumas = length as
  | x > sumas = length as - 1
  | otherwise = count 0 x (sort as)
  where
    sumas = sum as
    count n acc [] = if acc == 0 then n else (n - 1)
    count n acc (a:as)
      | acc == 0 = n
      | acc < 0 = n - 1
      | otherwise = count (n+1) (acc - a) as


Measured memory_bytes: 1020
N = gets.to_i
W = gets.split.map(&:to_i)

min = Float::INFINITY

N.times do |i|
    break if i == N - 1

    if (W[0..i].inject(:+) - W[i+1..(-1)].inject(:+)).abs <= min
        min = (W[0..i].inject(:+) - W[i+1..(-1)].inject(:+)).abs
    end
end

puts min



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

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

    vector<ll> V(N);
    rep(i,N){
        cin >> V[i];
    }

    ll max_val = 0;

    rep(i,K+1){
        vector<int> selected(i,0);
        
        if(i <= N){
            for(int j = 0;j <= i;j++){
                for(int k = 0;k < j;k++){
                    selected[k] = V[k];
                }

                for(int k = j;k < i;k++){
                    selected[k] = V[N - 1 - k + j];
                }

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

                int loop = min(i, K - i);

                for(int j = 0;j < loop;j++){
                    if(selected[j] < 0){
                        selected[j] = 0;
                    }else{
                        break;
                    }
                }

                ll sum = 0;
                for(int j = 0;j < i;j++){
                    sum += selected[j];
                }

                max_val = max(max_val,sum);


            }
        }else{
            for(int j = 0;j < N;j++){
                selected[j] = V[j];
            }

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

            int loop = min(i, K - i);

            for(int j = 0;j < loop;j++){
                if(selected[j] < 0){
                    selected[j] = 0;
                }else{
                    break;
                }
            }

            ll sum = 0;
            for(int j = 0;j < i;j++){
                sum += selected[j];
            }

            max_val = max(max_val,sum);
        }

    }

    cout << max_val << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <iostream>
using namespace std;
using Map = map< vector<int>, int >;

int N;

vector<int> flip(vector<int> &vec, int &l, int &r) {
    vector<int> ret = vec;

    for(int i=l; i<=r; i++) {
        int il = i, ir = r - (i-l);
        if(il >= ir) break;

        swap(ret[il], ret[ir]);
    }
    return ret;
}

int solve(vector<int> &init, vector<int> &term, Map &cur, Map &pre) {
    int ret = N - 1;
    queue< vector<int> > que;
    que.push(init);

    while(que.size()) {
        vector<int> vec = que.front(); que.pop();
        if(pre.count(vec)) {
            ret = min(ret, cur[ vec ] + pre[ vec ]);
        }
        if(cur[ vec ] >= (N - 1) / 2) continue;

        for(int l=0; l<N; l++) {
            for(int r=l+1; r<N; r++) {
                vector<int> nxt = flip(vec, l, r);
                if(cur.count(nxt)) continue;
                cur[ nxt ] = cur[ vec ] + 1;
                que.push(nxt);
            }
        }
    }

    return ret;
}

int main() {
    scanf("%d", &N);
    vector<int> perm(N);
    for(int i=0; i<N; i++) {
        scanf("%d", &perm[i]);
    }

    vector<int> term(N);
    iota(term.begin(), term.end(), 1);

    Map ml, mr;
    ml[ perm ] = 0;
    mr[ term ] = 0;

    int ans = N - 1;
    ans = min(ans, solve(perm, term, ml, mr));
    ans = min(ans, solve(term, perm, mr, ml));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 83224
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);

$answer = "No";

$lenS = strlen($S);
for ($i = 0; $i < $lenS; $i++) {
    $tmp = substr($S, $i) . substr($S, 0, $i);
    if ($tmp === $T) {
        $answer = "Yes";
    }
}

echo $answer . PHP_EOL;

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main()
{
    ll n; cin >> n;
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
}


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


int n;
//int a[1000001];
//int b[1000001];
pair<int,int> probs[1001];
// iÔÚÜÅÌàÌ©çjÂIÔÌÉKvÈÅ¬Ô
int dp[1001][1001];
const int INF=1000000000;

int main(){
    cin>>n;
    for(int i = 0; i < 1001; i++)for(int j = 0; j < 1001; j++)dp[i][j]=INF;
    for(int i = 0; i < n; i++)
        cin>>probs[i].second>>probs[i].first;
    sort(probs,probs+n);
    dp[0][0]=0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 1001; j++){
            if(j==0){
                dp[i+1][j]=dp[i][j];
            }
            else if(dp[i][j-1]+probs[i].second<=probs[i].first)
                dp[i+1][j]=min(dp[i][j],dp[i][j-1]+probs[i].second);
            else
                dp[i+1][j]=dp[i][j];
        }
    }

    for(int i = n; i >= 0; i--){
        if(dp[n][i]!=INF){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}

//int n;
//class Data{
//public:
//    int a,b;
//    bool operator<(const Data &d)const{
//        return this->a>d.a;
//    }
//};
//Data datas[1000001];
//
//bool cmp(const Data &d,const Data &d2){
//    return d.b<d2.b;
//}
//
//int main(){
//    cin>>n;
//    int ct=0;
//    for(int i = 0; i < n; i++){
//        cin>>datas[i].a>>datas[i].b;
//        ct=max(ct,datas[i].b);
//    }
//    sort(datas,datas+n,cmp);
//    int maxCnt=0;
//
//    for(int k = 0; k < n; k++){
//    priority_queue<Data> pq;
//    int idx=n-1-k;
//    for(int k = n-1; k > idx; k--){
//        pq.push(datas[k]);
//    }
//    int cnt=0;
//    ct=datas[idx].b;
//    while(1){
//        for(int i = idx; i >= 0; i--){
//            if(datas[i].b>=ct)
//                pq.push(datas[i]);
//            else{
//                idx=i;
//                break;
//            }
//            if(i==0)
//                idx=-1;
//        }
//        if(pq.size()==0){
//            if(idx==-1)
//                break;
//            // »ÝÉàÁÆàß¢àÌðâ[
//            ct=datas[idx].b;
//            for(int i = idx; i >= 0; i--){
//                if(datas[i].b==ct)
//                    pq.push(datas[i]);
//                else{
//                    idx=i;
//                    break;
//                }
//                if(i==0)
//                    idx=-1;
//            }
//            if(pq.size()==0)
//                break;
//        }
//        bool ok=false;
//        Data dd;
//        while(pq.size()){
//            dd=pq.top();
//            pq.pop();
//            ok=true;break;
//        }
//        if(!ok)
//            break;
//        ct-=dd.a;
//        if(ct<0)
//            break;
//        cnt++;
//        if(ct==0)
//            break;
//    }
//    maxCnt=max(maxCnt,cnt);
//    }
//    cout<<maxCnt<<endl;
//
//    return 0;
//}

Measured memory_bytes: 0
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let ans = if (a * b) % 2 == 0 { "No" } else { "Yes" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct BINNODE {
	int key;
	BINNODE *parent;
	BINNODE *left;
	BINNODE *right;

	BINNODE (int k) {
		key=k;
		parent=nullptr;
		left=nullptr;
		right=nullptr;
	}
};

void preorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	printf(" %d",root->key);
	preorderwalk(root->left);
	preorderwalk(root->right);
	return;
}

void inorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	inorderwalk(root->left);
	printf(" %d",root->key);
	inorderwalk(root->right);
	return;
}

bool findnode(int v, BINNODE* root) {
	if(root == nullptr) return false;
	if(root->key ==v ) return true;
	return (v< root->key)?findnode(v,root->left) : findnode(v,root->right);
}

int main() {
	int m,v;
	int i;
	string cmd;
	BINNODE* root=nullptr;
	BINNODE* x;
	BINNODE* y;
	BINNODE* z;
	cin >> m;
	for(i=0; i<m; ++i) {
		cin >> cmd;
		if(cmd=="find") {
			cin >> v;
			printf(findnode(v,root) ? "yes\n" : "no\n");
		} else if(cmd=="insert") {
			cin >> v;
			z=new BINNODE(v);
			y=nullptr;
			x=root;
			while(x!=nullptr) {
				y=x;
				if (z->key < x->key) {
					x=x->left;
				} else {
					x=x->right;
				}
			}
			z->parent = y;

			if(y==nullptr) {
				root=z;
			} else if(z->key < y->key) {
				y->left = z;
			} else {
				y->right = z;
			}
		} else {
			inorderwalk(root);
			printf("\n");
			preorderwalk(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 21928
words = ["dream", "dreamer", "erase","eraser"]
reverse_words = []
for word in words:
    reverse_words.append(word[::-1])
S = input()
S = S[::-1]

while len(S) !=0:
    flag = 0
    for word in reverse_words:
        if S.startswith(word):
            S = S[len(word):]
            flag=1
            break
    if (not flag):
        print("NO")
        quit()
print("YES")


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#include <functional>
#include <map>
#include <queue>
using namespace std;
vector<int> v;
int ans[100001];
int main()
{
  v.push_back(1);
  int x=1,y=1;
  for (int i=1;i<8;i++)
  {
    x*=6;
    y*=9;
    v.push_back(x);
    v.push_back(y);
  }
  int N;
  cin>>N;
  memset(ans,-1,sizeof(ans));
  queue<int> q;
  q.push(0);
  ans[0]=0;
  while (!q.empty())
  {
    int z=q.front();
    q.pop();
    for (int i=0;i<v.size();i++)
      if (z+v[i]<=N&&ans[z+v[i]]<0) {q.push(z+v[i]);ans[z+v[i]]=ans[z]+1;}
  }
  cout<<ans[N]<<endl;
  //system("pause");
  return 0;
}

Measured memory_bytes: 768
N=int(input())
A=list(map(int, input().split()))

memo=[0]*(10**5)
answer=0

for a in A:
  memo[a]+=1
  
for i in range(10**5-2):
  answer=max(answer, memo[i]+memo[i+1]+memo[i+2])
  
print(answer)

Measured memory_bytes: 14008
import fractions as fr
import functools as ft
#import math as fr


prime = 10**9+7

n = int(input())
an = list( map( int, input().split() ))

an.sort()


lcm_ = 1
for a in an :
    lcm_ = a*lcm_ // fr.gcd(a, lcm_)
#    print(lcm_)
    
#ans = 0
#for a in an:
#    ans += lcm_ // a
#    ans = ans % prime if ans >= prime else ans

ans = ft.reduce(lambda x,y: (x + lcm_//y), an ,0 )

print(ans%prime)

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

int main () {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
  int xc = k;
  cout << xa-xc << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;
const double PI = 3.14159265358979323846;

int main()
{
	int N, M, a=0;
	vector<int> A;

	cin >> N >> M;

	A.resize(M);

	for (int i = 0; i < M; i++)
	{
		cin >> A[i];
	}

	for (int i = 0; i < M; i++)
	{
		a += A[i];
	}

	int rest;
	rest = N - a;

	if (rest >= 0)
		cout << rest;
	else
		cout << -1;

	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MOD = 1000000007;
vector<ll> fact,fact_inv,inv;

/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}


int main() {
	int x,y;
	cin >> x >> y;
	if((x+y)%3) {
		cout << 0 << endl;
		return 0;
	}
	int n = (x+y)/3;
	x -= n;y -= n;
	if(x < 0 || y < 0) {
		cout << 0 << endl;
		return 0;
	}
	init_nCk(x+y);
	cout << nCk(x+y,y) << endl;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  int ans = 0;
  ll h_0;
  ll h_1;
  int count = 0;
  cin >> h_0;
  REPI(i, 1, N) {
    cin >> h_1;
    if (h_1 <= h_0) {
      ++count;
    } else {
      ans = max(ans, count);
      count = 0;
    }
    h_0 = h_1;
  }
  if (count != 0) {
    ans = max(ans, count);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
long long k,kk;
vector <long long> v;
map <long long ,long long> mp;
int main()
{
	cin>>k;
	for (long long i=1; i<=10; i++)
	{
		v.push_back(i);
		mp[i]=1;
	}
		for (long long i=0; i<v.size(); i++)
		{
			kk=v[i];
			//if (kk==3234566667) cout<<i<<endl;
			if (mp[kk*10+(kk%10-1)]==0)
			{
				//cout<<kk*10+(kk%10-1)<<endl;
			if (kk%10!=0)
			{
			v.push_back(kk*10+(kk%10-1));
			mp[kk*10+(kk%10)-1]=1;
			}
			}
			if (mp[kk*10+(kk%10)+1]==0)
			{
			if (kk%10!=9) 
			{
			v.push_back(kk*10+(kk%10)+1);
			mp[kk*10+(kk%10)+1]=1;
			}
			}
			if (mp[kk*10+(kk%10)]==0)
			{
				v.push_back(kk*10+kk%10);
				mp[kk*10+(kk%10)]=1;
			}
			if (v.size()>=k+100000) break;
		}
		
		sort(v.begin(),v.end());
		for (long long i=0; i<v.size(); i++)
		{
			//cout<<v[i]<<" ";
		}
		cout<<v[k-1]<<endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, p;

	cin >> n;

	ll cnt = 0;

	REP(i, n) {
		cin >> p;
		if (p != i + 1) {
			cnt++;
		}
	}

	if (cnt == 2 || cnt == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
void c()
{
    long long int n;
    cin >>n;
    long long int m = (long long int)sqrt(n);
    for(long long int i=m;i>=1;i--)
    {
        if(n%i==0)
        {
        cout << (i-1)+(n/i-1);
        return;
        }
    }

}
void b()
{
    int n;
    cin >>n;
    for(int i=1;i<10;i++)
    {
        if(n%i ==0)
     if(n/i<10)
     {
     cout<< "Yes";
     return;
     }

    }
    cout<<"No";
    return;
    


}
void a()
{
    int a,b;
    cin >>a>>b;
    if(a<10 && b<10)
    cout << a*b;
    else cout << -1;
    return;

}
int main(void){
    //a();
    //b();
    c();
    //d();
    return 0;
}

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

int n, m;
char a[59][59], b[59][59];

bool check(int t, int l){
    for(int i=0; i<m; i++)
        for(int j=0; j<m; j++)
            if(a[t+i][l+j] != b[i][j]) return false;
    return true;
}

int main(){
    scanf("%d %d ",&n,&m);
    for(int i=0; i<n; i++)
        scanf("%s", a[i]);
    for(int i=0; i<m; i++)
        scanf("%s", b[i]);

    for(int i=0; i < n-m+1; i++)
        for(int j=0; j < n-m+1; j++)
            if(check(i,j)){
                printf("Yes\n");
                return 0;
            }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    priority_queue<int> q;
    long long ans = a[0];
    q.push(a[1]);
    q.push(a[1]);
    for(int i=2;i<n;i++){
        int x = q.top();
        q.pop();
        ans += x;
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << ans << endl;
}


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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(const char* s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(char s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int64 s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    cout << "(";
    print(p.first, false);
    cout << ", ";
    print(p.second, false);
    cout << ")";

    if (endline) print();
}

template <typename T>
void print(T& t, bool endline = true) {
    cout << "[";
    for (auto it = t.begin(); it != t.end(); ++it) {
        if (it != t.begin()) cout << ", ";
        print(*it, false);
    }
    cout << "]";

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

bool c(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.first + a.second > b.first + b.second); 
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int64 n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    vector<int> arr;

    int cur = 0;
    char prev = s[0];

    for(auto& c : s) {
        if(c == prev) {
            cur++;
        } else {
            prev = c;
            arr.push_back(cur);
            cur = 1;
        }
    }

    if(cur != 0) {
        arr.push_back(cur);
    }

    vector<pair<int, int>> window;

    window.push_back({-(arr[0] + arr[1]), 0});
    for(int i = 1; i < (int) arr.size() - 1; ++i) {
        window.push_back({-(arr[i - 1] + arr[i] + arr[i + 1]), i});
    }

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

    // print(arr);
    // print(seen);

    int count = 0;
    for(int i = 1; i < (int) arr.size() and count < k; i += 2) {
        if (i < (int) arr.size() - 1) {
            arr[i] += arr[i + 1];
            arr[i + 1] = 1;
        }

        arr[i] += arr[i - 1];
        arr[i - 1] = 1;

        count++;
    }

    // print(arr);
    int ret = 0;

    for(auto& c : arr) {
        ret += max(0, c - 1);
    }

    print(ret);

    return 0;
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 405;
int n;
ll a[maxn], sum[maxn], dp[maxn][maxn];
ll get(int l, int r){return sum[r]-sum[l-1];}

ll solve(int l, int r){
	if (l == r) return 0;
	ll &ret = dp[l][r];
	if (ret != -1) return ret;
	ret = 1e18;
	for(int i = l; i<=r; i++) ret = min(ret, solve(l,i)+solve(i+1, r));
	return ret+=get(l, r);
}

int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &n);
	for(int i = 1; i<=n; i++) scanf("%lld", &a[i]), sum[i] = a[i] + sum[i-1];
	printf("%lld\n", solve(1, n));
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b-1);i>=(a);i--)
#define all(V) V.begin(),V.end()
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a
typedef long long ll;
typedef pair<int ,int > pii;
typedef vector<int> vi;
//----

const int N=2e5+5;
const int mod=1e9+7;
int data[N];
ll pre[N];
int main()
{
	int n;
	scanf("%d",&n);
	rep(i,1,n+1)scanf("%d",&data[i]),pre[i]=pre[i-1]+data[i];
	ll Ans=1e18;
	rep(i,2,n-1)
	{
		int l1=1,r1=i-1,l2=i+1,r2=n-1;
		while(l1<r1)
		{
			int mid=(l1+r1)/2;
			if(2*pre[mid]<pre[i])l1=mid+1;
			else r1=mid;
		}
		if(l1>1&&pre[i]-2*pre[l1-1]<2*pre[l1]-pre[i])l1--;
		while(l2<r2)
		{
			int mid=(l2+r2)/2+1;
			if(2*(pre[mid]-pre[i])>pre[n]-pre[i])r2=mid-1;
			else l2=mid;
		}
		if(r2<n&&pre[n]-pre[i]-2*(pre[r2]-pre[i])>2*(pre[r2+1]-pre[i])-(pre[n]-pre[i]))r2++;
		Ans=min(Ans,max(max(pre[l1],pre[i]-pre[l1]),max(pre[r2]-pre[i],pre[n]-pre[r2]))-min(min(pre[l1],pre[i]-pre[l1]),min(pre[r2]-pre[i],pre[n]-pre[r2])));
	}
	cout<<Ans<<endl;
	return 0;	
}

Measured memory_bytes: 2560
a,b,k = map(int,input().split())
from_a = set(list(range(a,a+k)))
from_b = set(list(range(b,b-k,-1)))
ab= from_a | from_b
#print(ab)
list_ab = list(ab)
list_ab.sort()
#print(list_ab)
for i in list_ab:
    if a<= i <= b:
        print(i)


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	if n < 3 {
		fmt.Println(0)
		return
	}
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	
	ans := 0
	for i := 0; i < n - 2; i++ {
		for j := i+1; j < n -1; j++ {
			if arr[i] == arr[j] {
				continue
			}
			for k := j+1; k < n; k++ {
				if arr[j] == arr[k] {
					continue
				}
				if arr[i] + arr[j] > arr[k] {
					ans ++
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1844
n = int(input())
h = list(map(int,input().split()))
w = 0
a = True

while a:
    mizu = False
    if sum(h) == 0:
        a = False
        break

    w += 1
    for i in range(n):
        if h[i] != 0:
            h[i] -= 1
            mizu = True
        else:
            if mizu:
                break 


print(w)

Measured memory_bytes: 9184
use proconio::{fastout, input};
use std::mem::swap;

#[fastout]
fn main() {
    input! {
        mut x: i32,
        mut y: i32,
        mut z: i32,
    }

    swap(&mut x, &mut y);
    swap(&mut x, &mut z);

    println!("{} {} {}", x, y, z);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll x, y;
  cin >> x >> y;
  if (y > x) {
    cout << min(x, y - x) << endl;
  } else {
    ll t1 = x % y;
    cout << min(t1, abs(t1 - y)) << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n, x;
	public void run(){
		n = sc.nextInt();
		x = sc.nextInt();
		solve();
	}
	public void solve(){
		int minm = Integer.MAX_VALUE;
		int ans = 0;
		for(int i = 0; i < n; i++){
			int m = sc.nextInt();
			if(minm > m) minm = m;
			
			x = x - m;
			ans = ans + 1;
		}
		
		ans += x / minm;
		
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;


const int INF = 1 << 29;
int main(){
    while(true){
        int N,M;
        cin >> N >> M;
        if(N == 0 and M == 0) break;

        vector<int> C(M);
        for(int i=0;i<M;i++) cin >> C[i];

        vector<int> DP(256,INF);
        DP[128] = 0;
        for(int ind_n=0;ind_n<N;ind_n++){
            vector<int> NEX(256,INF);
            int x;
            cin >> x;
            for(int j=0;j<=255;j++){
                for(int i=0;i<M;i++){
                    if(DP[j] != INF){
                        int now = j + C[i];
                        if(now < 0) now = 0;
                        else if(now > 255) now = 255;
                        NEX[now] = min(NEX[now],DP[j]+(now-x)*(now-x));
                    }
                }
            }
            DP = NEX;
        }

        int mix = INF;
        for(int i=0;i<=255;i++){
            mix = min(DP[i],mix);
        }
        cout << mix << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w; 
	cin >> h >> w;
	int m;
	cin >> m;
	int mxr = 0, mxc = 0;
	vector<int> row(h), col(w);
	vector<pair<int, int>> v;
	for (int i = 0; i < m; i++) {
		int x, y; 
		cin >> x >> y;
		--x, --y;
		mxr = max(mxr, ++row[x]);
		mxc = max(mxc, ++col[y]);
		v.emplace_back(x, y);
	}
	int inter = 0;
	for (auto [x, y] : v) {
		if (row[x] == mxr and col[y] == mxc)
			++inter;
	}
	int cnt_mxr = count(row.begin(), row.end(), mxr);
	int cnt_mxc = count(col.begin(), col.end(), mxc);
	cout << (mxr + mxc - (inter == 1ll * cnt_mxr * cnt_mxc)) << "\n";
}

Measured memory_bytes: 9792
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int h,a;
  cin >> h >> a;

  cout << h / a + (h % a == 0 ? 0 : 1);

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    cnt = 0

    for i in range(n):
        if a_list[a_list[i] - 1] - 1 == i:
            cnt += 1

    print(cnt // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 82860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   vector<int> a(3);

   cin >> a[0] >> a[1] >> a[2];

   sort(a.begin(), a.end());
   cout << a[0] + a[1] << endl;

   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>
#include<x86intrin.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nDigit,int N){      //nDigitは想定される最大桁数
    char *buf,*ptr;

    buf=(char*)malloc( (N*(nDigit+2)) * sizeof(char) );
    my_gets(buf,N*(nDigit+2),stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //b-aを返す(qsortなら4321)
    return *((int*)b)- *((int*)a);
}


int main(){
    int N;

    scanf("%d%*c",&N);
    printf("%d\n",N*N*N);
    return 0;
} 

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

signed main(void)
{
	vector<int> n(4);
	rep(i, 4) cin >> n[i];
	sort(n.begin(), n.end());
	if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
	{
		cout << "YES" << endl;
		return 0;
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for C - Modulo Summation
	var N int
	fmt.Scanf("%d", &N)

	var a int
	var ans int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a)
		ans += a
	}

	fmt.Println(ans - N)
}


Measured memory_bytes: 2048
import numpy as np
n ,d = map(int, input().split())
X = np.zeros((n,d) ,dtype=np.int) 

for i in range(n):
    X[i] = np.array( list(map(int,input().split())) )
cnt = 0
for j in range(n):
    for k in range(1,n-j):
        if (np.sqrt(sum((X[j] - X[j+k])**2))).is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 12504
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 110

using namespace std;

vector<int> G[MAX];
int remain[MAX];
int depth[MAX];

int main(){
  int T;
  cin >> T;
  while(T--){

    for(int i=0;i<MAX;i++){
      G[i].clear();
      remain[i] = 0;
      depth[i] = -1;
    }
    vector<int> record;
    vector<int> input;

    int r,cur,upper;

    while(cin >> r,r){
      input.push_back(r);
    }

    remain[0] = input[0];
    cur = 0, upper = 1, depth[0] = 0;

    for(int i=1;i<input.size();i++){
      //cout << "the input => " << input[i] << endl;
      //cout << "i = " << i << " cur = " << cur << endl;
      if( input[i] > 0 ){

	G[cur].push_back(upper);
	G[upper].push_back(cur);
	depth[upper] = depth[cur] + 1;
	remain[upper] = input[i] - 1;
	assert(remain[upper] >= 0);
	remain[cur]--;
	assert(remain[cur] >= 0);
	cur = upper++;

      } else {
	assert(depth[cur] != -1);
	int next = depth[cur] + input[i];
	for(int j=record.size()-1;j>=0;j--){
	  if(next == depth[record[j]]){
	    next = record[j];
	    break;
	  }
	}
	assert(next >= 0);
	G[next].push_back(cur);
	G[cur].push_back(next);
	remain[next]--;
	assert(remain[next] >= 0);
	remain[cur]--;
	assert(remain[cur] >= 0);

      }

      record.push_back(cur);

      for(int j=record.size()-1;j>=0;j--){
	if(remain[cur] != 0){
	  break;
	}
	cur = record[j];
      }

      //cout << "i = " << i << " become " << cur << endl;
      /*
      cout << "graph---" << endl;
      for(int j=0;j<upper;j++){
	cout << j+1;
	for(int k=0;k<G[j].size();k++){
	  cout << " " << G[j][k]+1;
	}
	cout << endl;
      }
      cout << endl;
      */
    }

    for(int i=0;i<upper;i++){
      cout << i+1;
      sort(G[i].begin(),G[i].end());
      for(int j=0;j<G[i].size();j++){
	cout << " " <<  G[i][j]+1;
      }
      cout << endl;
    }


  }
  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

char field[1005][1005];

int main(void) {
    int H, W, N; cin >> H >> W >> N;
    int SH, SW; cin >> SH >> SW;
    
    string S; cin >> S;
    string T; cin >> T;


    int left = SW;
    int right = SW;
    int flag = 1;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') right++;
        if (S[i] == 'L') left--;
        if (right > W || left < 1) {
            flag = 0;
            break;
        }
        if (T[i] == 'R' && left + 1 <= W) left++;
        if (T[i] == 'L' && right - 1 >= 1) right--;
    }
    int upper = SH;
    int lower = SH;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') upper++;
        if (S[i] == 'U') lower--;
        if (upper > H || lower < 1) {
            flag = 0;
            break;
        }
        if (T[i] == 'U' && upper - 1 >= 1) upper--;
        if (T[i] == 'D' && lower + 1 <= H) lower++; 
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

}



Measured memory_bytes: 1020
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

vector<ll> find_dividers(ll x) {
    vector<ll> dividers;

    for (ll i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
            dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}
int main() {
	fre("");
	ACCELERATE;

	int a, b;
	cin >> a >> b;
	cout << max(0, a - b - b);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++) 
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    int ans = 0;
    rep(i, N){                                    
      cin >> A[i];
    }
     rep(i, N){
        cin >> B[i];
        ans += B[i];
    }
    rep(i, N){
        cin >> C[i];
    }
    rep(i, N-1){
    if(A[i+1]==A[i]+1)ans+=C[A[i]-1];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int GetDigitsSum(int N) {
	int digitsSum = 0;
	while (N > 0) {
		digitsSum += N % 10;
		N /= 10;
	}
	return digitsSum;
}

int main()
{
	int N;
	int B;
	int A_B_DigitsSum;
	int answer = 2147483647;

	cin >> N;

	for (int A = 1 ; A <= ( N + 1 ) / 2  ; A++) {
		B = N - A;
		A_B_DigitsSum = 0;
		A_B_DigitsSum += GetDigitsSum(A);
		A_B_DigitsSum += GetDigitsSum(B);
		if ( A_B_DigitsSum < answer )
			answer = A_B_DigitsSum;		
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256