akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
T meguru_search(T ok, T ng, function<bool(T)> check){
    while(max(ok, ng) - min(ok, ng) > T(1)){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

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

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    auto check = [&](int mid){
        vector<int> ipos;
        vector<bool> used(n, false);
        rrep(i, n){
            if((int)ipos.size() >= mid){
                break;
            }
            if(s[i] == 'I'){
                ipos.emplace_back(i);
                used[i] = true;
            }
        }

        if((int)ipos.size() < mid){
            return false;
        }

        vector<int> opos;
        rrep(i, n){
            if((int)opos.size() >= mid){
                break;
            }
            if(s[i] == 'O' && i < ipos[opos.size()]){
                opos.emplace_back(i);
            }
        }

        if((int)opos.size() < mid){
            return false;
        }

        int cnt = 0;
        rrep(i, n){
            if(cnt >= mid){
                return true;
            }
            if(used[i] || s[i] == 'O'){
                continue;
            }
            if(i < opos[cnt]){
                ++cnt;
            }
        }

        return cnt >= mid;
    };

    int ans = meguru_search<int>(0, n, check);
    cout << ans << endl;

    cout << flush;

    return 0;
}


Measured memory_bytes: 9016
#include <bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define LD long double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define loop(i,a,b) for(int i=a;i<=b;++i)
#define pool(i,a,b) for(int i=a;i>=b;--i)
#define int long long
using namespace std; const int N = 200000 + 5, N2 = 50000 + 5, LOG = 9 + 1, INF = 1e9;

pair<int,int> a[N];

signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	loop(i,1,n) cin>>a[i].S>>a[i].F;
	sort(a+1,a+n+1);
	LL cur=0;
	loop(i,1,n){
		cur += a[i].S;
		if(cur > a[i].F){ cout<<"No\n"; return 0; }
	}
	cout<<"Yes\n";
}


Measured memory_bytes: 3328
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val w = cin.nextLong()
    val h = cin.nextLong()
    val x = cin.nextLong()
    val y = cin.nextLong()

    val s = w*h/2.0

    var d = 0

    if (x*2 == w && y*2 == h) {
        d = 1
    }
    println(s.toString() + " " + d.toString())
}

    

Measured memory_bytes: 31264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int ans = Math.max(A + B, A * B);
			ans = Math.max(ans, A - B);
			out.println(ans);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}
}


Measured memory_bytes: 21328
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    d=25-int(input())
    println("Christmas",repeat(" Eve",d))
end
main()

Measured memory_bytes: 112000
$h={}
def f l,a,b
a==b ?0:$h[[a,b]]||=(a..b-1).map{|i|f(l,a,i)+f(l,i+1,b)+l[a][0]*l[i][1]*l[i+1][0]*l[b][1]}.min
end
p f (1..n=gets.to_i).map{gets.split.map &:to_i},0,n-1

Measured memory_bytes: 6296
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,p[20011];
int a[20011],b[20011];
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		a[x]+=i;
		b[x]+=i;
	}
	for(int i=1;i<=n;i++)a[i]+=a[i-1];
	for(int i=n;i>=1;i--)b[i]+=b[i+1];
	for(int i=1;i<=n;i++)puti(a[i]);puts("");
	for(int i=1;i<=n;i++)puti(b[i]);
	return 0;
}


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

