akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	String S = s.next();
	String T = s.next();
	
	int max = T.length();
	for(int i = 0; i <= S.length()-T.length(); i++){
		int count = T.length();
		for(int j = 0; j < T.length(); j++){
			if(S.charAt(i+j)==T.charAt(j)) count--;
		}
		max = Math.min(count, max);
	}
		
	System.out.println(max);
	
	
	

    
  }
}

Measured memory_bytes: 35508
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
//
#define forn(i, n)for(ll i=0;i<n;i++)
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,m;
vl bul[15];
ll swi[15],p[15];

int main(){FAST;
cin>>n>>m;
for(ll i=0;i<m;i++){
	cin>>swi[i];
	for(ll j=0;j<swi[i];j++){
		ll x;cin>>x;
		x--;
		bul[i].pb(x);
	}
}

for(ll i=0;i<m;i++){
	cin>>p[i];
}

ll ans = 0;
for(ll i=0;i<(1LL<<n);i++){
	ll lit = 0;
	for(ll j=0;j<m;j++){
		ll par = 0;
		for(auto it:bul[j]){
			if(i&(1LL<<it)){
				par++;
			}
		}
		if(par%2 == p[j]%2)lit++;
	}
	if(lit == m){
		ans++;
	}
}
cout<<ans;
return 0;
}

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

int main() {
	long long l, r;
	cin>>l>>r;
	long long ans = 2019*2019;
	for (long long i=l; i<l+2019 && i<=r; i++) {
		for (long long j=i+1; j<=i+2019 && j<=r; j++)
			ans = min(ans, i*j%2019);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=100005;

int n,per,kind;
int a[N]={-1},cnt[N],num[N];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) {
		if(a[i]==a[i-1])
			cnt[kind]++;
		else cnt[++kind]=1,num[kind]=a[i];
	}
	if(kind>3)
		printf("No\n");
	else if(kind==3) {
		if(cnt[1]==cnt[2]&&cnt[2]==cnt[3]&&(num[1]^num[2]^num[3])==0)
			printf("Yes\n");
		else printf("No\n");
	}
	else if(kind==2) {
		if(num[1]==0&&cnt[1]*2==cnt[2])
			printf("Yes\n");
		else printf("No\n");
	}
	else if(kind==1) {
		if(num[1]==0)
			printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 2010;

int n, a[N], t[N][N], deg[N];

bool vis[N];

VI edge[N];

void dfs(int u)
{
	vis[u] = 1;
	for (int j = 1; j <= n; ++j)
		if (!vis[j] && t[u][j])
			edge[u].pb(j), ++deg[j], dfs(j);
}

priority_queue<int> pq;

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (__gcd(a[i], a[j]) != 1)
				t[i][j] = 1;
	for (int i = 1; i <= n; ++i)
		if (!vis[i]) dfs(i);
	for (int i = 1; i <= n; ++i) if (!deg[i]) pq.push(i);
	while (!pq.empty())
	{
		int u = pq.top(); pq.pop();
		printf("%d ", a[u]);
		for (int i=0;i<(int)edge[u].size();i++)
		{
		    int v=edge[u][i];
			--deg[v];
			if (!deg[v]) pq.push(v);
		}
	}
	return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

/* a と b の最小公倍数を求める */
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int A, B;
    cin >> A >> B;
    cout << LCM(A, B) << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    // if(n == 0)cout<<2<<endl;return 0;
    // if(n == 1)cout<<1<<endl;return 0;
    int64_t l = 0LL;
    vector<int64_t>container(100);
    for(int i=0;i<=n;i++)
    {
        if(i == 0)
        {
            container[0] = 2LL;
            continue;
        }
        if(i == 1)
        {
            container[1] = 1LL;
            continue;
        }
        container[i] = container[i-1] + container[i-2];
    }
    l = container[n];
    cout<<l<<endl;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, m; cin >> n >> m;

    vector<long long> votes(m);

    for(long long i = 0; i < n; i++) {
        long long k; cin >> k;
        for(long long j = 0; j < k; j++) {
            long long x; cin >> x;
            x--;
            votes[x]++;
        }
    }

    long long ans = 0;
    for(long long i = 0; i < m; i++) {
        ans += votes[i] == n;
    }

    cout << ans;

    return 0;
}


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

int main() {
  int n,k,x;
  cin >> n >> k;
  
  int sum = 0;
  
  for(int i=0; i<n; i++) {
    cin >> x;
    int typea = x;
    int typeb = k -x;
    if (k < 2*x) {
      sum += k-x;
    } else {
      sum += x;
    }
  }
  
  cout << sum*2 << endl;
  
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt = 1;
  rep(i,n-1) {
    if (s.at(i) != s.at(i+1)) cnt++;
  }
  cout << cnt << endl;
}


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

int main(){
  int n,k,d[1100],a[1000]={},s[1000]={};
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>d[i];
    for(int j=0;j<d[i];j++){
        cin>>a[j];
        s[a[j]]++;
    }
  }
  int cnt=0;
  for(int i=1;i<=n;i++){
      if(s[i]==0) cnt++;
  }
  cout<<cnt;
  
}


