akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,Ma,Mb = LI()
a,b,c = LIR(N,3)

n = N//2

d1 = [[5000]*401 for _ in range(401)]
d2 = [[5000]*401 for _ in range(401)]

for bit in range(1<<n):
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(n):
        if bit>>i&1:
            val_a += a[n-1-i]
            val_b += b[n-1-i]
            cost += c[n-1-i]
    d1[val_a][val_b] = min(d1[val_a][val_b],cost)

for bit in range(1<<(N-n)):
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(N-n):
        if bit>>i&1:
            val_a += a[N-1-i]
            val_b += b[N-1-i]
            cost += c[N-1-i]
    d2[val_a][val_b] = min(d2[val_a][val_b],cost)

vals = []
now = 1
while True:
    if Ma*now <= sum(a) and Mb*now <= sum(b):
        vals.append((Ma*now,Mb*now))
        now += 1
    else:
        break

ans = 5000
for ka in range(401):
    for kb in range(401):
        for v in vals[::-1]:
            left_a = v[0]-ka
            left_b = v[1]-kb
            if left_a < 0 or left_b < 0:
                break
            if d1[ka][kb]+d2[left_a][left_b] < ans:
                ans = d1[ka][kb]+d2[left_a][left_b]

if ans == 5000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 47964
n, m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
a = a.sort.reverse
sum = 0
a.each {|v| sum += v}
if a[m-1]*4*m >= sum
  puts "Yes"
else
  puts "No"
