akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

#define SIZ 1000000000
#define mod 10000007

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n,m,k;
	cin >> n >> m >> k;
	
	vector<ll> u(n + 1), v(m + 1);
	u[0] = v[0] = 0;
	
	
	for(ll i = 1; i <= n; i++) cin >> u[i], u[i] += u[i - 1];
	for(ll i = 1; i <= m; i++) cin >> v[i], v[i] += v[i - 1];
	
	ll cnt = 0;
	
	ll j = m, res = 0;
	for(ll i = 0; i <= n; i++){
		if(u[i] > k) break;
		
		while(j >= 0 && u[i] + v[j] > k){
			j--;
		}
		
		cnt = max(cnt, i + j);
	}
	
	cout << cnt << "\n";
}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  int t;
  t=1;

  while(t--) {
    ll n,k;
    cin>>n>>k;

    vector<ll> v(n+1);
    v[0]=0;
    for(int i=1;i<=n;i++) {
      cin>>v[i];
    }



    ll start=1;
    ll cur=k+1;

    while(cur<=n) {
      if(v[cur]>v[start]) {
        cout<<"Yes"<<endl;
      }
      else {
        cout<<"No"<<endl;
      }
      start++;
      cur++;
    }


  }
}


Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


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

int main() {
    int x;
    cin >> x;
    if (x) cout << 0 << endl;
    else cout << 1 << endl;
}


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

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

	int N;
	cin >> N;
	int a[100];
	for(int i=0; i<N; i++) cin >> a[i];

	int res = 1000000000;
	int tot;
	for(int b=-100; b<=100; b++){
		tot = 0;
		for(int i=0; i<N; i++) tot += (a[i]-b)*(a[i]-b);
		res = min(res, tot);
	}
	cout << res;
	return 0;
}


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

int n,m;
bool b[3000]={};

int main(){
  cin>>n>>m;
  while(m--){
    int l,r;
    cin>>l>>r;
    for(int i=l;i<r;i++){
      b[i]=true;
    }
  }

  int ans=0;
  for(int i=0;i<n+1;i++){
    if(b[i]) ans+=3;
    else ans++;
  }

  cout<<ans<<endl;
}



Measured memory_bytes: 3080
#include <stdio.h>
int main(){
  int i,n,a,b=0,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==b){
      c++;
      b=0;
    }else b=a;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
int main(){
int a,b;
std::cin >> a;
std::cin >> b;
if(a < b)
std::cout << "a < b\n";
if(a > b)
std::cout << "a > b\n";
if(a == b)
std::cout << "a == b\n";
return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
typedef long long ll;

const ll inf = 1ll << 40ll;
const ll minf = -1 * (1ll << 40ll);

ll N, K;
ll v[55];

ll calc(int pos, int len, int k);
ll msum(int pos, int len, int k);

int main()
{
    ll ans = 0;
    
    scanf("%lld %lld", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &v[i]);
    }

    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= i && i + j <= K; j++) {
            for (int k = 0; i + j + k <= K; k++) {
                for (int l = 0; l <= k && i + j + k + l <= K; l++) {
                    ans = max(ans,
                              calc(0, i, j) +
                              calc(max(N - k, i), k, l));
                }
            }
        }
    }

    printf("%lld\n", ans);
    
    return 0;
}

ll calc(int pos, int len, int k)
{
    if (pos + len > N) return 0;
    
    ll sum = 0;
    for (int i = pos; i < pos + len; i++) {
        sum += v[i];
    }

    return sum - msum(pos, len, k);
}

ll msum(int pos, int len, int k)
{
    if (k == 0) return 0;

    ll tmp;
    ll res;
    ll mpos = pos;
    for (int i = pos; i < pos + len; i++) {
        if (v[mpos] > v[i]) mpos = i;
    }

    tmp = v[mpos];
    v[mpos] = inf;
    res = msum(pos, len, k - 1);
    v[mpos] = tmp;

    return res + tmp;
}


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