Measured memory_bytes: 3648
#define m(a,b)(a=a<b?b:a)
long c,x[1<<17],v[1<<17],s,L,R,r,l;i;main(n){for(scanf("%d%ld",&n,&c);~scanf("%ld%d",x+i,v+i);)L+=v[i++];for(;i--;){L-=v[i];R+=v[i];m(s,L-x[i-1]*2+m(r,R-c+x[i]));}for(;i<n;){L+=v[i];R-=v[i++];m(s,R-(i!=n)*(c-x[i])*2+m(l,L-x[i-1]));}printf("%ld",s);}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int main()
{
    int a, b;
    cin >> a >> b;

    int x = 1;
    int count = 0;
    while (x < b) {
        x += a - 1;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

matrix = []
matrix.append([ int(i) for i in input().rstrip().split(' ')])
matrix.append([ int(i) for i in input().rstrip().split(' ')])

stack = [(0, 0, 0)]
ans = []
while stack:
    i, j, candies = stack.pop()
    candies += matrix[i][j]
    if i == 1 and j == n - 1:
        ans.append(candies)
    else:
        if j != n - 1:
            stack.append((i, j + 1, candies))
        if i == 0:
            stack.append((i + 1, j, candies))

print(max(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    string s;
    int one=0,zero=0;
    cin>>s;
    rep(i,s.size()) {
        if (s[i]=='0') zero++;
        else one++;
    }
    cout<<2*min(zero,one)<<endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.util.zip.Adler32;

public class Main {
    static Pair[]dp;
    static int[]a;
    static Pair dp(int i){
        if (i==0){
            return new Pair(0,-1);
        }
        if (dp[i]!=null)
            return dp[i];
        Pair sol = new Pair(i,-1);

        for (int j =0;j<18;j++){
            if ((i&1<<j)!=0){
                sol=maxmize(sol,dp(i^(1<<j)));
            }
        }
        return dp[i]=sol;
    }
    static Pair max(Pair x,Pair y){
        if (x.a==y.a)
        if (x.b>y.b)
            return x;
        return y;
    }
    static Pair maxmize(Pair x,Pair y){
        TreeSet<Integer>ts = new TreeSet<>((m,mm)->a[mm]==a[m]?m-mm:a[mm]-a[m]);
        ts.add(x.a);
        ts.add(y.a);
        if (x.b!=-1)ts.add(x.b);
        if (y.b!=-1)ts.add(y.b);
        return new Pair(ts.pollFirst(),ts.pollFirst());
    }
    static ArrayList<int[]>[]adj;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);;
        int n = sc.nextInt();
        a = new int[1<<n];
        dp= new Pair[1<<n];
        for (int i =0;i<1<<n;i++)a[i]=sc.nextInt();
        int[] ans = new int[1<<n];
        for (int i =1;i<1<<n;i++){
            Pair s = dp(i);
            ans[i]=a[s.a]+a[s.b] ;
            ans[i]=Math.max(ans[i],ans[i-1]);
            pw.println(ans[i]);
        }

        pw.flush();
    }
    static class Pair{
        int a,b;
        public Pair(int x ,int y){
            a=x;
            b=y;
        }

        @Override
        public Pair clone() {
            return new Pair(a,b);
        }
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 76912
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    char s;
    cin >> s;

    if(s=='A'){
        cout << 'T' << endl;
    }
    if(s=='T'){
        cout << 'A' << endl;
    }
    if(s=='C'){
        cout << 'G' << endl;
    }
    if(s=='G'){
        cout << 'C' << endl;
    }

    return 0;
}

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

int main(void)
{
  int n,inp,m=0,j=1;
  vector<int> a;

  cin>>n;

  for(int i=0;i<n;i++)
  {
    cin>>inp;
    a.push_back(inp);
  }
  
  if(a[a[0]] == a[0])
    {
      cout<<-1<<endl;
    }
    else
    {
      while(m!=n)
      {
        if(a[j-1]==2)
        {
          cout<<m+1<<endl;
          break;
        }
        else
        {
          j=a[j-1];
          m++;
        }
        if(m==n)
        {
          cout<<-1<<endl;
        }
      }
    }
}


Measured memory_bytes: 1020
N,K,C=map(int,input().split())
S=input()
L=[0 for i in range(K)]
R=[0 for i in range(K)]
n=0
rc=0
lc=0
while True:
  if lc==K:
    break
  if S[n]=="o":
    L[lc]=n+1
    n+=C+1
    lc+=1
  else:
    n+=1
n=N-1
while True:
  if rc==K:
    break
  if S[n]=="o":
    R[K-1-rc]=n+1
    n-=C+1
    rc+=1
  else:
    n-=1
for i in range(K):
  if R[i]==L[i]:
    print(R[i])


Measured memory_bytes: 20664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	m := nextInt()
	al := make([]int, a)
	bl := make([]int, b)
	for i := 0; i < a; i++ {
		al[i] = nextInt()
	}
	for i := 0; i < b; i++ {
		bl[i] = nextInt()
	}

	mat := nextIntMat(m, 3)
	cost := 0

	// 不使用時最小金額探索
	amin := 1000000
	bmin := 1000000
	for i := 0; i < a; i++ {
		amin = min(amin, al[i])
	}
	for i := 0; i < b; i++ {
		bmin = min(bmin, bl[i])
	}
	cost = amin + bmin

	//使用時最小金額探索
	for i := 0; i < m; i++ {
		r := mat[i][0] - 1
		d := mat[i][1] - 1
		c := mat[i][2]
		cost = min(cost, al[r]+bl[d]-c)
	}

	fmt.Println(cost)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func nextIntMat(a int, b int) [][]int {
	mat := make([][]int, a)
	for i := 0; i < a; i++ {
		mat[i] = make([]int, b)
		for j := 0; j < b; j++ {
			mat[i][j] = nextInt()
		}
	}
	return mat
}
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 10912
w = input()
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
  if w.count(alpha[i])%2!=0:
    print("No")
    break
  elif i == 25 and w.count(alpha[i])%2==0:
    print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
int x[505], a[2500005];
int n, vs[2500005];
int main() {
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &x[i]), a[x[i]] = i, vs[x[i]] = 1;
	int p = 0;
	rep(i, 1, n * n) {
		if(vs[i] == 0) continue;
		int y = a[i] - 1;
		while(y--) {
			++p;
			while(a[p]) ++p;
			a[p] = a[i];
		}
		if(p >= i) {puts("No"); return 0;}
	}
	rep(i, 1, n * n) {
		if(vs[i] == 0) continue;
		int y = n - a[i];
		
		while(y--) {
			++p;
			while(a[p]) ++p;
			if(p <= i) {puts("No"); return 0;}
			a[p] = a[i];
		}
	}
	puts("Yes");
	rep(i, 1, n * n) printf("%d ", a[i]);
	return 0;
}


Measured memory_bytes: 6016
def solve():
    N, W = map(int, input().split())
    weight = [0 for i in range(N)]
    value = [0 for i in range(N)]
    for i in range(N):
        weight[i], value[i] = map(int, input().split())
    dp = [0 for w in range(W + 1)]

    for i in range(N):
        wi = weight[i]
        vi = value[i]
        for w in range(W, -1, -1):
            _w = w + wi
            _v = dp[w] + vi
            if _w > W: continue
            if _v <= dp[_w]: continue
            dp[_w] = _v
    return dp[-1]

print(solve())


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int X, Y, Z;
  std::cin >> X >> Y >> Z;
  std::swap(X, Y);
  std::swap(X, Z);

  std::cout << X << ' ' << Y << ' ' << Z << '\n';
}


Measured memory_bytes: 256
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
(0...n).each do |i|
  if arr[i] > i + 1
    puts '-1'
    exit(0)
  end
end
list = []
while arr.count > 0
  delete_index = 0
  (1...arr.count).each do |i|
    item = arr[i]
    if i + 1 == item
      delete_index = i
    end
  end
  list << arr[delete_index]
  arr.delete_at(delete_index)
end
puts list.reverse

Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/





int main() {

	int q;
	cin >> q;

	ll sum = 0;
	ll first_sum = 0;
	ll latter_sum = 0;

	priority_queue<ll>	first;
	priority_queue < ll, vector<ll>, greater<ll> > latter;


	for (int _ = 0; _ < q; _++)
	{
		int a, b, c;
		cin >> a;
		if (a == 1) {
			cin >> b >> c;
			sum += c;//

			if (first.size() > latter.size()) {
				//後半に追加
				
				
				ll t = first.top();

				if (b >= t) {
					latter.push(b);
					latter_sum += b;
				}
				else
				{
					//前半の最大値を後半にもっていく
					//前半の最大値を取り出す
					first.pop();
					first_sum -= t;

					//後半に追加
					latter.push(t);
					latter_sum += t;
					
					//前半にクエリのxを加える
					first.push(b);
					first_sum += b;
				}

			}
			else
			{
				//前半に追加
				if (first.empty()) {
					first_sum += b;
					first.push(b);
				}
				else
				{
					//まずは後半の最大のものと比較
					ll t = latter.top();
					if (b <= t) {
						//後半の最小値以下ならば前半に追加
						first.push(b);
						first_sum += b;
					}
					else
					{
						//後半に追加すべきもの
						//後半の最大値を取り出す
						latter.pop();
						latter_sum -= t;

						//前半に入れる
						first.push(t);
						first_sum += t;

						//クエリの値は後半に入れる
						latter.push(b);
						latter_sum += b;
					}
				}
			}
		}
		else
		{
			
			ll mid = first.top();
			ll ans = (mid * (ll)first.size() - first_sum) + (latter_sum - mid * (ll)latter.size()) + sum;

			cout << mid << " " << ans << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
ll gcd(ll x, ll y)
{
  while (y) {
	ll r = x % y;
  	x = y; y = r;
  }
  return x;
}
int main()
{
  ll K, sum = 0; cin >> K;
  rep(i, 1, K + 1) {
  	rep(j, 1, K + 1) {
    	rep(k, 1, K + 1) {
        	sum += gcd(gcd(i, j), k);
        }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define 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)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    char c[2][3];
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>c[i][j];
        }
    }
    if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static final int INF=Integer.MAX_VALUE;
	static int size =1;
	static int[] val;
	static int[] lazy;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int n,q;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		q = sc.nextInt();
		
		
		while (size <n)
			size*=2;
		val = new int[size*2-1];
		lazy = new int[size*2 - 1];
		
		for(int i = 0;i<size*2-1;i++) {
			val[i] = INF;
			lazy[i] = -1;
		}
		
		String[] op = new String[q+1];
		for(int i=0;i<op.length;i++)
			op[i] = sc.nextLine();
		for(int i=1;i<=q;i++) {
			String[] Split = op[i].split(" ");
			int x,y,z;
			if(Integer.parseInt(Split[0]) == 0) {
				x = Integer.parseInt(Split[1]);
				y = Integer.parseInt(Split[2]);
				z = Integer.parseInt(Split[3]);
				Update(x,y+1,z);
			}else {
				x = Integer.parseInt(Split[1]);
				y = Integer.parseInt(Split[2]);
				int result = GetMin(x,y+1);
				System.out.println(result);
			}
			
		}
		
	}
	
	public static void lazy_propagate(int p) {
		if(lazy[p] !=-1) {
			val[p] = lazy[p];
			if(p< (size-1)) {
				lazy[p*2+1] = lazy[p];
				lazy[p*2+2] = lazy[p];
			}
			lazy[p] = -1;
		}
	}
	public static void update(int wishl,int wishr,int watchl,int watchr,int k,int x) {
		if(wishr <= watchl || watchr <= wishl) {
			lazy_propagate(k);
			return;
		}
		if(wishl <= watchl && watchr <= wishr) {
			lazy[k] = x;
			lazy_propagate(k);
			return;
		}
		int mid = (watchl+watchr)/2;
		lazy_propagate(k);
		update(wishl,wishr,watchl,mid,k*2+1,x);
		update(wishl,wishr,mid,watchr,k*2+2,x);
		val[k] = Math.min(val[k*2+1], val[k*2+2]);
	}
	public static void Update(int wishl,int wishr,int x) {
		update(wishl,wishr,0,size,0,x);
	}
	public static int getMin(int wishl,int wishr,int watchl,int watchr,int k ) {
		if(wishr <= watchl || watchr <= wishl) {
			return INF;
		}
		if(wishl <= watchl && watchr<=wishr) {
			lazy_propagate(k);
			return val[k];
		}
		int mid = (watchl+watchr)/2;
		lazy_propagate(k);
		int ml = getMin(wishl,wishr,watchl,mid,k*2+1);
		int mr = getMin(wishl,wishr,mid,watchr,k*2+2);
		return Math.min(ml, mr);
	}
	public static int GetMin(int wishl,int wishr) {
		return getMin(wishl,wishr,0,size,0);
	}
	
}



Measured memory_bytes: 191340
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#define int long long
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define fcout cout << fixed << setprecision(10)
using namespace std;

signed main() {
  int n;
  cin >> n;
  int c = 0;
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    if(a == b) {
      c++;
      if(c >= 3) {
        cout << "Yes\n";
        return 0;
      }
    }
    else c = 0;
  }
  cout << "No\n";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define fi first
#define se second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<ll, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const double PI = acos(-1);
const double EPS = 1e-9;
char mapa[12345];

string change(string txt)
{
    string res;
    memset(mapa,0,sizeof mapa);
    char chr='a';
    forr(i,0,txt.size())
    {
        if (mapa[txt[i]]==0)
            mapa[txt[i]]=chr++;
        res+=mapa[txt[i]];
    }
    return res;
}
set<string> s;
int n;
void go(string txt,int pos)
{
    if (txt.size()==n)
    {
        //cout<<txt.size()<<endl;
        s.insert(change(txt));
        return;
    }
    char chr='a';
    forr(i,0,pos)
    {
        go(txt+char('a'+i),pos);
    }
    go(txt+char('a'+pos),pos+1);
}
int main()
{    
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    go("",0);
    for( auto ite=s.begin();ite!=s.end();ite++)
    {
        cout<<(*ite)<<endl;
    }
    
}
// PLUS ULTRA!
    


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long n,ans=1000,now,k;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  now=a[0];
  for(int i=0;i<n;i++){
  	if(a[i]>now){
    	k=ans/now;
        ans=ans%now+k*a[i];
        now=a[i];
    }else{
    	now=a[i];
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3584
class BIT:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __str__(self):
        return "BIT: [{}]".format(
            ", ".join(str(self.sum(i + 1) - self.sum(i))
                      for i in range(self.size))
        )

    def bisect(self, w):
        bit, N = self.tree, self.size
        i = 0
        k = 1 << (N.bit_length() - 1)
        while k > 0:
            if i + k <= N and bit[i + k] < w:
                w -= bit[i + k]
                i += k
            k //= 2
        return i + 1

N, *A = map(int, open(0).read().split())

memo = {a: i for i, a in enumerate(sorted(set(A)), 1)}
B = [memo[a] for a in A]
M = len(memo) + 10

bit = BIT(M)
for b in B:
    s = bit.sum(b - 1)
    if s > 0:
        i = bit.bisect(s)
        bit.add(i, -1)
    bit.add(b, 1)

print(bit.sum(M))


Measured memory_bytes: 24792
////////////////いろいろあるよ//////////////////////////////////
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////

int main(){
	int A,B;
	cin >> A >> B;
  	int ans = min(A,B);
  	int noans=max(A,B);
	int AA;
	AA = pow(10,noans);
  	int aans=0;
  	for(int i=1;i < AA;i*=10)aans=aans+i*ans;
	cout << aans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
  int N, M, i;
  int A[100];
  int cnt = 0;
  double sum = 0;
  
  scanf("%d %d", &N, &M);
  for(i = 0; i < N; i++)
  {
    scanf("%d", &A[i]);
    
    sum += A[i];
  }
  
  for(i = 0; i < N; i++)
  {
     if(A[i] >= sum / (4 * M))
    {
      cnt++;
    }
  }
  
  if(cnt >= M)
    printf("Yes\n");
 
  else
    printf("No\n");
  
  return 0;
}


Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
int S[10];
int P[10];

int main()
{
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) 
        {
            int s;
            cin >> s;
            S[i] += 1 << (s - 1);
        }
        // cout << "* " << S[i] << endl;
    }
    for (int i = 0; i < M; i++)
        cin >> P[i];

    int ans = 0;
    for (int sw = 0; sw < 1 << N; sw ++)
    {
        bool flag = true;
        for (int i = 0; i < M; i++)
        {
            // cout << "# " << __builtin_popcount(S[i] & sw) << " " << S[i] << ' ' << sw << endl;
            if (__builtin_popcount(S[i] & sw) % 2 != P[i])
            {
                flag = false;
                break;
            }
        }
        if (flag)
            ans ++;
    }
    cout << ans << endl;
   	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vi64 = vector<int64_t>;
using vvi64 = vector<vi64>;
#define rep(i, n) for (int64_t i = 0; i < (n); ++i)
#define repe(i, n) for (int64_t i = 0; i <= (n); ++i)
#define reps(i, s, n) for (int64_t i = (s); i < (n); ++i)
#define repse(i, s, n) for (int64_t i = (s); i <= (n); ++i)
#define repr(i, n) for (int64_t i = (n); i >= 0; --i)
#define all(xs) (xs).begin(), (xs).end()
#define pp_vec(xs) rep (i, (xs).size()) if { (i) cout << endl; cout << (xs)[i] << " "; };
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;


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

  int A, B; cin >> A >> B;
  if (A >= 13) printf("%d\n", B);
  else if (A >= 6) printf("%d\n", B / 2);
  else printf("0\n");

  return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int();
        var ans = Math.Min(Calc(H, W), Calc(W, H));
        Console.WriteLine(ans);
    }

    private long Calc(long H, long W)
    {
        long res = long.MaxValue;
        for (int aw = 1; aw <= W / 2; aw++)
        {
            long bw = W - aw;
            long areaA = aw * H, areaB = bw * H;
            CheckMin(ref res, Calc2(areaA, bw, H));
            CheckMin(ref res, Calc2(areaA, H, bw));
            CheckMin(ref res, Calc2(areaB, aw, H));
            CheckMin(ref res, Calc2(areaB, H, aw));
        }
        return res;
    }

    private long Calc2(long areaA, long W, long H)
    {
        if (W < 2) return long.MaxValue;
        long areaB = W / 2 * H;
        long areaC = (W - W / 2) * H;
        var area = new[] { areaA, areaB, areaC };
        Array.Sort(area);
        return area[2] - area[0];
    }

    bool CheckMin(ref long a, long b) { if (b < a) { a = b; return true; } return false; }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 15436
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int N;
ll arr[100005], ans[100005];
std::vector<ll> v;

set<ll> done;

ll largestEle, secLargestEle;
map<ll, ll> mp, cc;

int main()
{
	int i, j;

	si(N);

	fl(i,0,N)
	{
		sll(arr[i]);		
		if(mp.find(-arr[i]) == mp.end())
		{
			mp[-arr[i]] = i;
		}
		cc[arr[i]]++;
	}

	map<ll,ll>::iterator itr, ii;
	ll eles = 0;
	ll minInd = N + 1;

	for(itr = mp.begin(); itr != mp.end(); itr++)
	{
		ll thisEle = itr->first;
		thisEle *= -1;
		ll thisMinIndex = itr->second;
		minInd = min(thisMinIndex, minInd);

		eles += cc[thisEle];

		ii = itr;
		ii++;

		ll nextEle = 0;

		if(ii != mp.end())
		{
			nextEle = ii->first;
			nextEle *= -1;
		}

		// cout << minInd << "\n";

		ans[minInd] += eles * (thisEle - nextEle);
	}

	fl(i,0,N)
		printf("%lld\n", ans[i]);


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 15104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		HashMap<String,Integer> order=new HashMap<String,Integer>();
		Vertex[] a=new Vertex[6];
		for(int i=0; i<6; i++) {
			a[i]=new Vertex();
		}
		for(int i=0; i<N; i++) {
			String t=sc.next();
			int vol=sc.nextInt();
			if(!order.containsKey(t)) {
				order.put(t, vol);
			}
			else {
				vol+=order.get(t);
				order.put(t, vol);
			}
		}
		for(int i=0; i<order.size(); i++) {

		}
		for ( String key : order.keySet() ) {
			int data = order.get( key );
			a[key.length()].add(key,data);
		}
		for(int i=1; i<=5; i++) {
			a[i].sort();
		}
		for(int h=1; h<=5; h++) {
			for(int i=0; i<a[h].size(); i++) {
				pl(a[h].getKey(i)+" "+a[h].getValue(i));
			}
		}

	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static final class Pair<K, V> {        //powered by mikit
		public K key;
		public V value;
		public Pair(K key, V value) {
			this.key = key;
			this.value = value;
		}
		public static int getValue(Pair<String,Integer> a) {
			return a.value;
		}
		public static String getKey(Pair<String,Integer> a) {
			return a.key;
		}
	}
	public static class Vertex{
		ArrayList <Pair<String,Integer>> rinsetu=new ArrayList<Pair<String,Integer>>();
		public void add(String key,int cost) {
			rinsetu.add(new Pair<String, Integer>(key,cost));
		}
		public String getKey(int i) {
			return Pair.getKey(rinsetu.get(i)); //Valueを取り出す
		}
		public int getValue(int i) {
			return Pair.getValue(rinsetu.get(i)); //Valueを取り出す
		}
		public void sort() {      //向かう頂点の番号順にソートします
			rinsetu.sort(Comparator.comparing(p -> p.key));
		}
		public int size() {     //次数を返す
			return rinsetu.size();
		}
	}
}



Measured memory_bytes: 35484
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 1 << 18;
const LL MOD = 1000000007;
const LL INF = (LL) 1e9 + 5;

int N, a[MAXN], dp1[MAXN], dp2[MAXN];

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

	cin >> N;
	for (int i = 0; i < (1 << N); i++) {
		cin >> a[i];
		dp1[i] = a[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < (1 << N); j++) {
			if (j >> i & 1) {
				int arr[4] = {dp1[j], dp2[j], dp1[j ^ 1 << i], dp2[j ^ 1 << i]};
				sort(arr, arr + 4);
				dp1[j] = arr[3];
				dp2[j] = arr[2];
			}
		}
	}
	int ans = 0;
	for (int i = 1; i < (1 << N); i++) {
		ans = max(ans, dp1[i] + dp2[i]);
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+10;
const double inf=1e18;
#define eps 1e-12
struct edge{
	int u,v,nxt;
}g[N<<1];
int tot=0,head[N];
inline void add(int u,int v){
	g[++tot]=edge{u,v,head[u]}; head[u]=tot;
}
int n,m,s[N],t[N],dgr[N],gu[N],cnt[N],mx[N];
double sum[N],ans[N];
int pre[N];
inline void gugugu(){
	for(int i=1; i<=n; ++i)sum[i]=cnt[i]=0,gu[i]=dgr[i];
	queue <int> q; q.push(n); sum[n]=0; cnt[n]=1;
	while(!q.empty()){
		int u=q.front(); q.pop(); ans[u]=sum[u]/cnt[u];
		for(int i=head[u]; i; i=g[i].nxt){
			int v=g[i].v;
			sum[v]+=ans[u]+1; cnt[v]++; if(ans[u]+1>ans[g[mx[v]].u]+1)mx[v]=i;
			gu[v]--; if(gu[v]==0)q.push(v);
		}
	}
}
inline double bfs(int ban){
	for(int i=1; i<=n; ++i)sum[i]=cnt[i]=0,gu[i]=dgr[i];
	if(ban)gu[g[ban].v]--;
	queue <int> q; q.push(n); sum[n]=0; cnt[n]=1;
	while(!q.empty()){
		int u=q.front(); q.pop(); ans[u]=sum[u]/cnt[u];
		for(int i=head[u]; i; i=g[i].nxt){
			int v=g[i].v; if(i==ban)continue;
			sum[v]+=ans[u]+1; cnt[v]++;
			gu[v]--; if(gu[v]==0)q.push(v);
		}
	}
	return cnt[1]?ans[1]:inf;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; ++i)scanf("%d%d",&s[i],&t[i]),add(t[i],s[i]),dgr[s[i]]++;
	gugugu();
	double ans=bfs(0);
	for(int i=1; i<n; ++i)ans=min(ans,bfs(mx[i]));
	printf("%.6lf",ans);
	return 0;
}

Measured memory_bytes: 22784
#include<stdio.h>
int main(){
  int n,i,a,b,as,bs;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(as=bs=i=0;i<n;i++){
      scanf("%d %d",&a,&b);
      if(a==b){
	as+=a;
	bs+=b;
      }
      else if(a>b) as=as+a+b;
      else bs=bs+a+b;
    }
    printf("%d %d\n",as,bs);
  }
  return 0;
}



Measured memory_bytes: 1976
#include<iostream>
#include<array>
using namespace std;
void dump(const array<int,52>&A)
{
	for(int i=0;i<52;i++)
	{
		cout<<A[i];
		if(i==51)cout<<endl;
		else cout<<",";
	}
}
array<int,52>MAX,ZERO;
array<int,52>operator-(const array<int,52>&A)
{
	array<int,52>ret=A;
	for(int i=0;i<52;i++)ret[i]=-ret[i];
	return ret;
}
array<int,52>operator+(const array<int,52>&A,const array<int,52>&B)
{
	array<int,52>ret=ZERO;
	for(int i=0;i<52;i++)ret[i]=A[i]+B[i];
	return ret;
}
array<int,52>operator-(const array<int,52>&A,const array<int,52>&B)
{
	array<int,52>ret=ZERO;
	for(int i=0;i<52;i++)ret[i]=A[i]-B[i];
	return ret;
}
array<int,52>operator*(const array<int,52>&A,const int&x)
{
	array<int,52>ret=ZERO;
	for(int i=0;i<52;i++)ret[i]=A[i]*x;
	return ret;
}
bool operator<(const array<int,52>&A,const array<int,52>&B)
{
	for(int i=0;i<52;i++)if(A[i]!=B[i])return A[i]>B[i];
	return false;
}
//Minimum Cost Flow O(FE log V)
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<limits>
template<typename T>
struct MCF{
	struct edge{
		int to,rev,cap;
		T cost;
	};
	vector<vector<edge> >G;
	vector<T>h,d;
	vector<int>pv,pe;
	MCF(int n_=0):G(n_),h(n_,ZERO),d(n_),pv(n_),pe(n_){}
	void add_edge(int from,int to,int cap,T cost)
	{
		G[from].push_back({to,(int)G[to].size(),cap,cost});
		G[to].push_back({from,(int)G[from].size()-1,0,-cost});
	}
	T min_cost_flow(int s,int t,int f)//ans or -1
	{
		T ret=ZERO;
		while(f>0)
		{
			priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
			fill(d.begin(),d.end(),MAX);
			d[s]=ZERO;
			P.push(make_pair(ZERO,s));
			while(!P.empty())
			{
				pair<T,int>p=P.top();P.pop();
				if(d[p.second]<p.first)continue;
				for(int i=0;i<G[p.second].size();i++)
				{
					edge&e=G[p.second][i];
					if(e.cap>0&&d[p.second]+e.cost+h[p.second]-h[e.to]<d[e.to])
					{
						d[e.to]=d[p.second]+e.cost+h[p.second]-h[e.to];
						pv[e.to]=p.second;
						pe[e.to]=i;
						P.push(make_pair(d[e.to],e.to));
					}
				}
			}
			if(d[t]==MAX)return MAX;
			for(int u=0;u<G.size();u++)h[u]=h[u]+d[u];
			int d=f;
			for(int u=t;u!=s;u=pv[u])d=min(d,G[pv[u]][pe[u]].cap);
			f-=d;
			ret=ret+h[t]*d;
			for(int u=t;u!=s;u=pv[u])
			{
				G[pv[u]][pe[u]].cap-=d;
				G[u][G[pv[u]][pe[u]].rev].cap+=d;
			}
		}
		return ret;
	}
};
main()
{
	for(int i=0;i<52;i++)MAX[i]=-114514;
	int N;
	cin>>N;
	vector<string>A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	MCF<array<int,52> >P(2*N+2);
	for(int i=0;i<N;i++)
	{
		P.add_edge(2*N,i,1,ZERO);
		P.add_edge(N+i,2*N+1,1,ZERO);
	}
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		array<int,52>cost=ZERO;
		if(A[i][j]<='Z')
		{
			cost[A[i][j]-'A']=1;
		}
		else
		{
			cost[A[i][j]-'a'+26]=1;
		}
		P.add_edge(i,N+j,1,cost);
	}
	array<int,52>ans=P.min_cost_flow(2*N,2*N+1,N);
	for(int i=0;i<52;i++)for(int j=0;j<ans[i];j++)
	{
		char c=i<26?i+'A':i-26+'a';
		cout<<c;
	}
	cout<<endl;
}