end

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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
vector<int> scores;
int main() {
  int N;
  cin >> N;
  scores.resize(3 * N);
  for (auto &val : scores){
    cin >> val;
  }
  sort(scores.rbegin(), scores.rend());
  int left = 0;
  int right = scores.size() - 1;
  ll sum =0;
  while (left < right){
    int a = scores[left + 1];
    sum += a;
    left += 2;
    right--;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define MAXN 55
#define mod 998244353
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n;
    cin>>n;
    int s=0;
    for(int a=1;a<=n;a++){
        for(int b=1;b<=n;b++){
            for(int c=1;c<=n;c++){
                int k=__gcd(a,b);
                k=__gcd(k,c);
                s+=k;
            }
        }
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            int[] dh = new int[1000];
            int ch = 0;
            for (int i = 1; i <= 999; i++) {
                ch += i;
                dh[i] = ch;
            }

            out.println(dh[b - a] - b);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            if (bufLength == -1)
                throw new InputMismatchException();
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return (c >= 33 && c <= 126);
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public long nextLong() {
            long n = 0;

            boolean minus = false;
            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || b > '9')
                throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (isSpaceChar(b) || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21332
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    string S = "Christmas";
    int D;
    cin >> D;
    while(D < 25){
        D++;
        S += " Eve";
    }
    cout << S << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int64 n;
    cin >> n;
    int ans = INT_MAX;
    for (int i=1; i<=sqrt(n); i++) {
        if (n%i) continue;
        ans = min(ans, max((int)(log10((double)n/(double)i)+1), (int)(log10(i)+1)));
    }
    cout << ans << endl;
}


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

int n, m;

void solve() {
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3652
/*input
abracadabra
avadakedavra
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,r;cin>>s>>r;
	int n = (int)s.size(),m = (int)r.size();

	vector<vector<int>> dp(n+1,vector<int> (m+1,0));
	dp[0][0]=0;

	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i-1]==r[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

	string ans="";
	int i=n,j=m;
	while(i>0 && j>0 )
	{
		if(s[i-1]==r[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i][j]==dp[i-1][j]) i--;
		else j--;
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 38628
#include <stdio.h>
int main(void){
	int a, b, flag = 0;
	char op;

	while (flag == 0){
		scanf("%d %c %d", &a, &op, &b);
		if (op == '?') flag = 1;
		else if (op == '+') printf("%d\n", (a + b));
		else if (op == '-') printf("%d\n", (a - b));
		else if (op == '/') printf("%d\n", (a / b));
		else if (op == '*') printf("%d\n", (a * b));
	}
}

Measured memory_bytes: 1028
//数が小さいほど、安いとき
//数が大きいと、その分利益＝大きいー小さい
//最後が小さい時だとしても購入することができない


#include <stdio.h>
#define N 200000
int main(){
	
	int num,i,max,min;
	int value[N];

	scanf("%d",&num);

	for(i=0;i<num;i++){
		scanf("%d",&value[i]);
	}

	max = value[1]-value[0];/* 大-小 */
	min = value[0];/* 0からじゃないと最後の数まで読み込んでしまう */

	for(i=1;i<num;i++){
		if(max<value[i] - min) max = value[i] - min;
		if(min>value[i]) min = value[i];/*最後は小さい値を読み込まない*/
	}

	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2636
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int N,M;
vector<vector<int>> edge(100010, vector<int>(0));
int dp[100010];
bool visited[100010];

ll dfs(int x){//通る頂点の数
    if(visited[x]){
        return dp[x];
    }
    visited[x] = 1;
    
    int M = 0;
    for(int i = 0; i < edge.at(x).size(); i++){
        int m;
        m = dfs(edge.at(x).at(i));
        M = max(M, m);
    }
    
    return dp[x] += M + 1;
    
}





int main(void){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        edge.at(a).push_back(b);
    }
    for(int i = 0; i < 100010; i++){
        visited[i] = 0;
        dp[i] = 0;
    }
    
    for(int i = 0; i < N; i++){
        if(visited[i] == 0){
            dfs(i);
        }
    }
    int Ans = 0;
    for(int i = 0; i < N; i++){
        int ans = dfs(i);
        Ans = max(Ans, ans);
    }
    cout << Ans - 1 << endl;
    
}


Measured memory_bytes: 8192
def F(alpha, beta, c):
    gamma = ord(c) - ord("a")
    return chr((alpha*gamma + beta) % 26 + ord("a"))

alphalist = [1,3,5,7,9,11,15,17,19,21,23,25]
N = int(input())
for lines in range(N):
    S = input()
    words = S.split()
    keyA = -1
    keyB = -1
    for i in range(len(words)):
        if len(words[i]) == 4:
            w = words[i]
            for k in range(len(alphalist)):
                for l in range(26):
                    alpha = alphalist[k]
                    beta = l
                    if F(alpha,beta,w[0]) == "t" and F(alpha,beta,w[1]) == "h":
                        if F(alpha,beta,w[2]) == "a" and F(alpha,beta,w[3]) == "t":
                            keyA = alpha
                            keyB = beta
                        elif F(alpha,beta,w[2]) == "i" and F(alpha,beta,w[3]) == "s":
                            keyA = alpha
                            keyB = beta
                    if keyA > 0:
                        break
                if keyB > 0:
                    break
        if keyA > 0:
            break

    for i in range(len(S)):
        if S[i] == " ":
            print(" ", end="")
        else:
            print(F(keyA,keyB,S[i]), end="")
    print("")



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

int main()
{
  int64_t n,ans,sum;
  sum=0;
  ans=0;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    sum+=a.at(i);
  }
  for(int i=0;i<n-1;i++)
  {
    sum-=a.at(i);
    ans+=a.at(i)*(sum%1000000007);
    ans=ans%1000000007;
  }
  cout<<ans<<endl;
}

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

#define push_back pb

void solve(){

    int n,m;
    cin >> n >> m;
    cout << n*m << endl;
    
}
int main(){
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    } 
}

Measured memory_bytes: 3616
#include <iostream>
int h, n;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> h >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        h -= x;
    }
    if (h <= 0) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
#define inf 1e12+7
typedef long long ll;