int main(void) {
    int input, ans = 0, flag;
    cin >> input;

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

    sort(side.begin(), side.end());
    reverse(side.begin(), side.end());

    vector<int> num;
    for (int i = 0; i < input; i++) {
        flag = 0;
        for (int j = i + 1; j < input; j++) {
            for (int k = j + 1; k < input; k++) {
                if (side.at(i) < side.at(j) + side.at(k) && side.at(j) < side.at(k) + side.at(i) && side.at(k) < side.at(i) + side.at(j)) {
                    ans++;
                }
                else {
                    break;
                    flag++;
                }
            }
            if (flag != 0) {
                break;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define NIL NULL
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};
 
typedef struct node * Node;
Node root;
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else{
      x = x->right;
    }
  }
  z->parent = y; 
    if(y==NIL){
      root=z;
    }
    else if(z->key < y -> key){
      y->left = z;
    }
    else{
      y->right =z;
    }
}
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);
    inorder(u->right);
  }
  
}
void preorder(Node u){ 
    if (u != NIL) {
      printf(" ");
      printf("%d",u->key); 
      preorder(u->left);
      preorder(u->right);
     
    }
}
 
int main(){
  int i,j,n1,n2;
  char str[10];
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%s",str);
    if(str[0]=='i'){  
      scanf("%d",&n2);
      insert(n2);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24036
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
int a[11], ans = 0; bool b[10]; string s;
int f(int p) {
	if (p == s.size() - 1) {
		b[p] = 0;
		int r = 0, r1 = 0;
		for (int i = 0; i < s.size(); i++) {
			r1 += a[i];
			if (b[i])r1 *= 10;
			else {
				r += r1;
				r1 = 0;
			}
		}
		return r;
	}
	int r = 0;
	b[p] = 0;
	r += f(p + 1);
	b[p] = 1;
	r += f(p + 1);
	return r;
}
signed main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++)a[i] = s[i] - '0';
	cout << f(0) << "\n";
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if abs(T - H[i] * 0.006 - A) < abs(T - H[ans] * 0.006 - A):
        ans = i
print(ans + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <numeric>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<int,int> pii;
int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) return -1;
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}
int main(){
    int n;
    scanf("%d", &n);
    vector<ll>vec;
    while(n--){
        vec.push_back((ll)in());
        int sz = vec.size();
        while(sz >= 3 and vec[sz-1] <= vec[sz-2] and vec[sz-3] <= vec[sz-2]){
            ll a = vec[sz-1] + vec[sz-3] - vec[sz-2];
            rep(i,3)vec.pop_back();
            vec.push_back(a);
            sz-=2;
        }
    }
    ll ans = 0;
    int i = 0, j = vec.size()-1;
    int k = 1;
    while(i<=j){
        if(vec[i] > vec[j]){
            ans += vec[i]*k;
            i++;
        }else{
            ans += vec[j]*k;
            j--;
        }
        k *= -1;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;

    rep(i, 0, 26)
    {
        char now = 'a' + i;

        int prev = -3;
        rep(j, 0, s.size())
        {
            if (s[j] == now)
            {
                if (j - prev < 3)
                {
                    printf("%d %d\n", prev + 1, j + 1);
                    return 0;
                }
                prev = j;
            }
        }
    }
    cout << -1 << ' ' << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()

n = int(str(N)[-1])

if n in [2,4,5,7,9]:
	print('hon')
elif n in [0,1,6,8]:
	print('pon')
else:
	print('bon')


Measured memory_bytes: 61932
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	string S;
	cin >> S;

	ll ans = 0;
	ll white = 0;
	for (int i = S.length() - 1; i >= 0; i--) {
		if (S[i] == 'W')
			white++;
		else
			ans += white;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  //入力値NとKを数値化して確保
  var N = Number.parseInt(inputStr[0]);
  var K = Number.parseInt(inputStr[1]);
  //入力値を配列に入れる
  var S = input[1];
  //入力値S_arrを、0と1の塊別に纏めて、配列A_arrに入れる。0はマイナス化する。
  var A_arr = [];
  var cnt = 1;
  var flg = 0;
  for( var i=0; i < N-1; i++){
    if( S.substr(i,1) !== S.substr(i+1,1) ){
      if(S.substr(i,1)==="0"){
        A_arr.push(cnt * -1);
        flg = 1;
      } else {
        A_arr.push(cnt);
      }
      cnt = 1;
    } else {
      cnt += 1;
    }
  }
  if(S.substr(i,1)==="0"){
    A_arr.push(cnt * -1);
    flg = 1;
  } else {
    A_arr.push(cnt);
  }
  
  //console.log("配列",A_arr);
  
  //ループカウンタiとjを定義し、iとjの間にマイナス値が5つ含んだ状態での尺取法を行う。
  var m_cnt = 0;
  var tmp = 0;
  var max = 0;
  var j=0;
  var lsat_j = -1;
  //console.log("配列の長さ",A_arr.length);
  for( var i=0 ; i < A_arr.length ; i++){
    //範囲の中にマイナス値をK個含むか、配列終端に辿り着くまでループしてtmpに足し込む
    while( m_cnt < K && j < A_arr.length ){
      if(lsat_j !== j ){
        tmp += Math.abs(A_arr[j]);
        //console.log("tmpに値を足しこみ",A_arr[j]);
        lsat_j = j;
      }
      if( A_arr[j] < 0 ){
        m_cnt +=1;
      }
      j++;
    }
    if(lsat_j !== j ){
      lsat_j = j;
      if( m_cnt >= K && j < A_arr.length ){
        tmp += Math.abs(A_arr[j]);
        //console.log("tmpに値を足しこみ",A_arr[j]);
      }
    }
    //最大値比較
    //console.log("iとj",i,j);
    //console.log("maxとtmp",max,tmp);
    max = Math.max(max,tmp);
    //マイナス値の消しこみ
    if( A_arr[i] < 0 ){
      m_cnt -= 1;
    }
    tmp -= Math.abs(A_arr[i]);
    //console.log("tmpから値を消しこみ",A_arr[i]);
  }
  console.log(max);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9908
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
from collections import deque
from heapq import heappop, heappush, heapify
from collections import defaultdict

N = int(readline())
A = list(map(lambda x: int(x) - 1,read().split())) + [-1]

def test(A,B):
    for x,y in zip(B, B[1:]):
        if A[x] == y:
            return False
    return True

def solve_small(cand, A, ng_first = -1):
    for p in itertools.permutations(cand):
        if p[0] == ng_first:
            continue
        if test(A, p):
            return p
    return False

if N <= 6:
    p = solve_small(range(N), A)
    if not p:
        print(-1)
        exit()
    print(' '.join(str(x+1) for x in p))
    exit()

in_deg = [0] * (N+10)
for x in A:
    in_deg[x] += 1

q = [(-x, i) for i,x in enumerate(in_deg)] # in_deg最大の人を分かるようにしたい
heapify(q)
se = set(q)

def greedy(rest,A,ng_first):
    B = []
    ng = ng_first
    while len(rest) >= 4:
        x = rest[0]; y = rest[1]
        if ng == x:
            B.append(y)
            rest.popleft()
            rest.popleft()
            rest.appendleft(x)
        else:
            B.append(x)
            rest.popleft()
        ng = A[B[-1]]
    return B

rest = deque(range(N))
B = []
prev = N
n = N
for _ in range(N-4):
    while q[0] not in se:
        heappop(q)
    if -q[0][0] == n - 1:
        v = q[0][1]
        B.append(v)
        rest.remove(v)
        B += greedy(rest, A, A[B[-1]])
        break
    x = rest[0]; y = rest[1]
    if A[prev] == x:
        B.append(y)
        rest.popleft()
        rest.popleft()
        rest.appendleft(x)
    else:
        B.append(x)
        rest.popleft()
    prev = B[-1]
    v = A[B[-1]]
    se.remove((-in_deg[v],v))
    in_deg[v] -= 1
    se.add((-in_deg[v],v))
    n -= 1
if len(B) < N:
    B += list(solve_small(rest, A, A[B[-1]]))

print(' '.join(str(x+1) for x in B))

Measured memory_bytes: 40016
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;
void solve(){
  ll n, a, b, ans = 0; cin >> n >> a >> b;
  vector<ll> x(n);
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  for(int i = 0; i < n - 1; i++){
    if((x[i + 1] - x[i]) * a <= b) ans += (x[i + 1] - x[i]) * a;
    else ans += b;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector> 
#include <algorithm>

int main()
{
    long long N;
    std::cin >> N;
    std::vector<long long> A(N, 0);
    for (int i=0; i<N; i++)
    {
        std::cin >> A.at(i);
    }
	std::sort(A.begin(), A.end());
    int M = 1000005;
    std::vector<long long> cnt(M, 0);
    for (const long long& i: A)
    {
        if (cnt.at(i)!=0)
        {
            cnt.at(i)++;
            continue;
        }

        for (int j=i; j<M; j+=i) cnt.at(j)++;
    }

    long long ans=0;
    for (const long long& i: A)
    {
        if (cnt.at(i) == 1) ans++;
    }
    std::cout << ans;
}

Measured memory_bytes: 12760
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<28;
const double PI = acos(-1);
const double EPS = 1e-8;

int g1[200][200];
int g2[200][200];
int dist[2][200];
int z[1000];
int main() {
  int n, m;
  while(scanf("%d%d",&n,&m),n||m) {
    REP(i,n)REP(j,n)g1[i][j]=g2[i][j]=INF;
    REP(i,n)g1[i][i]=g2[i][i]=0;
    REP(i,m) {
      int a,b,c;
      char t;
      scanf("%d%d%d %c ",&a,&b,&c,&t);
      a--;b--;
      if (t=='L') g1[b][a]=g1[a][b]=min(g1[a][b],c);
      else g2[b][a]=g2[a][b]=min(g2[a][b],c);
    }
    REP(k,n)REP(i,n)REP(j,n)g1[i][j]=min(g1[i][j],g1[i][k]+g1[k][j]),g2[i][j]=min(g2[i][j],g2[i][k]+g2[k][j]);
    int r;scanf("%d",&r);
    REP(i,r) {
      scanf("%d",z+i);
      z[i]--;
    }
    REP(i,n)dist[0][i] = INF;
    dist[0][z[0]] = 0;
    int p;
    REP(i,r-1) {
      int *now = dist[i&1];
      int *nxt = dist[(i+1)&1];
      REP(j,n)nxt[j]=INF;
      REP(j,n)REP(k,n) {
        if (j==k) nxt[k]=min(nxt[k],now[j]+g1[z[i]][z[i+1]]);
        else nxt[k] = min(nxt[k], now[j]+g1[z[i]][j]+g2[j][k]+g1[k][z[i+1]]);
      }
      //REP(i,n) cout << nxt[i] << " ";cout<<endl;
    }
    int ans = INF;
    REP(i,n) ans=min(ans, dist[(r-1)&1][i]);
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1200
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)


using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const int INF = 1e9 + 7;


/******************************************************************************************/
vector<int> pre, in, post;
int pos = 0;

void dfs(int l, int r) {

	if (l >= r)return;

	int root = pre[pos++];
	int id = 0;

	for (int i = 0; i < in.size(); i++)
	{
		if (in[i] == root) {
			id = i;
			break;
		}
	}

	dfs(l, id);
	dfs(id + 1, r);

	post.push_back(root);

}

void solve() {

	int pos = 0;

	dfs(0, pre.size());

	for (int i = 0; i < post.size(); i++)
	{
		if (i)cout << " ";
		cout << post[i];
	}
	cout << endl;

}



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		pre.push_back(c);
	}

	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		in.push_back(c);
	}

	solve();


	
	return 0;
}



Measured memory_bytes: 3192
b,s,o,i;main(a){for(scanf("%d",&i);i<15&&~scanf("%s",&a);b=a%3?a&1?o?b:(s=!printf("%d\n",b>3?s+b-3:s)):b+1:!(s+=++b))  o=a&1?-~o%3:o;return 0;}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  vector<int> L(3);
  rep(i, 3) cin >> L[i];
  sort(L.begin(), L.end());

  cout << L[0] * L[1] /2 << endl;

  return 0;
}


Measured memory_bytes: 256
def minCandies(candies, n, max_candy):
    count = 0
    for i in range(n - 1):
        if candies[i] + candies[i + 1] > max_candy:
            remove = (candies[i] + candies[i + 1]) - max_candy
            candies[i + 1] -= remove if candies[i + 1] >= remove else candies[i + 1]
            count += remove 
    return count


n, max_candy = input().split()
candies = list(map(int, input().split()))
print(minCandies(candies, int(n), int(max_candy)))



Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		Union_Find_Tree uft(n);
		vip a;
		for(int i=0;i<m;i++){
			int u,v,w;
			cin>>u>>v>>w;
			u--;v--;
			a.push_back({w,{u,v}});
		}
		sort(a.begin(),a.end());
		vi b;
		for(int i=0;i<m;i++){
			int u=a[i].second.first,v=a[i].second.second;
			if(!uft.Same(u,v)){
				uft.Unite(u,v);
				b.push_back(a[i].first);
			}
		}
		cout<<b[n/2-1]<<endl;
	}
}