Measured memory_bytes: 4500
import math
import sys
from itertools import permutations
input = sys.stdin.readline

N=int(input())
arr=list(map(int,input().split()))

flag=True
cur=1000
st=0
for i in range(N-1):
    if flag and arr[i+1]>arr[i]:
        st=cur//arr[i]
        cur-=st*arr[i]
        flag=False
    elif (not flag) and arr[i+1]<arr[i]:
        cur+=st*arr[i]
        st=0
        flag=True

cur+=st*arr[N-1]
print(cur)

Measured memory_bytes: 62312
#include <stdio.h>
#define SIZE 201
 
int que[SIZE];
int head, tail;
 
int init() { head = tail = 0; }
int empty() { return head == tail; }
int push(int elm) { que[tail] = elm; tail = (tail+1)%SIZE; }
int front() { return que[head]; }
void pop() { head = (head+1)%SIZE; }
 
int bfs(int n, int G[][101], int *cost) {
  int i;
  init();
  push(1);
  cost[1] = 0;
  while(!empty()) {
    int p = front();
    pop();
    for(i = 1; i <= n; ++i) {
      if(!G[p][i]) continue;
      if(cost[i] != -1) continue;
      cost[i] = cost[p] + G[p][i];
      push(i);
    }
  }
}
 
 
int main() {
  int n;
  int i,j,k;
  int G[101][101];
  int src, dst;
  int cost[101];
  for(i = 0; i < 101; ++i)  {
    cost[i] = -1;
    for(j = 0; j < 101; ++j) {
      if(i == 0) G[i][j] = 1;
      else G[i][j] = 0;
    }
  }
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf("%d %d", &src, &k);
    while(k--) {
      scanf("%d", &dst);
      G[src][dst] = 1;
    }
  }
  bfs(n,G,cost);
  for(i = 1; i <= n; ++i) {
    printf("%d %d\n", i, cost[i]);
  }
  return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const ll m = 1e9+7;
int main(){
	int n,k;
	ll ans = 0;
	scanf("%d%d",&n,&k);
	for (int i = k; i <=n+1; ++i)
	{
		ans= (ans + ((ll)(n-i+1 + n)*i/2 - ( (0 + (ll)(i-1))*i/2) + 1 ))%m;
		/* code */
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

int main(){
    FIO;
    bool flag0 = true, flag1 = true;
    ll n;
    cin >> n;
    ll arr[n], prev = -1;
    for(ll i = 0 ; i < n ; i++){
        cin >> arr[i];
    }
    for(ll i = n-2 ; i >= 0 ; i--){
        if(arr[i+1] < arr[i]){
            arr[i]--;
        }
        if(arr[i+1] < arr[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
defmodule Main do
  def main do
    [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    if a <= b do IO.puts("unsafe") else IO.puts("safe") end
  end
end


Measured memory_bytes: 30740
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    while (true) {
        val h = sc.nextInt()
        val w = sc.nextInt()
        if (h == 0 && w == 0) break
        println("${"#".repeat(w)}\n".repeat(h))
    }
}



Measured memory_bytes: 27576