int main(){
    int r; cin >> r;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
int main(){
	int arr[10];
	for(int i=0;i<10;i++) std::cin>>arr[i];
	std::sort(arr,arr+10);
	for(int i=9;i>6;i--) std::cout<<arr[i]<<"\n";
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	ll dp[n][3];
	for(int i=0;i<n;i++){
		ll a,b,c;cin>>a>>b>>c;
		if(i==0){
			dp[i][0] = a;
			dp[i][1] = b;
			dp[i][2] = c;
		}
		else{
			dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a;
			dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b;
			dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c;
		}
	}
	ll ans = max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
	cout<<ans<<endl;
}

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

int main() {
    ll N;
    cin >> N;
    ll X[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    ll MIN = 1LL << 40;

    for (ll i = 1; i <= 100; i++) {
        ll power = 0;
        for (ll j = 0; j < N; j++) {
            power += pow(abs(X[j]-i), 2);
        }
        MIN = min(MIN, power);
    }

    cout << MIN << endl;
    return 0;
}

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

int main() {
    int n; cin >> n;
    int a[n];
    rep(i,0,n){
        cin >> a[i];
    }
    sort(a,a+n);
    cout <<  a[n-1]-a[0] << endl;
}

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

int dp[200][200];

int main() {
    int i,j, n , m ;


    cin >>  n >> m ;
    string s[n+10] ;
    for(i=0;i<n;i++)
        cin >> s[i]  ;

    for(i=0;i<=n;i++) {
        for(j=0;j<=m;j++)
            dp[i][j] = 100000 ;
    }

    dp[0][0] = (s[0][0]=='#') ;


    for(i=0;i<n;i++) {
        for(j=0;j<m;j++) {
            if (!i and !j) continue ;
            if (!i) {
                dp[i][j] = min(dp[i][j],dp[i][j-1]+(s[i][j]=='#' && s[i][j-1]!='#')) ;
            }
            if (!j) dp[i][j] = min(dp[i][j],dp[i-1][j]+(s[i][j]=='#' && s[i-1][j]!='#')) ;
            if (i && j) {
                dp[i][j] = min(dp[i][j],dp[i][j-1]+(s[i][j]=='#' && s[i][j-1]!='#')) ;
                dp[i][j] = min(dp[i][j],dp[i-1][j]+(s[i][j]=='#' && s[i-1][j]!='#')) ;
            }
        }
    }
   // for(i=0;i<n;i++) {for(j=0;j<m;j++) cout << dp[i][j] <<  ' ' ; cout << endl ;}
    cout << dp[n-1][m-1] << endl ;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int H = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        double Hdeg = H * 30 + M * 0.5;
        double Mdeg = M * 6;

        double deg = Hdeg - Mdeg;
        if (deg > 180) {
            deg = 360 - deg;
        }
        deg = Math.abs(deg);

        double cSquare = A * A + B * B - (2 * A * B * Math.cos(deg * Math.PI / 180));
        System.out.println(Math.sqrt(cSquare));
    }
}


Measured memory_bytes: 35988
s = input()

l = int(s[:2])
r = int(s[2:])

is_yymm = False
is_mmyy = False

if 1 <= l and l <= 12 and 0 <= r and r <= 99:
  is_mmyy = True

if 1 <= r and r <= 12 and 0 <= l and l <= 99:
  is_yymm = True

if is_mmyy and is_yymm:
  print('AMBIGUOUS')
elif is_mmyy:
  print('MMYY')
elif is_yymm:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 38256
#include <iostream>

using namespace std;

#define PRIMENUM 1299710

//その数は素数かどうか判定する変数
int isPrime[PRIMENUM];

void makePrimeNumber(){

	isPrime[2]=1;
	isPrime[3]=1;

	for(int i=4;i<PRIMENUM;i++){
		int flag=0;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=1;
				break;
			}
		}
		if(flag==0){
			isPrime[i]=1;
			//cout<<i<<endl;
		}	
	}

}

int main(){
	int n;

	makePrimeNumber();

	while(cin>>n){
		if(n==0)break;
		if(isPrime[n]==1){
			cout<<0<<endl;
			continue;
		}

		int start,end;

		for(int i=n-1;i>=0;i--){

			if(isPrime[i]==1){
				start = i;
				break;
			}
		}
		for(int i=n+1;i<=PRIMENUM;i++){
			if(isPrime[i]==1){
				end = i;
				break;
			}
		}
		cout<<end-start<<endl;
	}

	return 0;
}

Measured memory_bytes: 6236
#include <stdio.h>
#include <string.h>

int main () {
	char a[100000];
	int n;
	scanf("%d", &n);
	getchar();
	scanf("%s", &a);
	int len = strlen(a);
	
	for (int i = 0; i < len; i++){
		if (a[i] + n > 'Z'){
			a[i] -= 26 - n;
		}
		else {
			a[i] += n;
		}
	}
	printf("%s", a);
	return 0;
}

Measured memory_bytes: 1740
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int h,w,a,b;