Measured memory_bytes: 3308
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int[] X=new int[N];
        int[] R=new int[N];
        for(int i=0;i<N;i++){
            X[i]=sc.nextInt();
            R[i]=X[i];
        }
        Arrays.sort(X);
        int l=X[(N-1)/2];
        int r=X[(N-1)/2+1];
        for(int i=0;i<N;i++){
            if(R[i]<r){
               System.out.println(r);
            }else{
               System.out.println(l);
            }
        }
    }
}



Measured memory_bytes: 101300
H,W = map(int,input().split())
C = [[0 for _ in range(W+1)]]
for _ in range(H):
    row = list(input())
    row.insert(0,0)
    C.append(row)
F = [[0 for _ in range(W+1)]]
for i in range(1,2*H+1):
    row = [0 for _ in range(W+1)]
    for j in range(1,W+1):
        row[j] = C[(i+1)//2][j]
    F.append(row)
for i in range(1,2*H+1):
    print("".join(F[i][1:]))

Measured memory_bytes: 39408
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pint> con;
vector<pint> stars;

int main() {
	int m;
	while(m=in()){
		con.clear();
		stars.clear();
		int i;
		pint buf;
		for(i=0;i<m;i++){
			cin>>buf.first>>buf.second;
			con.push_back(buf);
		}
		int n=in();
		for(i=0;i<n;i++){
			cin>>buf.first>>buf.second;
			stars.push_back(buf);
		}
		int j,k;
		int x,y;
		for(i=0;i<n;i++){
			x=stars[i].first-con[0].first;
			y=stars[i].second-con[0].second;
			for(j=0;j<m;j++){
				for(k=0;k<n;k++){
					if(stars[k].first==con[j].first+x&&stars[k].second==con[j].second+y)break;
				}
				if(k==n)break;
			}
			if(j==m)break;
		}
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 964
#include <iostream>
#include <set>
#include <cstring>
#include <vector>
#include <queue>
#include <climits>
#include <math.h>
#include <map>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>

int main(){

	ll n;
	cin >> n;
	int ans = 0;
	ll x = 100;
	while(x < n){
		x *= 1.01;
		ans++;
	}
	// double p = 100;
	// ans = 1;
	// while(1){
	// 	double sum = 100*ans + ((ans * (ans-1))/2)*(1.01);
	// 	if(sum >= n)
	// 		break;
	// 	ans++;
	// }
	cout << ans << endl;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,k,ans{};
    cin>>h>>w>>k;
    vector<string> c(h);
    for(auto&s:c) cin>>s;
    fr(i,(1<<h)) fr(j,(1<<w)){
        int cnt{};
        fr(s,h) fr(t,w){
            if(c[s][t]=='#' and((i>>s)&1) and((j>>t)&1)) ++cnt;
        }
        if(cnt==k) ++ans;
    }
    cout<<ans<<'\n';
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int cnt = 0;
    int uk = 0;
    while (uk < n && a[uk] == a[0]) {
        ++cnt;
        ++uk;
    }
    if (cnt > 2) {
        cout << "Impossible\n";
        return 0;
    }
    if (cnt == 1) {
        if (a.back() > 2 * a[0]) {
            cout << "Impossible\n";
            return 0;
        }
    } else {
        if (a.back() >= 2 * a[0]) {
            cout << "Impossible\n";
            return 0;
        }
    }
    for (int i = 1; i < n; ++i) {
        if (a[i] - a[i - 1] > 1) {
            cout << "Impossible\n";
            return 0;
        }
    }
    cout << "Possible\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,x;
	cin>>N>>x;
	int a[100];
	int cnt=0;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a,a+N);
	for(int i=0;i<N;i++){
		if(i+1==N){
			x-=a[i];
			if(x==0) cnt++;
		}else{
			x-=a[i];
			if(x<0) break;
			cnt++;
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
import heapq
a, b = map(int, input().split())
c = list(map(int, input().split()))
heapq.heapify(c)
d = []
for i in range(b):
    e, f = map(int, input().split())
    d.append([e, f])
d = sorted(d, key=lambda x: x[1], reverse=True)
for i in range(len(d)):
    g = heapq.heappop(c)
    if d[i][1] < g:
        heapq.heappush(c, g)
        break
    else:
        heapq.heappush(c, g)
        for j in range(d[i][0]):
            g = heapq.heappop(c)
            if g < d[i][1]:
                heapq.heappush(c, d[i][1])
            else:
                heapq.heappush(c, g)
                break
print(sum(c))


Measured memory_bytes: 26424
#include<stdio.h>
#define M 1000000007
int main(void)
{
	int n,i;
	long long int p=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		p=p*i;
		p=p%M;
	}
	printf("%lld\n",p);
	return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
t = [True for i in range(n)]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        t[a[j]-1] = False
count = 0
for i in t:
    if i:
        count+=1
print(count)

Measured memory_bytes: 9024
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for _ in range(101)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).find('AGC') != -1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur+1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))



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

int main(){
    char a, b, c, d;
    scanf("%c%c%c%c", &a, &b ,&c, &d);
    int for_two = 0, lat_two = 0;
    for_two = for_two * 10 + (a - '0');
    for_two = for_two * 10 + (b - '0');
    lat_two = lat_two * 10 + (c - '0');
    lat_two = lat_two * 10 + (d - '0');
    if(for_two >= 1 && lat_two >= 1 && for_two <= 12 && lat_two <= 12){
        printf("AMBIGUOUS\n");
    }
    else if(for_two >= 1 && for_two <= 12){
        printf("MMYY\n");
    }
    else if(lat_two >= 1 && lat_two <= 12){
        printf("YYMM\n");
    }
    else{
        printf("NA\n");
    }
    return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long a,b,c,N;
  cin >> a >> b >> c >> N;
	if(N <= a){
      cout << N;
}else if(N <= a + b){
    cout << a << endl;
  }else{
    cout << a - (N - a - b) << endl;
  }
return 0;
}

Measured memory_bytes: 3576
while 1:
    n = int(input())
    if n == 0:
        break

    charge = 1000 - n
    cnt = 0
    if charge >= 500:
        cnt += 1
        charge -= 500
    cnt += charge // 100
    charge %= 100

    if charge >= 50:
        cnt += 1
        charge -= 50
    cnt += charge // 10
    charge %= 10

    if charge >= 5:
        cnt += 1
        charge -= 5
    cnt += charge

    print(cnt)



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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

int DP[3][100010];

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	vector<vi> A(3, vi (n));
	M00(i, n) {
		cin >> A[0][i] >> A[1][i] >> A[2][i];
	}
	M00(i, 3) DP[i][0] = A[i][0];
	MOO(i, 1, n) {
		M00(j, 3) {
			int best = 0;
			M00(k, 3) {
				if(j != k) best = max(best, DP[k][i-1]);
			}
			DP[j][i] = A[j][i] + best;
		}
	}
	cout << max(DP[0][n-1], max(DP[1][n-1], DP[2][n-1])) << endl;
}


Measured memory_bytes: 2556
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	int t = 0, x = 0, y = 0;
	bool flag = true;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		if ((a - t) < (abs(b - x) + abs(c - y))) {
			flag = false;
			break;
		}
		if ((a - t) % 2 == 1) {
			if ((abs(b - x) + abs(c - y)) % 2 == 0) {
				flag = false;
				break;
			}
		}
		else {
			if ((abs(b - x) + abs(c - y)) % 2 == 1) {
				flag = false;
				break;
			}
		}
		t = a;
		x = b;
		y = c;
	}

	if (!flag) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	return 0;
}

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

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){
  int n,q;
  string name;
  int t;
  int t2 = 0;
  pair<string, int> p,p2;
  queue< pair< string, int > > que;

  cin >> n >> q;
  for( int i = 0; i < n; ++i){
    cin >> name >> t;
    que.push( make_pair( name, t));
  }

  while(!que.empty()){
    p = que.front();
    que.pop();
    if( p.second <= q){
      cout << p.first << " " << t2 + p.second <<
      endl;
      t2 += p.second;
    }else{
      p2.first = p.first;
      p2.second = p.second - q;
      que.push(p2);
      t2 += q;
    }
  }
}

