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

using namespace std;

typedef vector<int> vi;

bool tarjan(vi e[], int x, bool st[], int disc[], int &dn, vi &t) {
    int dmax = -1, dmaxp = -1;
    for (int y : e[x]) {
        if (st[y] && disc[y] > dmax) {
            dmax = disc[y];
            dmaxp = y;
        }
    }

    disc[x] = ++dn;
    st[x] = true;

    if (dmaxp != -1) {
        int y = dmaxp;
        while (y != x) {
            t.push_back(y);

            int dmax = -1, dmaxz = -1;
            for (int z : e[y]) {
                if (st[z] && disc[z] > dmax) {
                    dmax = disc[z];
                    dmaxz = z;
                }
            }
            y = dmaxz;
        }
        t.push_back(x);
        return true;
    }

    for (int y : e[x]) {
        if (!disc[y]) {
            bool f = tarjan(e, y, st, disc, dn, t);
            if (f) {
                return true;
            }
        }
    }

    st[x] = false;
    return false;
}

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }

    bool st[n];
    memset(st, false, sizeof(st));
    int disc[n];
    memset(disc, 0, sizeof(disc));
    int dn = 0;
    for (int i = 0; i < n; i++) {
        if (!disc[i]) {
            vi t;
            if (tarjan(e, i, st, disc, dn, t)) {
                cout << t.size() << endl;
                for (int x : t) {
                    cout << x + 1 << endl;
                }
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 384
S = input()
l = len(S) // 2
s1 = [S[i*2] for i in range(l+(len(S) % 2))]
s2 = [S[i*2+1] for i in range(l)]
c = s1.count('1') + s2.count('0')
ret = c if c <= l else len(S) - c
print(ret)


Measured memory_bytes: 3956
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
MIN = 10**7
for i in range(2**N):
    ler = [0]*M
    money = 0
    bitlist = deque()
    for j in range(N):
        if ((i >> j) & 1): #2進数表示のj桁目(0桁目から数える)が1かどうか
            bitlist.appendleft(1)
        else:
          	bitlist.appendleft(0)
    bitlist = list(bitlist)
    for k in range(N):
        if bitlist[k] == 1:
            money += CA[k][0]
            for l in range(1,M+1):
                ll = CA[k][l]
                ler[l-1] += ll
    judge = 0
    for ju in range(M):
        if ler[ju] < X:
            judge = 1
            break
    if judge == 0:
        MIN = min(MIN,money)
if MIN == 10**7:
    print(-1)
else:
    print(MIN)

Measured memory_bytes: 27236
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    string S;
    cin >> S;
    int N = S.size();
    vector<vector<int>> dp(N + 1, vector<int>(13, 0));
    dp[0][0] = 1;
    REP(i, N) {
        int c;
        if (S[i] == '?') {
            c = -1;
        } else {
            c = S[i] - '0';
        }
        REP(j, 10) {
            if (c != -1 && c != j) {
                continue;
            }
            REP(k, 13) {
                int l = (k * 10 + j) % 13;
                dp[i + 1][l] += dp[i][k];
                dp[i + 1][l] %= MOD;
            }
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}


Measured memory_bytes: 8912
import java.util.*;
import java.util.Vector;
import java.math.*; 
public class Main {
     Scanner sc = new Scanner(System.in);
	//	System.out.println( );
	
	
	
	void run(){ // kokonikaku
		
		String s=sc.next();
		
		int l=s.length();
		
		int ans1=0,ans2=0;
		
		for(int i=0;i<l;i++){
			if(i%2==1){
				if(s.charAt(i)=='0') ans1++;
				else ans2++;
			}
			else{
				if(s.charAt(i)=='1') ans1++;
				else ans2++;
			}
		}
		
		System.out.println(Math.min(ans1,ans2));
	}

	
	public static void main(String[] args) {
		new Main().run();
        
    }
}

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

int main()
{
    int N, M;

    cin >> N >> M;

    vector<vector<int>>job_list(M);

    rep(i , N)
    {
        int A, B;
        cin >> A >> B;
        if(A > M) continue;
        job_list[M-A].push_back(B);
    }
    priority_queue<int> queue_lsit;

    long long anser = 0;

    for(int i= M-1; i >= 0; i--)
    {
        for(int B:job_list[i])
        {
            queue_lsit.push(B);
        }
        if(!queue_lsit.empty())
        {
            anser += queue_lsit.top();
            queue_lsit.pop();
        }
    }

    cout << anser << endl;

    return 0;
}


Measured memory_bytes: 5504
N, M = gets.split.map(&:to_i)
arrs = M.times.map { gets.split.map(&:to_i) }

ways = {}
arrs.each do |from, to|
  ways[from] ||= []
  ways[from] << to
  ways[to] ||= []
  ways[to] << from
end

queue = [[1, [1]]]
counter = 0
while !queue.empty?
  p, history = queue.shift
  if history.count == N
    counter += 1
    next
  end

  ways[p].each do |next_p|
    unless history.include?(next_p)
      queue.push([next_p, history + [next_p]])
    end
  end
end
puts counter

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[3];
signed main(){
	rep(i,3)cin>>a[i];
	sort(a,a+3);
	int Min=INT_MAX;
	do{
		Min=min(Min,abs(a[1]-a[0])+abs(a[2]-a[1]));
	}while(next_permutation(a,a+3));
	cout<<Min<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
A = inputIL()
B = inputIL()
C = inputIL()

ans = B[A[0]-1]
for a in range(1,N):
  i = A[a]
  ans += B[i-1]
  if i == A[a-1]+1:
    ans += C[i-2]
print(ans)
  


Measured memory_bytes: 66028
#define _CRT_SECURE_NO_WARNINGS
#define REL

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

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 60;
const int N = (int)1e6 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

void solve() {
	int a, b;
	cin >> a >> b;
	cout << (a <= b ? "unsafe" : "safe");
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
  string s;
  cin>>s;
  int N=s.size(),a=0,b=0;
  for(int i=0;i<N;i++){
    if(s[i]=='0') a++;
    else b++;
  }
  cout<<min(a,b)*2<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int A, B, C;
  cin >> A >> B >> C;

  int X = max({A, B, C});
  int min = (3*X - (A+B+C))/2;
  if((3*X)%2 - (A+B+C)%2 == 0) {
    cout << min << endl;
  }else{
    cout << min+2 << endl;
  }

  return 0;
}

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

int main(void) {
    int H, W;
    
    while(true) {
        cin >> H >> W;
        if(H == 0 && W == 0)   break;
        
        for(int w = 0; w < W; ++w) {
            cout << "#";
        }
        cout << endl;
        for(int h = 0; h < H - 2; ++h) {
            cout << "#";
            for(int w = 0; w < W - 2; ++w) {
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(int w = 0; w < W; ++w) {
            cout << "#";
        }
        cout << endl;
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3044
/*
 * 16-9-11_ABC045_B.cpp
 *
 *  Created on: 2016/09/11
 *      Author: ryoma
 */

#include<iostream>
#include<string>

using namespace std;

string sa,sb,sc;
int a,b,c,turn;
int main(){
	cin >> sa >> sb >> sc;
	while(1){
		switch(turn){
		case 0:
			if(a >= sa.length()){
				cout << "A" << endl;
				return 0;
			}
			turn = sa[a] - 'a';
			a++;
			break;
		case 1:
			if(b >= sb.length()){
				cout << "B" << endl;
				return 0;
			}
			turn = sb[b] - 'a';
			b++;
			break;
		case 2:
			if(c >= sc.length()){
				cout << "C" << endl;
				return 0;
			}
			turn = sc[c] - 'a';
			c++;
			break;
		}
	}
	return 0;
}





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

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

int main() {
    long long X, Y;
    cin >> X >> Y;
    long long cou = 0;
    while (X <= Y) {
        X *= 2;
        cou++;
    }
    cout << cou << endl;
}

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

using namespace std;

#define lli long long int

lli dp[100005],a[100005];

int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        dp[i] = 1e10;
    }
    dp[1] = 0;
    for(int i=2; i<=n; i++)
    {
        lli mx = max( 1,i-k);
        for(int j=i-1; j>=mx; j--)
        {
            dp[i] = min(dp[i],abs(a[i]-a[j])+dp[j]);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int res = 0;

    for (int i = 1; i < N; i++)
        res = max(res, A[i] - A[i-1]);
    res = max(res, K - A[N-1] + A[0]);

    cout << K - res << "\n";

    return 0;
}


Measured memory_bytes: 1024
PROGRAM piyo
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      character(10**5) :: s
      integer(prec) :: len, i, ans=0
      
      read*,s
      len = len_trim( s )
      
      if( len==1 )then
        print*,0
        stop
      end if
      
      do i = 2,len
        if( s(i:i)/=s(i-1:i-1) )then
          ans = ans + 1
        end if
      end do
      
      print*,ans
      
      
      stop
      !debugg
      
      print*,trim( s )
      print*,len
      
      
      
      END PROGRAM

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < SIZE; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

LL Bin(LL n, LL k) {
    if(k < 0 || n < k) {
        return 0;

    }
    LL ret = 1;
    for(LL i = 1; i <= k; ++i) {
        ret *= n--;
        ret /= i;

    }
    return ret;
}


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

    int n;
    cin >> n;
    LL cnt[5] = {};
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s[0] == 'M') ++cnt[0];
        if(s[0] == 'A') ++cnt[1];
        if(s[0] == 'R') ++cnt[2];
        if(s[0] == 'C') ++cnt[3];
        if(s[0] == 'H') ++cnt[4];

    }

    LL res = 0;
    for(int i = 0; i < 5; ++i) {
        for(int j = i + 1; j < 5; ++j) {
            for(int k = j + 1; k < 5; ++k) {
                res += cnt[i] * cnt[j] * cnt[k];

            }
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	int n, h, w;
	int count = 0;
	int a, b;

	cin >> n >> h >> w;
	FOR(i, 1, n) {
		cin >> a >> b;
		if (a >= h && b >= w) {
			count++;
		}
	}
	cout << count << endl;


	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# まずは桁数を増やす→数字の大きい順に並べる
N, M = lr()
A = lr()
matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = [(matches[a], a) for a in A]
A.sort(key = lambda x: x[1], reverse=True)
A.sort(key = lambda x: x[0])
top_match = A[0][0]
dp = [None] * (N+1)
dp[0] = []
used = set()
for match, num in A:
    if match in used:
        continue
    used.add(match)
    for x in range(N+1):
        if x - match < 0:
            continue
        if dp[x] == None and dp[x-match] != None:
            dp[x] = dp[x-match] + [num]
        elif dp[x] != None and dp[x-match] != None:
            if len(dp[x-match]) >= len(dp[x]):
                dp[x] = dp[x-match] + [num]
            elif len(dp[x-match]) >= 1 and len(dp[x-match]) == len(dp[x]) - 1:
                y = list(map(str, dp[x][::-1])); y.sort(reverse=True)
                z = [str(num)] + list(map(str, dp[x-match][::-1])); z.sort(reverse=True)
                y = int(''.join(y))
                z = int(''.join(z))
                if z > y:
                    dp[x] = dp[x-match] + [num]

X = dp[N]
X.sort(reverse=True)
answer = ''.join(list(map(str, X)))
print(answer)
# 37


Measured memory_bytes: 255112
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
vector<int> t[maxn];
int p[maxn];
long long lazy[maxn], ans[maxn];
void init(){
    for(int e = 0; e < maxn; e++){
        p[e] = e;
        lazy[e] = 0;
        t[e].push_back(e);
    }
}
int find(int x){
    if(p[x] == x) return x;
    return p[x] = find(p[x]);
}
void join(int u, int v, int w){
    u = find(u);
    v = find(v);
    assert(u != v);
    if(t[u].size() < t[v].size()) swap(u, v);
    for(int x : t[v]){
        ans[x] -= 1ll * t[v].size() * w;
        ans[x] += 1ll * t[u].size() * w;
        ans[x] += lazy[v];
        ans[x] -= lazy[u];
    }
    lazy[u] += 1ll * t[v].size() * w;
    for(int x : t[v]) t[u].push_back(x);
    p[v] = u;
    lazy[v] = 0;
    t[v].clear();
}
int uu[maxn], vv[maxn], ww[maxn], od[maxn];
int main(){
    int n;
    scanf("%d", &n);
    for(int e = 0; e < n - 1; e++) scanf("%d %d %d", uu + e, vv + e, ww + e), uu[e]--, vv[e]--;
    for(int e = 0; e < n - 1; e++) od[e] = e;
    sort(od, od + n - 1, [&](int a, int b){
        return ww[a] > ww[b];
    });
    init();
    for(int e = 0; e < n - 1; e++) join(uu[od[e]], vv[od[e]], ww[od[e]]);
    for(int e = 0; e < n; e++) ans[e] += lazy[find(e)];
    for(int e = 0; e < n; e++) printf("%lld\n", ans[e]);
    return 0;
}


Measured memory_bytes: 13944
#include <cstdio>
#include <algorithm>
#include <set>
#include <iostream>

using namespace std;

const int N = 100'009;

int a[N];
int b[N];
int ab[N];
int o[N];

int main() {
  int n;
  scanf("%d", &n);
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", a + i, b + i);
    sa += a[i];
    sb += b[i];
    ab[i] = a[i] + b[i];
  }
  long long ans = min(sa, sb);
  if (n % 2 == 0) {
    sort(ab, ab + n);
    long long cur = 0;
    for (int i = 0; i < n / 2; ++i) {
      cur += ab[i];
    }
    ans = min(ans, cur);
  }
  auto cmp_mn = [](int i, int j) {
    int mni = min(a[i], b[i]);
    int mnj = min(a[j], b[j]);
    int mxi = max(a[i], b[i]);
    int mxj = max(a[j], b[j]);
    if (mni != mnj) {
      return mni > mnj;
    }
    if (mxi != mxj) {
      return mxi > mxj;
    }
    return i < j;
  };
  auto cmp_mx = [](int i, int j) {
    int mni = min(a[i], b[i]);
    int mnj = min(a[j], b[j]);
    int mxi = max(a[i], b[i]);
    int mxj = max(a[j], b[j]);
    if (mxi != mxj) {
      return mxi < mxj;
    }
    if (mni != mnj) {
      return mni > mnj;
    }
    return i < j;
  };
  set<int, decltype(cmp_mn)> mn(cmp_mn);
  set<int, decltype(cmp_mx)> mx(cmp_mx);
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    cur += min(a[i], b[i]);
    mn.insert(i);
    mx.insert(i);
  }
  while ((int)mn.size() >= 3) {
    int i = *mn.begin();
    int j = *mx.begin();
    if (i != j) {
      cur -= min(a[i], b[i]);
      cur += max(a[j], b[j]);
      mn.erase(i);
      mn.erase(j);
      mx.erase(i);
      mx.erase(j);
    } else {
      long long tmp_mn = cur;
      tmp_mn -= min(a[i], b[i]);
      mx.erase(i);
      int k_mn = *mx.begin();
      tmp_mn += max(a[k_mn], b[k_mn]);
      mx.insert(i);
      long long tmp_mx = cur;
      tmp_mx += max(a[i], b[i]);
      mn.erase(i);
      int k_mx = *mn.begin();
      tmp_mx -= min(a[k_mx], b[k_mx]);
      mn.insert(i);
      mn.erase(i);
      mx.erase(i);
      if (tmp_mn < tmp_mx) {
        cur = tmp_mn;
        mn.erase(k_mn);
        mx.erase(k_mn);
      } else {
        cur = tmp_mx;
        mn.erase(k_mx);
        mx.erase(k_mx);
      }
    }
    ans = min(ans, cur);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 10752
#pragma GCC positionimize(3,"Otrst","inline")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<tr1/unordered_map>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+10;
const int INF=0x3fffffff;
const double pi = 3.141592653;
const double E = 2.71828182846;
//const ll mod=9999991;
const int M=2e4+5;
const double eps=1e-8;
const ll MMod=1ll<<32;
#define ci(x) scanf("%lld",&x)
#define co(x) printf("%lld\n",x)

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

ll fast_muttki(ll m, ll n,ll mod)//快速乘法
{
    ll cnt = 0;//注意初始化是0，不是1
    while (n)
    {
        if (n & 1)
        {
            cnt += m;
            cnt %= mod;
        }
        m = (m + m) % mod;//和快速幂一样，只不过这里是加
        n >>= 1;
    }
    return cnt;
}
ll fast_get(ll a, ll n,ll mod)//快速幂
{
    ll cnt = 1;
    while (n)
    {
        if (n & 1)
            cnt = fast_muttki(cnt,a,mod);//不能直接乘
        a = fast_muttki(a, a,mod);
        cnt %= mod;
        a %= mod;
        n >>= 1;
    }
    return cnt;
}

ll n,m;
string s;
ll a[N];
ll b[N];
ll p[N];

int main()
{
    ci(n);
    for(int i=1;i<=n;i++)
    {
        ci(p[i]);
    }
    for(ll i=1;i<=n;i++)
    {
        a[i]=i*20003;
        b[i]=(n-i+1)*20003;
    }
    for(int i=1;i<=n;i++)
    {
        a[p[i]]+=i;
        b[p[i]]+=i;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",a[i]);
    }
    printf("\n");
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",b[i]);
    }
    printf("\n");
    return 0;
}
// 5 5 2 1 5 4  = 9
// 5 2 1 5 4 5  = 7
// 5 5 2 1 4 5  = 8


Measured memory_bytes: 4864
'use strict'

function main(input) {
  const lines = input.split('\n');
  lines.pop();
  const n = lines.shift();
  f(lines);
}

function f(lines) {
  const parsed = {}
  lines.forEach(line => {
    const sorted = line.split('').sort().join('');
    if (!!parsed[sorted]) {
      parsed[sorted] += 1;
    } else {
      parsed[sorted] = 1;
    }
  });
  let result = 0;
  Object.keys(parsed).forEach(k => {
    const v = parsed[k];
    if (v === 2) {
      result += 1;
    } else if (v > 2) {
      result += (v * (v - 1)) / 2;
    }
  });
  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 44252
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int a, b; std::cin >> a >> b;
	if (a > 9 || b > 9) {
		std::cout << -1 << '\n';
	}
	else {
		std::cout << a * b << '\n';
	}
}


Measured memory_bytes: 888
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
A,B,C,D = [x for x in S()]
for op1,op2,op3 in itertools.product(['+','-'],repeat=3):
    ans = A+op1+B+op2+C+op3+D
    if eval(ans)==7:
        print(ans+'=7')
        break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define IL inline
#define _
#define ll long long
using namespace std ;

IL ll gi(){
    ll data = 0 , m = 1; char ch = 0;
    while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
    if(ch == '-'){m = 0 ; ch = getchar() ; }
    while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
    return (m) ? data : -data ; 
}

ll K , A , B ;

int main() {
	K = gi() ; A = gi() ; B = gi() ;
	ll x = 1 , y = 0 ;
	x += min(K , A - x) ; K -= min(K , A - 1) ;
	ll fa = 2 , fb = B - A ;
	if(fa >= fb) x += K ;
	else {
		x += (K / 2) * fb ; if(K & 1) ++ x ; 
	}
	cout << x << endl ; return 0 ;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    cout << (n+2-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  int n = s.size();

  vector<int> rle(0);
  if(s[0]=='>'){
    rle.push_back(1);
  }
  int cnt = 1;
  rep(i,n-1){
    if(s[i]!=s[i+1]){
      rle.push_back(cnt);
      cnt=1;
    }
    else{
      cnt++;
    }
  }
  rle.push_back(cnt);
  if(s[n-1]=='<'){
    rle.push_back(1);
  }

  ll res=0;
  int m = rle.size();
  for(int i=0;i<m;i+=2){
    ll x=rle[i],y=rle[i+1];
    if(x>y){
      res += (x+1)*x/2 + (y-1)*y/2;
    }
    else{
      res += (x-1)*x/2 + (y+1)*y/2;
    }
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

ll H,W,Ch,Cw,Dh,Dw;
vector<vector<ll>> G(1005,vector<ll>(1005));
vector<ll> d(1000100,INF);

void dijkstra(){
    
    d[Ch*W+Cw] = 0;
    priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>> pque;
    pque.push(make_tuple(0,Ch,Cw));
    while(!pque.empty()){
        tuple<ll,ll,ll> p = pque.top();
        pque.pop();
        ll y=get<1>(p);
        ll x=get<2>(p);
        ll cost=get<0>(p);
        if( cost > d[y*W+x] )continue;
        rep(dir,4){
            ll ny = y + dy[dir] ;
            ll nx = x + dx[dir] ;
            if(!In_map(ny,nx,H,W)) continue;
            if(G[ny][nx]){
                for(int j =-2;j<=2;j++){
                    for(int k =-2;k<=2;k++){
                        ll nny= y+j;
                        ll nnx = x+k;
                        if(j==0&&k==0)continue;
                        if(!In_map(nny,nnx,H,W)) continue;
                        if(G[nny][nnx])continue;
                        ll newcost = cost+1 ;
                        if(newcost < d[nny*W+nnx]){
                            d[nny*W+nnx] = newcost;
                            pque.push(make_tuple(d[nny*W+nnx],nny,nnx));
                        }

                    }
                }
            }else{
                ll newcost = cost ;
                if(newcost < d[ny*W+nx]){
                    d[ny*W+nx] = newcost;
                    pque.push(make_tuple(d[ny*W+nx],ny,nx));
                }
            }
            
        }

    }

}
int main() {
    cin >>H>>W>>Ch>>Cw>>Dh>>Dw;
    Ch--;Cw--;Dh--;Dw--;
    rep(i,H){
        rep(j,W){
            char c;
            cin>>c;
            if(c=='#'){
                G[i][j]=1;
            }
        }
    }
    dijkstra();
    if(d[Dh*W+Dw]==INF){
        cout<<-1<<endl;
    }else{
        cout << d[Dh*W+Dw] << endl;
    }
    


    return 0;
    

}

Measured memory_bytes: 19600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		double min= 100000;
		int num = 0;
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			double re = Math.abs(A-(T-temp *0.006));
			if (re<min) {
				min = re;
				num =i+1;
			}
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 38804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }

  vector<bool> b(n, false);
  int pos = 0;
  b[pos] = true;
  int cnt = 0;
  while(pos != 1){
    pos = a[pos];
    if(b[pos]){
      cout << -1 << endl;
      return 0;
    }
    cnt++;
    b[pos] = true;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = 2 * x.first + x.second;qc%=3;
		c ^= (qc+1);
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
	c = 0;
	int d = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second - 1;
		if ((w & x.first) == w) { c ^= 1; }
		w++;
		if ((w & x.first) == w) { d ^= 1; }
	}
	ans.first *= 2; ans.second *= 2;
	ans.first += (c | d); ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}

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

signed main()
{
	string s;
	cin >> s;
	int dem=0;
	int maxx=0;
	for (int i=0;i<s.length();i++){
		if (s[i]=='S'){
			maxx=max(dem,maxx);
			dem=0;
		}
		else {
			dem++;
		}
	}
	maxx=max(dem,maxx);
	cout << maxx;
}

Measured memory_bytes: 3592
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
const static sl M = 3;
static vector<sl> Ai;

void solve(void) {
  vector<sl> C(N);
  vector<vector<sl>> D(N, vector<sl>(M, 0));
  auto q = [&](sl i, sl v) {
    vector<sl> res;
    FOR0(j, M) {
      if (D[i][j] == v) {
        res.push_back(j);
      }
    }
    return res;
  };
  if (Ai[0] == 0) {
    C[0] = M;
    D[0][0] = 1;
  }
  FORi(i, 1, N) {
    auto X = q(i - 1, Ai[i]);
    C[i] = X.size();
    D[i] = D[i - 1];
    if (X.size() > 0) {
      D[i][X[0]]++;
    }
  }
  ul ret = 1;
  FOR0(i, N) {
    ret *= C[i];
    ret %= 1000000007;
  }
  cout << ret << endl;
}

int main(void) {
  cin >> N;
  Ai.resize(N);
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[100001],maxn,m1=(int)2.1e9,m2;

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		maxn=max(maxn,a[i]);
	}
	for(int i=1;i<=n;++i){
		if(a[i]==maxn)continue;
		int dst=abs(maxn-a[i]*2);
		if (m1>dst){m1=dst;m2=a[i];}
	}
	cout<<maxn<<" "<<m2<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <cstring>


using namespace std;
#define int long long

int tmp[5] = {};
string s;
vector<int> num;
vector<int> ans;


void Refresh() {
	for (int i = 0; i < ans.size(); i++) {
		ans[i] = num[0];
	}
}

signed main()
{

	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		tmp[i] = s[i] - 48;
	}
	int N;
	cin >> N;
	bool ttmp[10] = {};
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		ttmp[t] = true;
	}
	for (int i = 0; i < 10; i++) {
		if (ttmp[i] == false) num.push_back(i);
	}
	bool flag = 0;
	for (int i = s.length()-1; i >=0; i--) {
		if (flag == false) {
			bool f = 0;
			for (int j = 0; j < num.size(); j++) {
				if (tmp[i] == num[j]) {
					f = true;
					ans.push_back(num[j]);
					break;
				}
				else if (tmp[i] < num[j]) {
					f = true;
					Refresh();
					ans.push_back(num[j]);
					break;
				}
			}
			if (f == false) {
				if (i != 0) {
					Refresh();
					ans.push_back(num[0]);
					flag = true;
				}
				else {
					ans.push_back(num[0]);
					Refresh();
					if (num[0] == 0) ans.push_back(num[1]);
					else ans.push_back(num[0]);
				}
			}



		}
		else {
			bool f = 0;
				for (int j = 0; j < num.size(); j++) {
					if (tmp[i] < num[j]) {
						Refresh();
						flag = false;
						f = true;
						ans.push_back(num[j]);
						break;
					}
				}
				
				if (f == false) {
					if (i != 0) {
						ans.push_back(num[0]);
					}
					else {
						ans.push_back(num[0]);
						if (num[0] == 0) ans.push_back(num[1]);
						else ans.push_back(num[0]);
					}
				}
		}
	}

	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i];
	}

		 
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;


int main(void)
{
    IOS
    //const int KMAX = 3000;
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<INT64> a(x), b(y), c(z);
    REP(x) cin >> a[i];
    REP(y) cin >> b[i];
    REP(z) cin >> c[i];

    vector<INT64> v;
    FOR(i,0,x) {
        FOR(j,0,y) {
            v.emplace_back(a[i]+b[j]);
        }
    }
    sort(RALL(v));
    int mk = min(k,x*y);
    vector<INT64> v2;
    REP(mk) {
        cerr << v[i] << endl;
        v2.emplace_back(v[i]);
    }
    v.clear();
    FOR(i,0,mk) {
        FOR(j,0,z) {
            v.emplace_back(v2[i]+c[j]);
        }
    }
    sort(RALL(v));
    
    REP(k) cout << v[i] << endl;



    return 0;
}


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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

ll solve(int, int M, vector<ii>& xs)
{
    sort(xs.begin(), xs.end(), greater<ii>());

    priority_queue<ll> pq;
    ll ans = 0;

    // t - o qual falta para o dia M
    for (int t = 0; t <= M; ++t)
    {
        while (not xs.empty() and xs.back().first <= t)
        {
            pq.push(xs.back().second);
            xs.pop_back();
        }

        if (not pq.empty())
        {
            ans += pq.top();
            pq.pop();
        }
    }
    
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ii> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, M, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2168
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
       s: chars
    }
    let mut s = s;
    loop {
        if s.is_empty() {
            break;
        }
        s.pop();
        s.pop();
        let len = s.len();
        let s1 = &s[0..len/2];
        let s2 = &s[len/2..len];
        if s1 == s2 {
            break;
        }
    }
    println!("{}", s.len());
}


Measured memory_bytes: 4352
#include <stdio.h>

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

    if(d==0){
        if(n<100){printf("%d\n",n);}
        if(n==100){printf("101\n");}
    } else if(d==1){
        if(n<100){printf("%d\n",n*100);}
        if(n==100){printf("10100\n");}
    } else if(d==2){
        if(n<100){printf("%d\n",n*10000);}
        if(n==100){printf("1010000\n");}
    }

    return 0;
}

Measured memory_bytes: 128
n = int(input())
x = input().split()
for i in range(n):
    x[i] = int(x[i])
xs = sorted(x)
ml = xs[n//2-1]
mr = xs[n//2]

for i in range(n):
    if x[i] <= ml:
        print(mr)
    elif x[i] >= mr:
        print(ml)

Measured memory_bytes: 21636
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Arrays;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        HashMap<String, String> dict = new HashMap<String, String>();

        String line;
        while ((line = br.readLine()) != null) {
            String[] input = line.split(" ");
            if (dict.containsKey(input[0])) {
                dict.put(input[0], dict.get(input[0]) + " " + input[1]);
            } else {
                dict.put(input[0], input[1]);
            }
        }

        int length = dict.keySet().size();
        String[] keyset = new String[length];
        int index = 0;
        for (String s : dict.keySet()) {
            keyset[index++] = s;
        }

        Arrays.sort(keyset);

        for (int i = 0; i < length; i++) {
            System.out.println(keyset[i]);
            String[] pages = dict.get(keyset[i]).split(" ");
            int[] a = new int[pages.length];
            for (int j = 0; j < pages.length; j++) {
                a[j] = Integer.parseInt(pages[j]);
            }
            Arrays.sort(a);
            boolean isFirst = true;
            for (int j = 0; j < pages.length; j++) {
                if (isFirst) {
                    System.out.print(a[j]);
                    isFirst = false;
                } else {
                    System.out.print(" " + a[j]);
                }
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 24284
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
const int INF = 1e9;
int n, a, b, c, l[8], _l[3];
int calc(int bamboo, int i) {
	if (i >= 3) {
		return abs(a - _l[0]) + abs(b - _l[1]) + abs(c - _l[2]) - 30;
	}
	int res = INF;
	if (_l[i] > 0) {
		res = min(res, calc(bamboo, i + 1));
	}
	for (int j = 0; j < n; j++) {
		if (bamboo & (1 << j)) continue;
		_l[i] += l[j];
		res = min(res, calc(bamboo | (1 << j), i) + 10);
		_l[i] -= l[j];
	}
	return res;
}
int main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);
	for (int i = 0; i < n; i++) scanf("%d", &l[i]);
	memset(_l, 0, sizeof(_l));
	int ans = calc(0, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
   public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int a;
    	String op;
    	int b;
    	
    	for(;;){
    		a = scan.nextInt();
        	op = scan.next();
    		b = scan.nextInt();
		if(op.equals("+")){
		   System.out.println(a+b);
		}else if(op.equals("-")){
			   System.out.println(a-b);
		}else if(op.equals("*")){
			   System.out.println(a*b);
		}else if(op.equals("/")){
			   System.out.println(a/b);
		}
		else{
		  break;
		}
    	}
   }
}

Measured memory_bytes: 26388