int main()
{
  scanf("%d %d %d %d",&h,&w,&a,&b);
  FORN(i,1,h-b)
  {
    FORN(j,1,a) printf("1");
    FORN(j,a+1,w) printf("0");
    puts("");
  }
  FORN(i,h-b+1,h)
  {
    FORN(j,1,a) printf("0");
    FORN(j,a+1,w) printf("1");
    puts("");
  }
  return 0;
}











Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=200005;
int a[N],b[N];
set<ii> s;
void rekt()
{
  cout<<-1<<endl;
  exit(0);
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  int cnt=0;
  rep(i,1,n+1) cin>>a[i];
  rep(i,1,n+1)
    {
      cin>>b[i];
      if(a[i]==b[i]) cnt++;
      else s.insert(mp(b[i],i));
    }
  b[n+1]=b[1];
  b[0]=b[n];
  ll ans=0;
  while(cnt!=n)
    {
      auto it=*s.rbegin();
      s.erase(it);
      int id=it.se;
      if(b[id]==a[id]) rekt();
      int sum=b[id-1]+b[id+1];
      int num=(b[id]-a[id])/sum;
      num=min(num,(b[id]-1)/sum);
      if(!num) rekt();
      ans+=num;
      b[id]-=num*sum;
      if(b[id]==a[id]) cnt++;
      else s.insert(mp(b[id],id));
      if(id==n) b[0]-=num*sum;
      if(id==1) b[n+1]-=num*sum;
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 11264
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
bool compare(int a,int b){
return a>b;
}
int main(){
	int k,n,a[50],i,sum=0;
	scanf("%d%d",&k,&n);
	for(i=0;i<k;i++)
	scanf("%d",&a[i]);
	sort(a,a+k,compare);
	for(i=0;i<n;i++) sum+=a[i];
	printf("%d",sum);
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

r = 1_000_000_000

(-100..100).each do |k|
  c = 0
  a.each do |ai|
    c += (k-ai) * (k-ai)
  end
  r = [r, c].min
end

puts r


Measured memory_bytes: 1788
N = int(input())
A = list(map(int, input().split()))
X = [0] * 10 ** 5

for i in range(N):
    X[A[i]] += 1

ans = 0
X_count = 0

if N == 1:
    print(1)
elif N == 2:
    if abs(A[1] - A[0]) <= 1:
        print(2)
    else:
        print(1)
else:
    for i in range(N-2):
        X_count = X[i] + X[i+1] + X[i+2]
        ans = max(ans,X_count)
        X_count = 0
    print(ans)

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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=3e5+5,MOD=1e9+7;

using namespace std;

int n,m;
ll ans;
int a[N];
pi b[N];
int main() {
	

	scanf("%d %d",&n,&m);

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

	for(int i=0;i<m;i++){
		scanf("%d %d",&b[i].second,&b[i].first);
	}

	sort(a,a+n);
	sort(b,b+m);
	int curr=0;
	for(int i=m-1;i>=0;i--){
		int val = b[i].first , howmuch = b[i].second;
		if(curr>=n)break;
		while(curr<n && howmuch && a[curr]<val){
			a[curr++]=val;
			howmuch--;
		}
	}

	for(int i=0;i<n;i++)ans+=a[i];

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

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
      int n,k;
      cin>>n;
      vector< int>a;
      for( int i=0;i<n;i++)
        {   cin>>k;
            a.push_back( k );
        }
      sort( a.begin(),a.end() );      
         
      long long s1=-1,s2=-1;
       for(  int i=n-1;i>=1;i--)
             {
                 if( a[i] == a[i-1] )
                      {
                        s1= a[i];
                        a.pop_back();
                        a.pop_back();
                        break;
                    
                      }
                    else
                        a.pop_back();
                 
             }
        for( int i= a.size()-1; i>=1;i-- )          
            {
            
                 if ( a[i] != a[i-1] )
                     a.pop_back();
               else
                   {
                       s2 = a[i];
                       break;
                   }
                
            }
           if(  s1 != -1 && s2 != -1 )
               cout<< s1 * s2<<endl;
           else
                   cout<<0<<endl;
     return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

struct node
{
	int c;
	int a[15];
}book[15];
int b[15];

int main()
{
//	freopen("input.txt","r",stdin);
	
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
	{
		cin>>book[i].c;
		for(int j=0;j<m;j++) cin>>book[i].a[j];
	}
//	for(int i=0;i<n;i++)
//	{
//		cout<<book[i].c<<" ";
//		for(int j=0;j<m;j++) cout<<book[i].a[j];
//		puts("");
//	}
	int ans=-1;
	for(int i=0;i<(1<<n);i++)
	{
		int sum=0;
		memset(b,0,sizeof b); 
		for(int j=0;j<n;j++)
			if((i>>j)&1)
			{
				sum+=book[j].c;
				for(int k=0;k<m;k++) b[k]+=book[j].a[k];
			}
		bool flag=1;
		for(int j=0;j<m;j++) if(b[j]<x) flag=0;
		if(flag)
		{
			if(ans==-1) ans=sum;
			else ans=min(ans,sum);
		}
	}
	cout<<ans<<endl;
	
	return 0;
 } 
 
//每行第一个数前不输出 
 

 
 
 
 
 

Measured memory_bytes: 3532
#include <cstdio>
#include <cstring>
#include <stack>
#include <string>

using namespace std;

int main()
{
    char buf[8];
    stack<int> stk;
    while(scanf("%s", buf)!=EOF){
        int n;
        if(!strcmp(buf, "+")){
            int op2=stk.top(); stk.pop();
            int op1=stk.top(); stk.pop();
            n=op1+op2;
        } else if(!strcmp(buf, "-")){
            int op2=stk.top(); stk.pop();
            int op1=stk.top(); stk.pop();
            n=op1-op2;
        } else if(!strcmp(buf, "*")){
            int op2=stk.top(); stk.pop();
            int op1=stk.top(); stk.pop();
            n=op1*op2;
        } else{
            n=stoi(buf);
        }
        stk.push(n);
    }
    printf("%d\n", stk.top());
    return 0;
}

Measured memory_bytes: 2876
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define get(vv, times) for(int ii = 0; ii < times; ++ii) {int jj; cin >> jj; (vv).pb(jj);}
#define all(vv) (vv).begin(), (vv).end()

int n, state, pre, ans;
vector <int> a;

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	get(a, n);
	// 0 -> same, 1 -> increasing, 2 -> decreasing
	state = -1, pre = 0, ans = 1;
	for(int i = 0; i < n; ++i) {
		if (state == -1) {
			state = 0;
		}
		else if (state == 0) {
			if (a[i] > pre) state = 1;
			else if (a[i] < pre) state = 2;
			else if (a[i] == pre) state = 0;
		}
		else if (state == 1) {
			if (a[i] < pre) {
				++ans;
				state = 0;
			}
		}
		else if (state == 2) {
			if (a[i] > pre) {
				++ans;
				state = 0;
			}
		}
		pre = a[i];
	}
	cout << ans;
}

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

using namespace std;

int main()
{
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double x = (c * e - b * f) / (a * e - b * d);
        double y = (a * f - c * d) / (a * e - b * d);
        x *= 1000; x = x + (x > 0 ? 0.5 : -0.5); x = (int)x;
        y *= 1000; y = y + (y > 0 ? 0.5 : -0.5); y = (int)y;
        printf("%.3f %.3f\n", x / 1000, y / 1000);
    }
    return 0;
}

Measured memory_bytes: 1236
/*
power code taken from geeks for geeks
*/

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 200001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


bool comp(pair<ll,ll>& a, pair<ll,ll>& b){
    return a.first<b.first;
}

void swap(ll& s1, ll &s2){
    ll temp=s1;
    s1=s2;
    s2=temp;
}
ll gcd(ll a, ll b){
    if(b==0){
        return a;
    }
    return gcd(b, a%b);
}


void solve(){
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        sum+=i;
    }
    cout<<sum<<endl;
}


int main(){



    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t=1;
    
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


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

int main() {
    int H,W;
    cin>>H>>W;
    vector<char> vec(W);

    for(int i=0;i<W+2;i++){
        cout<<'#';
    }
    cout<<endl;

    for(int i=0;i<H;i++){
        cout<<'#';
        for(int k=0;k<W;k++){
            cin>>vec.at(k);
            cout<<vec.at(k);
        }
        cout<<'#'<<endl;
    }
    
    for(int i=0;i<W+2;i++){
        cout<<'#';
    }
    cout<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,cnt,a[110],mini=0x7fffffff,maxn=0x80000000;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		mini=min(mini,a[i]);
		maxn=max(maxn,a[i]);
	}
	if(mini!=((maxn+1)>>1)){
		puts("Impossible");
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(a[i]==mini)
			cnt++;
	if(cnt!=1+(maxn&1)){
		puts("Impossible");
		return 0;
	}
	for(int i=mini+1;i<=maxn;i++){
		cnt=0;
		for(int j=1;j<=n;j++)
			if(a[j]==i)
				cnt++;
		if(cnt<2){
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <vector>
#include <functional>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAX_T = 110;

int a[MAX_T];

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

    int k, t;
    cin >> k >> t;

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

    int prev = -1, ans = 0;
    for (int d = 0; d < k; d++) {
        int max_cake = -1, val = 0;
        for (int i = 0; i < t; i++) {
            if (a[i] > val && i != prev) {
                max_cake = i;
                val = a[i];
            }
        }
        if (max_cake >= 0) {
            a[max_cake]--;
            prev = max_cake;
        } else {
            for (int i = 0; i < t; i++) {
                if (a[i] > 0) {
                    prev = i;
                    a[i]--;
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  long sum = accumulate(T.begin(), T.end(), 0L);
  int M;
  cin >> M;
  while (M--) {
    int P, X;
    cin >> P >> X;
    P--;
    cout << sum - T.at(P) + X << "\n";
  }
}

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

using namespace std;
typedef long long ll;
ll MAX = 1000000000000000000;

int main() {
  ll a, b, c, k;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);

  ll ans;
  if (k % 2 == 0) {
    ans = a - b; 
  } else {
    ans = b - a;
  }

  if (ans > MAX) {
    printf("Unfair");
  } else {
    printf("%lld\n", ans);
  }

  return 0;
}


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

#define MAX_N 15
#define INF 100000

int n;
int t[MAX_N][MAX_N];

int dp[1 << MAX_N][MAX_N];

int rec(int s, int v) {
	if (dp[s][v] >= 0) {
		return dp[s][v];
	}

	if (s == (1 << n) - 1 && v == 0) return dp[s][v] = 0;

	int res = INF;
	for (int u = 0; u < n; u++) {
		if (t[v][u] != INF && !(s >> u & 1)) {
			res = min(res, rec(s | 1 << u, u) + t[v][u]);
		}
	}
	return dp[s][v] = res;
}

int main() {
	int m;

	cin >> n;
	cin >> m;

	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			t[i][j] = INF;
		}
	}

	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		t[a][b] = c;
	}

	/*for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << t[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;*/
	if (rec(0, 0) == INF) {
		cout << -1 << endl;
	}
	else {
		cout << rec(0, 0) << endl;
	}

	/*for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/

	return 0;
}


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

using namespace std;

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

    #ifdef FUNSOCIETY
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif // FUNSOCIETY

    int n;
    cin >> n;

    vector<int> a, b;
    map<int, int> pos;
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        pos[x] = i%2;
        a.push_back(x);
    }

    sort(a.begin(), a.end());
    int ans = 0;

    for (int i = 0; i < n; ++i) {
        if (pos[ a[i] ] != i % 2) {
            ++ans;
        }
    }

    cout << ans/2 << endl;
}



Measured memory_bytes: 5368
#include<stdio.h>
int main()
{
  int x, y, r, tmp;
  scanf("%d%d", &x, &y);
  if(x < y)
    {
      tmp = x;
      x = y;
      y = tmp;
    }
  r = x % y;
  while(r != 0)
    {
      x = y;
      y = r;
      r = x % y;
    }
  printf("%d\n", y);
  return 0;
}



Measured memory_bytes: 2084
n, k = map(int, input().split())

height_list = []
for i in range(n):
    height_list.append(int(input()))
# print(height_list)

min = 2000000000
height_list.sort()
# print(height_list)

for start in range(0, len(height_list) - k + 1):
    # print("start is {}".format(height_list[start]))
    # print("end is {}".format(height_list[start + k -1]))

    x = height_list[start + k - 1] - height_list[start]
    if x < min:
        min = x

print(min)

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

int main(){
    int N, K;
    cin >> N >> K;
    int h[100000];
    int result=0;
    for(int i=0; i<N; i++){
        cin >> h[i];
        if(h[i]>=K){
            result++;
        }
    }

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

Measured memory_bytes: 640
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  // abs, sin, cos, tan
#include <ctime> // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ld, ll, ll>> vtll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

vll key;

//素因数分解
map<ll, ll> prime_factor(ll n)
{
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      //含まれる素数を使用する際
      if (!ret.count(i)) key.pb(i);
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
  {
    //含まれる素数を使用する際
    if (!ret.count(n)) key.pb(n);
    ret[n] = 1;
  }
  return ret;
}

void Main()
{
  vll w = {1};
  rep(i, 20)
  {
    rep(j, i + 2)
    {
      w.pb(i + 1);
    }
  }
  ll n; cin >> n;
  map<ll,ll> flag = prime_factor(n);
  ll ans = 0;
  if(n == 1) fin(0);
  for(ll i = 0;i < key.size();i++)
  {
    ans += w[flag[key[i]]];
  }
  fin(ans);
  return;
}

//前処理
int main()
{
  //int ti = clock();
  //srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); //0埋め４桁
  Main();
  //cout << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl; // 実行時間計測
  return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  int c[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>c[i][j];
    }
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
      }
    }
  }
  int a,cnt=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a;
      if(abs(a)!=1){
        cnt+=c[a][1];
      }
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>

using namespace std;

int        n, inputed_order[41] = {0};
queue<int> Queue;

struct Node {
    Node() { left_child = right_child = -1; };
    int left_child, right_child;
};

void postORDER(Node order[], int id) {
    if (order[id].left_child != -1) postORDER(order, order[id].left_child);
    if (order[id].right_child != -1) postORDER(order, order[id].right_child);
    Queue.push(id + 1);
}

int findRoot(int inorder[], int left, int right) {
    int root = inorder[left];
    for (int i = left + 1; i <= right; i++) {
        if (inputed_order[root] > inputed_order[inorder[i]]) {
            root = inorder[i];
        }
    }
    return root;
}

void reconstruct(int inorder[], Node order[], int root, int left, int right) {
    int root_index;
    for (root_index = left; inorder[root_index] != root; root_index++)
        ;
    if (left < root_index) {
        int new_root               = findRoot(inorder, left, root_index - 1);
        order[root - 1].left_child = new_root - 1;
        if (left < root_index - 1)
            reconstruct(inorder, order, new_root, left, root_index - 1);
    }
    if (root_index < right) {
        int new_root                = findRoot(inorder, root_index + 1, right);
        order[root - 1].right_child = new_root - 1;
        if (root_index + 1 < right)
            reconstruct(inorder, order, new_root, root_index + 1, right);
    }
}

int main() {
    scanf("%d", &n);
    int  preorder[n], inorder[n];
    Node order[n];

    for (int i = 0; i < n; i++) {
        scanf("%d", &preorder[i]);
        inputed_order[preorder[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &inorder[i]);
    }

    if (n == 1) {
        printf("%d\n", preorder[0]);
    } else {
        reconstruct(inorder, order, preorder[0], 0, n - 1);
        postORDER(order, preorder[0] - 1);
        while (!Queue.empty()) {
            if (Queue.size() != 1) {
                printf("%d ", Queue.front());
                Queue.pop();
            } else {
                printf("%d\n", Queue.front());
                Queue.pop();
            }
        }
    }
}



Measured memory_bytes: 2740
#include <stdio.h>
#include <string.h>
#include <math.h>
int main (){
	char A[15],B[15],C[15];
	scanf(" %s %s %s",&A,&B,&C);
	int a,b;
    a=strlen(A),b=strlen(B);
    if(A[a-1]==B[0]&&B[b-1]==C[0]){
    printf("YES\n");}
    else printf("NO\n");
    return 0;


}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();
    int n, s=1;
    cin>> n;

    int a[n];
    cin>> a[0];

    for(int i=1; i<n; i++)
    {
        cin>> a[i];
        if( a[i]>= a[0])
        {
            s++;
            a[0]= a[i];
        }
    }


    cout << s;
    nl;


    return 0;
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vi vector<int>
#define pi pair<int,int>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define ll long long 

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
	int add(int a,int b)
	{
		a+=b;
		if(a>=mod)a-=mod;
		return a;
		}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
		return res;
	}

long double dp[3001][3001];

void solve()
{

for(int i=0;i<3001;i++)for(int j=0;j<3001;j++)dp[i][j]=0;
int n;
cin>>n;
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
	long double p;
	cin>>p;
	for(int j=0;j<=i;j++)
	{
		if(j)
		{dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j]*(1-p);}
		else dp[i][j]=dp[i-1][j]*(1-p);
		}
	
	}
	long double ans=0;
	for(int i=n/2+1;i<=n;i++)ans+=dp[n][i];
	cout<<fixed<<setprecision(10)<<ans;
}
	
	
int main()
{   ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		}
	
	
	}


Measured memory_bytes: 141056
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(double base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
}

int main(){
	//Qalbaz();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n, m;
	cin >> n >> m;
	string str;
	cin >> str;
	int ans = n + m + 1;
	if (str.size() != ans)
	{
		cout << "No";
		return 0;
	}
	if (str[n] != '-')
	{
		cout << "No";
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		if (str[i] >= '0' && str[i] <= '9')
			continue;
		cout << "No";
		return 0;
	}
	for (int i = n + 1; i < str.size(); i++)
	{
		if (str[i] >= '0' && str[i] <= '9')
			continue;
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}

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

using namespace std;

template<class T> ostream& operator << (ostream& os, const vector<T>& v) { os << "["; for (int i=0; i<v.size(); i++) { os << v[i]; if (i < v.size() - 1) os << ", "; } return os << "]"; }

constexpr size_t MAX_N = 100001;

int N;
int K;
int T[MAX_N];

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

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

  sort(&T[0], &T[N]);

  vector<int> gaps;

  for (int i=0; i<N-1; i++) {
    gaps.push_back(T[i+1] - T[i] - 1);
  }

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

  // cout << "gaps=" << gaps << endl;

  long long ans = T[N-1] - T[0] + 1;

  // cout << "ans=" << ans << endl;

  for (int i=0; i<N && i<K-1; i++) {
    // cout << "sub " << gaps[i] << endl;
    ans -= gaps[i];
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        WriteLine(n[0] <= n[2] && n[2] <= n[1] ? "Yes" : "No");
    }
}


Measured memory_bytes: 18968
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n, k, s; cin >> n >> k >> s;
	if( k == 0 ){
		if( s == 1e9 ){
			for( int i = 0; i < n; ++i ){
				cout << 999999999 << ' ';
			} cout << endl;
			return 0;
		} else {
			for( int i = 0; i < n; ++i ){
				cout << 1000000000 << ' ';
			} cout << endl;
			return 0;
		}	
	}
	int t = s/(n-k+1);
	if( t == 0 ){
		if( s == 1e9 ){
			for( int i = 0; i < k; ++i ){
				cout << s << ' ';
			}
			for( int i = 0; i < n-k; ++i ){
				cout << 999999999 << ' ';
			} cout << endl;
			return 0;
		} else {
			for( int i = 0; i < k; ++i ){
				cout << s << ' ';
			}
			for( int i = 0; i < n-k; ++i ){
				cout << 1000000000 << ' ';
			} cout << endl;
			return 0;
		}	
	}
	int r = s%(n-k+1);
	for( int i = 0; i < n; ++i ){
		int bzh = t;
		if( i%(n-k+1) == 0 ){
			bzh += r;
		}
		cout << bzh << ' ';
	} 
	cout << endl;
}

Measured memory_bytes: 1280
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

parent=[0 for i in range(n)]
for i in range(n-1):
    parent[ab[i][1]-1]=ab[i][0]
ans=[0 for i in range(n)]
for i in range(q):
    ans[px[i][0]-1]+=px[i][1]
for i in range(1,n):
    if parent[i] != 0:
        ans[i]+=ans[parent[i]-1]


print(" ".join(map(str,ans)))


Measured memory_bytes: 126196