Measured memory_bytes: 6272
from numpy.linalg import solve

X,Y = input().split(" ")

left = [[2, 4],
        [1, 1]]
 
right = [int(Y), int(X)]
 
Ans = solve(left, right)

#print(Ans)

# 数値が整数（小数点以下が0）か、0より大きいか判定
if Ans[0].is_integer() == True and Ans[1].is_integer() == True and Ans[0] >= 0 and Ans[1] >= 0:
  print("Yes")
else:
  print("No")

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int i=0;i<(n);i++)        //repeat n times
#define REP2(i,s,n) for(int i=(s);i<(n);i++)   //repeat from s to n 
#define REPD(i,n) for(int i=(n);i>=0;i--)      //repeat from n to 0
#define REPD2(i,s,e) for(int i=(s);i>=(e);i--) //repeat from s to e
#define RANGE(i,v) for(auto &i:v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    LL N;
    cin>>N;
    LL tmp = N;
    string ans = "";
    while(tmp>0){
        tmp--;
        ans += char(tmp%26+'a');
        tmp/=26;
    }

    reverse(ALL(ans));
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, k, a[510];

    int sum = 0;

    cin >> n >> k;
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }

    V y;
    for (int i = 1; i <= sqrt(sum); i++)
    {
        if (sum % i == 0)
        {
            y.push_back(i);
            y.push_back(sum / i);
        }
    }

    SORT(y);

    int res = 1;

    for (int s : y)
    {
        V d;

        REP(i, n)
        {
            if (a[i] % s)
                d.push_back(a[i] % s);
        }

        SORT(d);

        int nokori[510];
        nokori[d.size()] = 0;
        for (int j = d.size() - 1; j >= 0; j--)
        {
            nokori[j] = nokori[j + 1] + s - d[j];
        }

        int su = 0;
        for (int j = 0; j < d.size(); j++)
        {
            su += d[j];

            if (su == nokori[j + 1])
            {
                break;
            }
        }

        if (su <= k)
            res = s;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
	}
	sort(ALL(a));

	int ans1 = a.back();
	int k = upper_bound(ALL(a), ans1 / 2) - a.begin();
	if(k == n - 1){ --k; }
	if(k > 0){
		if(abs(a[k - 1] * 2 - ans1) < abs(a[k] * 2 - ans1)){ --k; }
	}
	int ans2 = a[k];
	
	printf("%d %d\n", ans1, ans2);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	cin>>n>>s;
	stack<char> st;
	FOR(i,0,n){
		if(st.size()==0){
			st.push(s[i]);
		}else if(s[i]==')'){
			if(st.top()==s[i]){
				st.push(s[i]);
			}else{
				st.pop();
			}
		}else{
			st.push(s[i]);
		}
	}
	string a1,a2;
	while( not st.empty() ){
		if(st.top()=='('){
			a2 += ')';
		}else{
			a1 += '(';
		}
		st.pop();
	}
	cout<<a1<<s<<a2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  print(x2-y2+y1,y2+x2-x1,x1-y2+y1,y1+x2-x1);

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0;i < N;i++)cin >> L[i];

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

  ll ans = 0;

  for(int i = 0;i < N - 1;i++){
    for(int j = i + 1;j < N;j++){
      int a = L[i];
      int b = L[j];
      auto itr_lower = lower_bound(L.begin(),L.end(),a+b);
      auto itr_upper = upper_bound(L.begin(),L.end(),b-a);

      ans += max((ll)(itr_lower - itr_upper),(ll)0);

      if(2 * a > b)ans--;

      ans--;
    }
  }

  cout << ans / 3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int board[10][5];