int main(){
    int N, sum=0;
    int l[100000], r[100000];
    cin >> N;

    for (int i=0; i<N; i++){
        cin >> l[i] >> r[i];
        sum += (r[i]-l[i]+1);
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
import Data.Array.ST
import Data.Array.Unboxed
import Data.Array.IArray
import Control.Monad
import Control.Monad.ST
main = interact $ unlines.map (unwords.map show.(\x -> [lessPrimeSearch x,overPrimeSearch x]).read).lines

prime = sieve 999999

sieve :: Int -> UArray Int Bool
sieve n = runSTUArray $ do
    t <- newArray (0,n) True
    writeArray t 0 False
    writeArray t 1 False
    sequence_ [writeArray t i False | i <- [4,6..n]]
    let sqn = (floor.sqrt.fromIntegral) (n::Int)
    sequence_ (actions t sqn n)
    return t

actions :: STUArray s Int Bool -> Int -> Int -> [ST s ()]
actions t k m = [readArray t i >>= (flip when) (writeArray t j False) | i <- [3,5..k],j <- [i*i,i*(i+2)..m]]

lessPrimeSearch n = if prime ! (n-1) then n-1
                                     else lessPrimeSearch (n-1)

overPrimeSearch n = if prime ! (n+1) then n+1
                                     else overPrimeSearch (n+1)

Measured memory_bytes: 4932
#include<cstdio>
int main(){
	int a[26]={};
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		char c[11];
		scanf("%s",c);
		a[c[0]-65]++;
	}
	int p=0;
	int m=0;
	int h=0;
	while(m==0){
		p=0;
		for(int i=0;i<26;i++){
			p+=a[i];
		}
		h=p/k;
		m=1;
		for(int i=0;i<26;i++){
			if(a[i]>h){
				a[i]=h;
				m=0;
			}
		}
	}
	printf("%d\n",h);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var s = cin.ReadInt;
            bool flg = true;
            int ans=0;
            int[] a = new int[1000000];
            a[0] = s;
            for (int i = 1; i < 10000000 && flg; i++)
            {
                if (a[i-1] % 2 == 0) a[i] = a[i - 1] / 2;
                else a[i] = a[i - 1] * 3 + 1;
           
                for (int j = 0; j < i; j++)
                {
                    if (a[j] == a[i])
                    {
                        flg = false;
                        ans = i+1;
                    }
                }
               
            }
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	double a, b;
	cin >> a >> b;
	int cnt = 0;
	if (b == 1) {
		cout << 0 << '\n';
		return 0;
	}
	while (1) {
		b -= a;
		cnt++;
		if (b > 0) {
			b++;
		}
		else break;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int bubble(int a[],int n);
void printline(int a[], int n);

int main(){

	int i,n,a[N],change;

	scanf("%d",&n);

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

	change = bubble(a,n);

	printline(a,n);
	printf("%d\n",change);


}

int bubble(int a[], int n){

	int i,j,change=0,dum;
	for(i=n;i>0;i--){
		for(j=1;j<i;j++){
			if(a[j]<a[j-1]){
				dum=a[j];
				a[j]=a[j-1];
				a[j-1]=dum;
				change++;
			}
		}
	}

	return change;

}

void printline(int a[],int n){

	int i;
	for(i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);

}

Measured memory_bytes: 1768
fun main(arr:Array<String>) {
    val x = readLine()!!.toInt()
    val ans = getPrimeList().filter { it >= x }.min()!!
    println(ans)
}

fun getPrimeList():List<Int> {
    val arr = BooleanArray(200000)
    val list = mutableListOf<Int>()
    for(i in (2 until arr.size)) {
        if(arr[i]) {
            continue
        }
        list.add(i)
        for(j in (1 until  arr.size)) {
            if(i * j >= arr.size) {
                break
            }
            arr[i*j] = true
        }
    }
    return list
}

Measured memory_bytes: 33680
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e6+7;
#define mo 998244353
char s[MAXN];
int f[MAXN][3][3][2],n,ans;
inline bool check_all()
{
	for(int i=1;i<=n-1;i++)
		if(s[i]!=s[i+1]) return 0;
	return 1;
}
inline bool check_same()
{
	for(int i=1;i<=n-1;i++)
		if(s[i]==s[i+1]) return 0;
	return 1;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if(check_all()) {
		cout<<1;
		return 0;
	}
	if(n<=3){
		if(n==2) cout<<2;
		else if(s[1]!=s[2]&&s[2]!=s[3]&&s[1]!=s[3]) cout<<3;
		else if(s[1]==s[3]) cout<<7;
		else cout<<6;
		return 0;
	}
	int tot=0;
	for(int i=1;i<=n;i++)
		tot+=s[i]-'a';
	tot%=3;
	f[1][1][1][0]=f[1][2][2][0]=f[1][0][0][0]=1;
	for(int i=2;i<=n;i++)
		for(int j=0;j<=2;j++)
			for(int k=0;k<=2;k++)
				for(int p=0;p<=2;p++){
					int last=(j-k+3)%3;
					(f[i][j][k][1]+=f[i-1][last][p][1])%=mo;
					if(k==p) (f[i][j][k][1]+=f[i-1][last][p][0])%=mo;
					else (f[i][j][k][0]+=f[i-1][last][p][0])%=mo;
				}
	for(int i=0;i<=2;i++)
		(ans+=f[n][tot][i][1])%=mo;
	cout<<ans+check_same();
}

Measured memory_bytes: 16640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


bool isValid(vector<int> ans,vector<int> x){
	vector<int> res(x.size(),-1);
	vector<int> c(x.size(),0);
	rep(i,ans.size()){
		int num = ans[i];
		c[num]++;
		if(c[num]==num+1)res[num] = i;
	}
	
	rep(i,res.size())assert(res[i]!=-1);
	if(res==x)return true;
	else return false;
}

int main(){
	int n;
	cin>>n;
	vector<int> x(n);
	rep(i,n){
		int a;
		cin>>a;
		x[i] = a-1;
	}
	
	
	vector<int> ans(n*n,-1);
	rep(i,x.size()){
		ans[x[i]] = i;
	}
	
	vector<pii> vp;
	rep(i,x.size()){
		vp.pb(pii(x[i],i));
	}
	sort(all(vp));
	map<int,int> mp;
	rep(i,vp.size()){
		mp[i] = vp[i].second;
	}
	
	
	queue<int> que;
	for(int i=0;i<n;i++){
		rep(j,mp[i]){
			que.push(mp[i]);
//			cout<<"queued "<<mp[i]<<endl;
		}
	}
	for(int i=0;i<n;i++){
		rep(j,n-mp[i]-1){
			que.push(mp[i]);
//			cout<<"queued "<<mp[i]<<endl;
	}
	}
	
	
	assert(que.size()==n*n-n);
	rep(i,ans.size()){
		if(ans[i]==-1){
			ans[i] = que.front();
			que.pop();
		}
	}
	assert(que.size()==0);
	
//	rep(i,ans.size())cout<<ans[i]<<" ";cout<<endl;
	if(isValid(ans,x)){
		cout<<"Yes"<<endl;
		rep(i,ans.size()){
			if(i)cout<<" ";
			cout<<ans[i]+1;
		}
		cout<<endl;
	}
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3244
//#undef DEBUG
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
const char lf = '\n', splf[] = " \n";
#define all(x) begin(x), end(x)
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
#define TCC template<class C
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
#define ENI typename enable_if<
#define DTOR , Dbg&>::type operator<<
#define RIS return *this
TCC> static auto o(C *x)->decltype(os << *x, 0);
TCC> static char o(...);
TCC> ENI sizeof o<C>(0)!=1 DTOR(const C &x) {os<<x; RIS;}
TCC> Dbg &dump(C b, C e) {
    int ii = 0;
    for(C i = (os << "\n[", b); i!=e and ii<26; i++, ii++) *this << ", "+2*(i==b) << *i;
    RIS << ']';
}
TCC> ENI sizeof o<C>(0)==1 DTOR(const C &x) {
    return dump(all(x));
}
TCC, size_t X> ENI !is_same<C, const char>::value DTOR(C (&x)[X]) {
    return dump(all(x));
}
TCC, class D> Dbg &operator<<(const pair<C, D> &x) {RIS<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(ostream&)) { os << x; RIS; }
} dbg;
void err(istringstream *iss) { delete iss; }
TCC, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#ifdef DEBUG
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
int T = 1, Q, cn;
const int inf = 1000000007, mxn = 1000005;

int n,cnt[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> T;
    auto kase = [&]()->void {   // if T>1, inputAll + resetAll -> solution
        //cout << "Case " << cn << ":";
        cin>>n;
        int g=1;
        for(int i=0,x;i<n;++i)cin>>x,++cnt[x],g=i? __gcd(g,x): x;
        if(g>1){cout<<"not coprime\n"; return;}
        bool pairWise=1;
        for(int i=2;i<mxn-4;++i){
            int tot=0;
            for(int j=i;j<mxn-4;j+=i)tot+=cnt[j];
            if(tot>1){pairWise=0;break;}
        }
        cout<<(pairWise? "pairwise coprime\n": "setwise coprime\n");
    };
    while (cn++!=T) kase();
}


Measured memory_bytes: 7564
#include<iostream>
 
using namespace std;
 
int main(){
    int i, j;
 
    for(i=1;i<10;i++){
        for(j=1;j<10;j++){
            cout << i << "x" << j << "=" << i*j << endl;
        }
    }
 
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b;
    cin >> a >> b;

    if (a%2 == 0 || b%2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
    return 0;
}

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

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> hs(n);
	for (auto &&h : hs)
	{
		cin >> h;
	}

	int64_t ans = 0;
	for (auto &&h : hs)
	{
		if (k <= h)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int [] array = new int[3];
		array[0] = stdIn.nextInt();
		array[1] = stdIn.nextInt();
		array[2] = stdIn.nextInt(); 
		int cnt = 0;
		
		while(true) {
			
			Arrays.sort(array);
			
			if(array[0] == array[1] && array[1] == array[2]) {
				break;
			}
			
			if(array[0]<array[1]) {
				cnt++;
				array[0] += 2;
				continue;
			}
			if(array[0] == array[1]) {
				cnt++;
				array[0]++;
				array[1]++;
			}
		
		}
		System.out.println(cnt);
		
	}

}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S;
	string A = "CODEFESTIVAL2016";
	cin >> S;
	int ans = 0;
	for(int i = 0; i < 16; i++){
		if(S[i] != A[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
S = input()

listS = list(S)
ans = []
for i in range(len(S)):
    listS.pop(-1)
    if len(listS) % 2 == 0 and  (listS[0:int((len(listS))/2)]) == (listS[int((len(listS))/2):]):
        ans.append(len(listS))

    
    
print(max(ans))

Measured memory_bytes: 3064
use std::io::Read;
fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let s: Vec<char> = iter.next().unwrap().chars().collect();

    println!(
        "{}",
        if s[2] == s[3] && s[4] == s[5] {
            "Yes"
        } else {
            "No"
        }
    );
}


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

using namespace std;

//ABC079-Dの問題

void warshall_floyd(int n,vector<vector<int>> &d) {
	for (int k = 0; k < n; k++) {       // 経由する頂点
		for (int i = 0; i < n; i++) {    // 始点
			for (int j = 0; j < n; j++) {  // 終点
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {

	int h, w; //この問題専用
	cin >> h >> w;

	//10までの隣接行列を読み込む
	//この問題では有向きグラフG[始点][終点]
	vector<vector<int>> G(10, vector<int>(10));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> G[i][j];
		}
	}
	
	warshall_floyd(10, G);

	//こっからはこの問題専用。
	int summ = 0;
	int tmp;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tmp;
			if (tmp != -1) {
				summ += G[tmp][1];
			}
		}
	}

	cout << summ << endl;

	return 0;

}

Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


A,V=nm()
B,W=nm()
T=int(input())

d=abs(A-B)
move_s=(V-W)
if(move_s<=0):
    print("NO")
    sys.exit(0)
if(((d//move_s))<=(T-1) or ((d//move_s)==T and (d%move_s==0)) ):
    print("YES")
    sys.exit(0)
print("NO")


Measured memory_bytes: 10396
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	if (a > b) {
		swap(a, b);
	}

	int ans = 1;
	if (a == 1 && b == 2) {
		ans = 3;
	} else if (a == 1 && b == 3) {
		ans = 2;
	} else {
		ans = 1;
	}

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


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

int main() {
 int N;
  cin >>N;
  
  vector<double> vec(N);
  for(int i=0;i<N;i++){
    cin >>vec.at(i);
  }
  double A=0;
  
 for(int i=0;i<N;i++){
   A+=1/vec.at(i);
   
 }
  cout<<1/A<<endl;
}


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


int main(){
    int K, N;
    cin >> K >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    vector<int> dist(N);
    rep(i, N - 1){
        dist[i] = a[i + 1] - a[i];
    }
    dist[N - 1] = a[0] + (K - a[N - 1]);
    int maxi = 0;
    rep(i, N){
        maxi = max(maxi, dist[i]);
    }

    cout << K - maxi << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
int n,i,s;
  cin>>n;
  for(i=1;i<=50000;i++){
    s=i*1.08;
    if(s==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
  return 0;
}
  


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for(auto& i: a) cin >> i;

  sort(begin(a), end(a));

  auto ok = [&](auto x) {
    if(K <= a[x]) return true;
    vector<bool> dp(K);
    dp[0] = true;
    for(auto i = 0; i < N; ++i) if(i != x) if(a[i] < K) {
      for(auto j = K-1; a[i] <= j; --j) dp[j] = dp[j] | dp[j - a[i]];
    }
    for(auto i = 0; i < K; ++i) if(dp[i]) if(K <= i + a[x]) return true;
    return false;
  };

  int l=-1, h=N;
  while(l+1 < h) {
    auto m=(l+h)/2;
    if(ok(m)) h = m;
    else      l = m;
  }
  cout << h << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int>a(N);
  for(int i=0;i<N;i++)
    cin >> a.at(i);
  int ans=0;
  bool chen=false;
  for(int i=0;i<N;i++){
    if(a.at(i)==i+1&&!chen){
      ans++;
      chen=true;
    }else{
      chen=false;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3708
H,W=map(int,input().split())
a=[list(map(int,input().split())) for i in range(H)]
count=0
ans=[]
for i in range(W):
    if i%2==0:
        for j in range(H):
            if j!=H-1:
                if a[j][i]%2==1:
                    a[j][i]-=1
                    a[j+1][i]+=1
                    ans.append([j+1,i+1,j+2,i+1])
                    count+=1
            else:
                if a[j][i]%2==1and i!=W-1:
                    a[j][i]-=1
                    a[j][i+1]+=1
                    ans.append([j+1,i+1,j+1,i+2])
                    count+=1
    if i%2==1:
        for j in reversed(range(H)):
            if j!=0:
                if a[j][i]%2==1:
                    a[j][i]-=1
                    a[j-1][i]+=1
                    ans.append([j+1,i+1,j,i+1])
                    count+=1
            else:
                if a[j][i]%2==1and i!=W-1:
                    a[j][i]-=1
                    a[j][i+1]+=1
                    ans.append([j+1,i+1,j+1,i+2])
                    count+=1
print(count)
for i in range(len(ans)):
    print(*ans[i])

Measured memory_bytes: 30224
class Main{
    public static void main(String[] a){
		for(int i=0; i<9; i++) {
			int x = i+1;
			for(int j=0; j<9; j++) {
				int y = j+1;
				System.out.println( x + "x" + y + "=" + x*y);
			}
		}
    }
}

Measured memory_bytes: 24136
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if(l[i] == l[j]):
                continue
            if(l[k] == l[j]):
                continue
            if(l[i] == l[k]):
                continue
            if(l[i] + l[j] <= l[k]):
                continue
            if(l[i] + l[k] <= l[j]):
                continue
            if(l[k] + l[j] <= l[i]):
                continue
            count += 1
print(count)

Measured memory_bytes: 9216
import java.util.Scanner;

// (1) ????????????????????????
	// (1.1) n???????????????
	// (1.2) x???????????????
	// (1.3) n??¨x???0?????????????????????????????????????????????
	// (1.4) ?????????????????????????????\???????????°sum????????????0??§????????????
	// (1.5) i???1??????(n - 2)????????\?????????????????????
		// (1.5.1) j???i + 1??????(n - 1)????????\?????????????????????
			// (1.5.1.1) k???j + 1??????n????????\?????????????????????
				// (1.5.1.1.1) ?????????(i + j + k)???x????????°?????\?????????????????????
					// (1.5.1.1.1.1) sum?????°???1?¢???????
	// (1.6) ????????????????????°?????¨?????????
// (2) scan?????????????????????
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (true) {

			int n = scan.nextInt();
			int x = scan.nextInt();

			if (n == 0 && x == 0) {
				break;
			}

			int sum = 0;

		for (int i = 1; i <= (n - 2); i++){
			for (int j = (i + 1); j <= (n - 1); j++) {
				for (int k = (j + 1); k <= n; k++) {
					if ((i + j + k) == x) {
						sum++;
					}
				}
			}
		}
		System.out.println(sum);
		}
		scan.close();
	}
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;
const int maxn = 4e3+2;
int cnk[maxn][maxn];

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    FOR(i,0,maxn) {
        cnk[i][0] = 1;
        FOR(j,1,i+1) {
            cnk[i][j] = cnk[i-1][j-1] + cnk[i-1][j];
            cnk[i][j] %= mod;
        }
    }
    int n,k;
    while (cin >> n >> k) {
        FOR(i,1,k+1) {
            const int r = n-k-i+1;
            const int p = i+1;
            cout << 1LL * cnk[k-1][i-1] * cnk[p+r-1][r] % mod << endl;
        }
        /* cout << ans << endl; */
    }
    return 0;
}


Measured memory_bytes: 61312
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	HashMap<String, String> map=new HashMap<String, String>();
	String start, end;
	int ans;

	void run(){
		for(;;){
			n=sc.nextInt();
			//println("n:"+n);
			if(n==0){
				break;
			}
			map.clear();
			for(int i=0; i<n; i++){
				String s=sc.next();
				String t=sc.next();
				map.put(s, t);
			}
			start=sc.next();
			end=sc.next();
			ans=-1;
			dfs(start, 0);
			println(""+ans);
			//println("here");
		}
	}

	void dfs(String s, int r){
		// if(r==4)
		// println("r:"+r+" s:"+s);
		if(r>=ans&&r>=10){
			return;
		}else if(s.length()>end.length()){
			return;
		}else if(s.equals(end)){
			if(ans==-1||r<ans){
				ans=r;
			}
			return;
		}
		for(Entry<String, String> entry : map.entrySet()){
			if(s.contains(entry.getKey())){
				String t=s.replaceAll(entry.getKey(), entry.getValue());
				dfs(t, r+1);
			}
		}
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define popb pop_back()
#define lb lower_bound
#define mp make_pair
#define le length()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
typedef unordered_map<ll,ll> ull;
typedef unordered_map<ll,int> uli;
typedef unordered_map<int,int> uii;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0,lim-1);
  return uid(rang);
}
ll mpow(ll base, ll exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);
 
const int mod = 1000000009;
const int N = 3e5, M = N;
//=======================
 
vi g[N];
int a[N];
vector<ll> f(500069,1);
void compute_factorial(){
  for(int i =2;i<500068;i++){
    f[i] = (i*f[i-1])%mod;
  }
}

void rec(string a, vector<char> b,vector<bool> added,unordered_set<string>& m ,vector<string>& ans){
  //cout<<b.size()<<'\n';
  if(b.size() == a.length()){
    string ss;
    for(auto it:b)ss+=it;
    if(m.find(ss) == m.end())ans.pb(ss),m.insert(ss);
  }
  for(int i =0;i<a.le;i++){
    if(!added[i]){
      b.pb(a[i]);
      added[i]  = true;
      rec(a,b,added, m,ans);
      b.popb;
      added[i] = false;
    }
  }
}

ll gcd(ll a, ll b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
}



void solve(){
  int n;cin>>n;
  int i;
  vl a(n);fo(i,n)cin>>a[i];
  ll ans = 0;
  //stack<ll> st;
  //st.push(0);
  ll m = 0;
  for(auto it:a){
    if(it<m)ans+=m-it;
    m=max(it,m);
  }
  cout<<ans<<'\n';
  


 
 }
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
    #endif
          int t;
          t = 1;
          //cin>>t;
          int tt = t;
   while(t--)solve();
 
    return 0;
}
 


Measured memory_bytes: 15868
s = input()
t = input()

min_cnt = 1005
len_t = len(t)
length = len(s)
for i in range(length-len_t+1):
  cnt = 0
  for j in range(len_t):
    if t[j] != s[i+j]:
      cnt += 1
  min_cnt = min(cnt, min_cnt)
    
print(min_cnt)

Measured memory_bytes: 72852
import scala.io.StdIn.{readInt,readLine}

object Main {
  val a = Array(
    Array('.',',','!','?',' '),
    Array('a','b','c'),
    Array('d','e','f'),
    Array('g','h','i'),
    Array('j','k','l'),
    Array('m','n','o'),
    Array('p','q','r','s'),
    Array('t','u','v'),
    Array('w','x','y','z')
  )

  def main(args:Array[String]) = {
    val n = readInt
    val r = for(i<-1 to n) yield {
      val s = readLine.split("0")
      s.map { btns =>
        if(btns.length>0) {
          val btn = btns(0).asDigit
          val len = if(List(2,3,4,5,6,8).contains(btn)) 3
                    else if(List(7,9).contains(btn)) 4
                    else if(List(1).contains(btn)) 5
                    else 1
          a(btn-1)((btns.length-1) % len)
        } else ""
      }.mkString
    }
    println(r.mkString("\n"))
  }

}

Measured memory_bytes: 50528
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int K[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int num = sc.nextInt();
        System.out.println(K[num-1]);
    }
}


Measured memory_bytes: 21844
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
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; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll n, a, b, c;
string str;


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	cin >> str;

	ll ans = 0;
	ll cnt = 0;
	rep(i, str.size()){
		if(str[i] == 'R'){
			cnt++;
		}
		else{
			chmax(ans, cnt);
			cnt = 0;
		}
	}
	chmax(ans, cnt);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3592
a, b, c = map(int, input().split())

if a == b == c and a % 2 == 0:
    print(-1)
else:
    count = 0
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            break
        count += 1
        temp_a = b // 2 + c // 2
        temp_b = a // 2 + c // 2
        temp_c = a // 2 + b // 2
        a, b, c = temp_a, temp_b, temp_c
    print(count)
        

Measured memory_bytes: 3060
from collections import deque
from copy import deepcopy

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
r = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == '.':
      b = deepcopy(a)
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        for di in range(-1, 2):
          i1 = i + di
          if 0 <= i1 < h:
            for dj in range(di % 2 - 1, 2, 2):                
              j1 = j + dj
              if 0 <= j1 < w and b[i1][j1] == '.':
                b[i1][j1] = b[i][j] + 1
                q.append((i1, j1))
print(r)


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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n,x;cin>>n>>x;
	vec a(n);
	FOR(i,0,n) cin>>a[i];
	vec m(n,INF);
	ll out=INF,temp;
	FOR(i,0,n) {
		temp=i*x;
		FOR(j,0,n) {
			m[j]=min(m[j],a[(n+j-i)%n]);
			temp+=m[j];
		}
		out=min(out,temp);
	}
	cout<<out;
}

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

typedef long long ll;
typedef pair <int, int> ii;

const int Maxd = 100;

int n, t;
vector <ii> seq;
vector <int> zers;
ll dp[Maxd];

bool Less(const ii &fir, const ii &sec)
{
    return ll(sec.first) * (fir.second + 1) < ll(fir.first) * (sec.second + 1);
}

int main()
{
    scanf("%d %d", &n, &t);
    for (int i = 0; i < n; i++) {
        int a, b; scanf("%d %d", &a, &b);
        if (a == 0) zers.push_back(b);
        else seq.push_back(ii(a, b));
    }
    sort(seq.begin(), seq.end(), Less);
    fill(dp, dp + Maxd, t + 1);
    dp[0] = 0;
    for (int i = 0; i < seq.size(); i++) {
        for (int j = Maxd - 2; j >= 0; j--) if (dp[j] <= t) {
            ll cand = dp[j] + 1;
            cand += ll(seq[i].first) * cand + seq[i].second;
            dp[j + 1] = min(dp[j + 1], cand);
        }
    }
    sort(zers.begin(), zers.end());
    int res = 0;
    for (int i = 0; i < Maxd; i++) if (dp[i] <= t) {
        int cand = i;
        ll cur = dp[i];
        for (int j = 0; j < zers.size(); j++)
            if (cur + 1 + zers[j] <= t) {
                cur += 1 + zers[j];
                cand++;
            }
        res = max(res, cand);
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 5316
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

paths = [[] for i in range(N)]
longest_paths = [-1 for i in range(N)]

for i in range(M):
    x, y = map(int, input().split())
    paths[x-1].append(y-1)

def get_longest(node):
    if longest_paths[node] != -1:
        return longest_paths[node]
    if paths[node] == []:
        longest_paths[node] = 0
        return 0
    else:
        result = max([get_longest(nd) for nd in paths[node]]) + 1
        longest_paths[node] = result
        return result

print(max([get_longest(i) for i in range(N)]))

Measured memory_bytes: 115472
INF = 10 ** 10
n, m = gets.split.map(&:to_i)
keys = []
m.times do
  open_cost = gets.to_i
  open_boxes = gets.split.map(&:to_i).inject(0) { |res, num| res | 2 ** (num - 1) }
  keys << [open_cost, open_boxes]
end
dp = Array.new(2 ** n, INF)
dp[0] = 0
keys.each do |open_cost, open_boxes|
  dp.each_with_index do |cost, opened|
    next if cost == INF
    next_opened = (opened | open_boxes)
    dp[next_opened] = cost + open_cost if dp[next_opened] > cost + open_cost
  end
end
puts dp.last == INF ? - 1 : dp.last

Measured memory_bytes: 3836
#include <cstdio>
#include <cstdlib>

int main()
{
  int n;
  scanf("%d", &n);
  long long a[200001] = {0};
  for (int i = 1; i <= n; ++i)
  {
    scanf("%lld", a + i);
    a[i] += a[i - 1];
  }
  long long ans = 1e18;
  for (int i = 1; i < n; ++i)
  {
    long long x = a[i];
    long long y = a[n] - a[i];
    if (ans > std::abs(x - y)) ans = std::abs(x - y);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1664
num = gets.chomp.split(" ").map(&:to_i)

n = num[0]
m = num[1]
x = num[2]

fee = gets.chomp.split(" ").map(&:to_i)
cost0 = 0
costN = 0
fee.each do |i|
    if x < i
        costN += 1
    elsif
        i < x
        cost0 += 1
    end
end

if cost0 < costN
    puts cost0
else
    puts costN
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
// #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

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

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


int main() {
  int n;cin>>n;
  int cnt=0;
  int ans=0;
  for(int i=1;i<=n;i++){
    cnt=0;
    for(int j=1;j<=i;j++){
      if (i%j==0 && i%2==1){
        cnt+=1;
      }
    }
    if (cnt==8){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}


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

using ll = long long;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;

    if (n == 1) {
        cout << "? 1\n";
        string x;
        cin >> x;
        if (x == "Blue") {
            cout << "! BR\n";
        } else {
            cout << "! RB\n";
        }
        return;
    }

    vector<char> ans(n * 2 + 1, '*');

    cout << "? ";
    REP1(i, n) cout << i << (i == n ? EOL : ' ');
    string r;
    cin >> r;

    string q;
    function<bool(int)> ask = [&](int m) {
        cout << "? ";
        FOR(i, m, m + n) cout << i << (i == m + n - 1 ? EOL : ' ');
        cin >> q;
        return r == q;
    };

    int left = 1;
    int right = n + 1;
    while (abs(right - left) > 1) {
        int m = (left + right) / 2;
        if (ask(m)) {
            left = m;
        } else {
            right = m;
        }
    }

    cout << "? ";
    FOR(i, left, left + n) cout << i << (i == left + n - 1 ? EOL : ' ');
    cin >> q;

    if (q == "Red") {
        ans[left] = 'R';
    } else {
        ans[left] = 'B';
    }

    FOR(i, 1, left) {
        cout << "? " << i << " ";
        FOR(j, left + 1, left + n) cout << j << (j == left + n - 1 ? EOL : ' ');
        cin >> q;
        if (q == "Red") {
            ans[i] = 'R';
        } else {
            ans[i] = 'B';
        }
    }

    FOR(i, left + n, n * 2 + 1) {
        cout << "? " << i << " ";
        FOR(j, left + 1, left + n) cout << j << (j == left + n - 1 ? EOL : ' ');
        cin >> q;
        if (q == "Red") {
            ans[i] = 'R';
        } else {
            ans[i] = 'B';
        }
    }

    FOR(i, left + 1, left + n) {
        cout << "? " << i << " ";
        int c = 1;
        FOR(j, 1, left) {
            c++;
            cout << j << (c == n ? EOL : ' ');
        }
        FOR(j, left + n + 1, n * 2 + 1) {
            c++;
            cout << j << (c == n ? EOL : ' ');
        }
        cin >> q;
        if (q == "Red") {
            ans[i] = 'R';
        } else {
            ans[i] = 'B';
        }
    }
    cout << "! ";
    REP1(i, n * 2) cout << ans[i];
    // cout << EOL << flush;
    cout << EOL;
}


Measured memory_bytes: 724
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int lmax(long int a, long int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int lmin(long int a, long int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
long int power(int a,int b){
  long int count=1;
  for(int i=0;i<b;i++){
    count *= 2;
  }
  return count;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  char s[11];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++){
    if(s[i]=='/') s[i]='0';
  }
  if(atoi(s) <= 2019004030)printf("Heisei");
  else printf("TBD");
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define debug(x) cout << #x << ": " << x << endl
#define ALL(x) (x).begin(),(x).end()
 
const int INF = 1e9;
const ll LINF = 1e16;
 
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
 
 
    while(1){
        int m, nmin, nmax;
        cin >> m >> nmin >> nmax;
        if (m == 0 && nmin == 0 && nmax == 0)break;
        vector<int> P(m);
        for (int i = 0; i < m; i++) cin >> P[i];
        int MAX = -1;
        int ret = 0;
        for (int i = nmin; i <= nmax; i++) {
            if (P[i - 1] - P[i] >= MAX) {
                MAX = P[i - 1] - P[i];
                ret = i;
            }
        }
        cout << ret << endl;
    }
     
  return 0;
}

Measured memory_bytes: 3024