int check(int y,int x){
    int nx=x,cnt=0;
    while(nx+1<5){
        if(board[y][nx]!=0&&board[y][nx]==board[y][nx+1])cnt++;
        else break;
        nx++;
    }
    return cnt+1;
}

int main(){
    int H;
    while(cin >> H,H){
        rep(i,H)rep(j,5)cin >> board[i][j];
        int point = 0;
        while(1){
            int breakflag=1;
            //消す
            for(int i=0;i<H;i++){
                for(int j=0;j<3;j++){
                    int c=0;
                    if((c=check(i,j))>=3){
                        breakflag=0;
                        for(int k=0;k<c;k++){
                            point+=board[i][j+k];
                            board[i][j+k]=0;
                        }
                    }
                }
            }
            if(breakflag)break;
            //落とす
            for(int t=0;t<11;t++){
                for(int i=H-1;i>=1;i--){
                    for(int j=0;j<5;j++){
                        if(board[i][j]==0){
                            swap(board[i-1][j],board[i][j]);
                        }
                    }   
                }
            }
        }
        cout << point << endl;
        rep(i,10)rep(j,5)board[i][j]=0;
    }
    return 0;
}


Measured memory_bytes: 3020
// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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)*}
    };
}

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, chars) => { read_value!($next, String).chars().collect::<Vec<char>>()
           };

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

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

fn main() {
    input! {
        x: usize,
    }

    let mut a = 100;
    let mut year = 0;
    while a < x {
        a += a / 100;
        year += 1;
    }
    println!("{}", year);
}


Measured memory_bytes: 2144
using System;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        char[] input = Console.ReadLine ().ToCharArray ();
        bool ans = false;
        for (int i = 0; i < input.Length; i++) {
            if (input[i] == '7') {
                ans = true;
            }
        }
        if (ans) {
            Console.WriteLine ("Yes");
        } else {
            Console.WriteLine ("No");
        }
    }
}

Measured memory_bytes: 25680