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

using namespace std;

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

  if((A+B)==(C+D)) cout<<"Balanced";
  else if((A+B)<(C+D))cout<<"Right";
  else cout<<"Left";

  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
const long long inf = 1e17;
const int mod = 1000000007;

const int MAX_ROW = 61; // to be set appropriately
const int MAX_COL = 200; // to be set appropriately
struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};
int GaussJordan(BitMatrix &A, bool is_extended = false) {
	int rank = 0;
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = rank; row < A.H; ++row) {
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		swap(A[pivot], A[rank]);
		for (int row = 0; row < A.H; ++row) {
			if (row != rank && A[row][col]) A[row] ^= A[rank];
		}
		++rank;
	}
	return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
	int m = A.H, n = A.W;
	BitMatrix M(m, n + 1);
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
		M[i][n] = b[i];
	}
	int rank = GaussJordan(M, true);

	// check if it has no solution
	for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

	// answer
	res.assign(n, 0);
	for (int i = 0; i < rank; ++i) res[i] = M[i][n];
	return rank;
}
int solve(vector<int>V,int k) {
	BitMatrix A(61, (int)V.size());
	vector<int>b(61), res;
	rep(d, 61) {
		rep(i, V.size()) {
			if (V[i] & (1ll << d))A[d][i] = 1;
		}
		if (k&(1ll << d))b[d] = 1;
	}
	int rank = linear_equation(A, b, res);
	return rank;
}
signed main() {
	int t; cin >> t;
	rep(T, t) {
		int n; cin >> n;
		vector<int>a(n);
		rep(i, n)cin >> a[i];
		string s; cin >> s;
		vector<int>v;
		int flg = 0;
		if (s[n - 1] == '1')flg++;
		else {
			for (int i = n - 1; i >= 0; i--) {
				if (s[i] == '0')v.push_back(a[i]);
				else {
					if (solve(v, a[i]) == -1)flg = 1;
				}
			}
		}
		cout << flg << endl;
	}
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
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> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  bool aaa = true;
  rep(i,a+b+1){
    if(i==a&&s[i]!='-') aaa = false;
    if(i==a) continue;
    if(s[i]<'0' || s[i]>'9') aaa = false;
  }
  if(aaa) pri("Yes");
  else pri("No");
  return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "01B0" ].parse.expand.solve == "00" );
	assert( [ "0BB1" ].parse.expand.solve == "1" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	auto ans = "";
	foreach( c; s )
	{
		if( c == 'B' )
		{
			if( 0 < ans.length ) ans.length--;
		}
		else
		{
			ans ~= c;
		}
	}
	return ans;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,x,n) for(int i=(x);i<(n);i++)
#define sortn(a) sort((a).begin(),(a).end())
#define sortr(a) sort((a).begin(),(a).end(),greater<int>())
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
    
    int n,m;
    // int c;
    ll ans=0;
    cin >> n >> m;
    multiset<double> a;
    double tmp;
    rep(i,n){
        cin >> tmp;
        a.insert(tmp);
    }

    // rep(i,m){
    //     a.back() /= 2; 
    //     if(a.back() < 1){
    //         a.pop_back();
    //         if(a.size() == 0)break;
    //     }else{
    //         c = 0;
    //         while(a[a.size()-1-c] < a[a.size()-2-c]){
    //             swap(a[a.size()-1-c],a[a.size()-2-c]);
    //             c++;
    //         }
    //     }
    // }

    rep(i,m){
        auto itr = a.end();
        itr--;
        tmp = *itr/2;
        a.erase(itr);
        if(tmp < 1){
            if(a.size() == 0)break;
        }else{
            a.insert(tmp);
        }
    }

    for(auto i=a.begin();i!=a.end();i++){
        ans += (int)(*i);
    }

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



Measured memory_bytes: 4992
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	1000005

int		N, pre[n], Q[n];

char	A[n], B[n];

int		main(int argc, char* argv[]){
	
		N= IN();
		scanf("%s%s", A+1, B+1);
		
		int flag= 0;
		For(i, 1, N)	if	(A[i] != B[i])	flag= 1;
		if	(! flag)	return	puts("0"), 0;
		
		for (int i= N, j= N; i; i--)	{
			j= min(j, i);
			for (; j && A[j] != B[i]; j--);
			if	(! j)	return	puts("-1"), 0;
			pre[i]= j;
		}
		
		int	Ans= 1, l= 1, r= 0;
		Rep(i, N, 1)	if	(pre[i] > pre[i-1])	{
			for (; l <= r && Q[l] - (r-l) > i; l++);
			if	(pre[i] < i)	Q[++ r]= pre[i], Ans= max(Ans, r-l+2);
		}
		printf("%d\n", Ans);
		
		return	0;
}

Measured memory_bytes: 10112
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int a, b, c;

int main() {
	cin >> a >> b >> c;
	if (a == b && a == c) {
		cout << "No" << endl;
	}
	else if (a == b || a == c || b == c) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,s=0;
    cin>>n;
    vector<ll> d(n);
    for(ll i=0;i<n;i++) cin>>d[i];
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            s+=d[i]*d[j];
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
H,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]

INF = float('inf')
dp = [INF] * (H+1)
dp[H] = 0
for a,b in AB:
    for h in range(H,0,-1):
        i = max(0,h-a)
        dp[i] = min(dp[i], dp[h]+b)
print(dp[0])

Measured memory_bytes: 52828
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i,s,e) for(int i = (s);i <= (e);i++)

typedef long long i64;
int n;
vector<i64> a;
i64 sum[100010];

int main()
{
    cin >> n;
    a.resize(n + 1,0);
    rep(i,1,n) cin >> a[i];
    sort(a.begin() + 1,a.end());
    rep(i,1,n) sum[i] = sum[i - 1] + a[i];
    int result = 0;
    rep(i,1,n - 1)
    {
        if(sum[i] * 2 < a[i + 1])
        {
            result = 0;
        }
        else
        {
            result++;
        }
    }
    result++;
    cout<< result << endl;


}

Measured memory_bytes: 1792
#include<iostream>//itp16a
using namespace std;
int main(void)
{
	int n,i,a[1001];
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=n-1;i>=0;i--){
		cout<<a[i];
		if(i==0) break;
		cout<<" ";
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

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

typedef long long ll;

int main()
{

    int n;
    cin >> n;

    if (n == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<int> ans;
    while (n != 0)
    {
        ans.push_back(abs(n % -2));
        n = (n - abs(n % -2)) / -2;
    }

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

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, a, b, c;
	cin>>n;
	vector<int> days(3, 0);
	vector<vector<int> > vec(n, days);
	vector<vector<int> > ans(n, days);
	for(int i = 0; i < n; ++i){
		cin>>a>>b>>c;
		vec[i][0]=a;
		vec[i][1]=b;
		vec[i][2]=c;
	}
	for(int i = 0; i < 3; ++i){
		ans[0][i] = vec[0][i];
	}
	for(int i = 1; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			if(j == 0){
				ans[i][j] = max(ans[i - 1][j + 1] + vec[i][j], ans[i - 1][j + 2] + vec[i][j]);
			}
			if(j == 1){
				ans[i][j] = max(ans[i - 1][j - 1] + vec[i][j], ans[i - 1][j + 1] + vec[i][j]);

			}
			if(j == 2){
				ans[i][j] = max(ans[i - 1][j - 1] + vec[i][j], ans[i - 1][j - 2] + vec[i][j]);
			}
		}
	}
	int res = 0;
	for(int i = 0; i < 3; ++i){
		res = max(res, ans[n - 1][i]);
	}
	cout<<res<<endl;	
	return 0;
}


Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split();
            int k = int.Parse(data[0]);
            int s = int.Parse(data[1]);
            //long cnt = 0;

            if (k == s)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            
            //Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
  int n;

  for(;cin>>n,n;)
    {
      long long int sk[31];
      memset(sk,0,sizeof(sk));
      for(int i=0;i<n;i++)
	{
	  int f;
	  cin>>f;
	  //cout<<"input :"<<i<<endl;
	  for(int j=0;j<f;j++)
	    {
	      int tmp;
	      cin>>tmp;
	      sk[tmp]=sk[tmp]|(long long int)1<<i;

	    }	  
	}
      long long int have[n];
      for(int i=0;i<n;i++)
	have[i]=(long long int)1<<i;
      
      int ans=-1;
      for(int i=1;i<31;i++)
	{
	  if(sk[i]==0)
	    continue;
	  long long int tmp=0;
	  for(int j=0;j<n;j++)
	    {
	      if((sk[i]&((long long int)1<<j))!=0)
		tmp|=have[j];
	    }
	  if(tmp==(((long long int)1<<n)-1))
	    {
	      ans=i;
	      break;
	    }
	  for(int j=0;j<n;j++)
	    {
	      if((sk[i]&((long long int)1<<j))!=0)
		have[j]=tmp;
	    }
	  
	  //   cout<<"sk["<<i<<"] = "<<sk[i]<<endl;


	}

      cout<<ans<<endl;

    }
}

Measured memory_bytes: 1160
def d_two_sequences():
    # 参考: https://atcoder.jp/contests/abc091/submissions/6048882
    import numpy as np
    N = int(input())
    A = np.array(input().split(), dtype=np.int32)
    B = np.array(input().split(), dtype=np.int32)

    bit = 1 << 28  # 入力は 28bit 未満の非負整数
    ans = 0
    while bit:
        # bit + 1 番目以上のビットは考慮する必要がないため、mask で除いてしまう
        mask = 2 * bit - 1
        A &= mask
        B &= mask
        A.sort()
        B.sort()

        # numpy.searchsorted() は bisect.bisect_left() と同等
        x1, x2, x3 = (np.searchsorted(B, v - A).sum() for v in [bit, 2 * bit, 3 * bit])
        # [0, x1 - 1], [x2, x3 - 1] 番目の要素は、bit 番目のビットが 0 である
        # [x1, x2 - 1], [x3, N - 1] 番目の要素は、bit 番目のビットが 1 である
        zero_cnt = x1 + (x3 - x2)
        if (N - zero_cnt) % 2:
            ans += bit  # 解の bit 番目のビットは 1 である
        bit >>= 1  # 下位ビットへ
    return ans

print(d_two_sequences())

Measured memory_bytes: 35912
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define roop(i,n) for(int i=0;i<n;i++)
int n,a[300001],sum;
main(){
	cin>>n;
	roop(i,n*3)cin>>a[i];
	sort(a,a+3*n);
	for(int i=n;i<3*n;i+=2)sum+=a[i];
	cout<<sum<<endl;
}

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

int n, a[55], MAX=INT_MIN, pos1, pos2, MIN=INT_MAX;
vector< pair<int, int> > ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        if(a[i] > MAX) {
            MAX = a[i];
            pos1 = i;
        }
        if(a[i] < MIN) {
            MIN = a[i];
            pos2 = i;
        }
    }
    if(abs(MAX)>=abs(MIN)) {
        for(int i=1; i<=n; i++) {
            a[i] += MAX;
            ans.push_back(make_pair(pos1, i));
        }
        for(int i=2; i<=n; i++) {
            ans.push_back(make_pair(i-1, i));
        }
        cout << ans.size() << endl;
        for(int i=0; i<ans.size(); i++)
            cout << ans[i].first << ' ' << ans[i].second << '\n';
    }
    else {
        for(int i=1; i<=n; i++) {
            a[i] += MIN;
            ans.push_back(make_pair(pos2, i));
        }
        for(int i=n; i>=2; i--) {
            ans.push_back(make_pair(i, i-1));
        }
        cout << ans.size() << endl;
        for(int i=0; i<ans.size(); i++)
            cout << ans[i].first << ' ' << ans[i].second << '\n';
    }

    return 0;
}


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

int N;
ll A;

ll gcd(ll x, ll y){
    if(y==0) return x;
    if(x < y) swap(x, y);
    return gcd(y, x%y);
}

int main(){
    scanf("%d", &N);
    ll g;
    scanf("%lld", &A); g=A;
    for(int i =1; i<N; i++){
        scanf("%lld", &A);
        g = gcd(g, A);
    }
    int cnt = 0;
    while(g%2 == 0){
        cnt++;
        g/=2;
    }
    printf("%d", cnt);
    return 0;
}



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

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A' && s[i+1] == 'C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
///FUCKOUT
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<ll, ll>;

#define int ll

const int N = 2e5+5, M = 1e6 + 5, LG = 17, MOD = 1e6 + 3;
const int BLOCK = 55;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;
using ull = unsigned long long;
ll t[N<<2];
ll tA[N<<2], tB[N<<2];
void upd(int node, int s, int e, int idx, ll v){
  t[node] = min(t[node], v);
  tA[node] = min(tA[node], v + idx);
  tB[node] = min(tB[node], v - idx);
  if(s==e)return;
  int md = (s+e)>>1;
  if(idx<=md)
    upd(node<<1,s,md,idx,v);
  else
    upd(node<<1|1,md+1,e,idx,v);
}
ll qry(int node, int s, int e, int idx){
  if(e < idx)return idx + tB[node];
  if(s > idx)return tA[node] - idx;
  if(s==e)return t[node];
  int md = (s+e)>>1;
  return min(qry(node<<1,s,md,idx),qry(node<<1|1,md+1,e,idx));
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE
  memset(t,63, sizeof t);
  memset(tA,63, sizeof tA);
  memset(tB,63, sizeof tB);
  int n, q, A, B;
  cin >> n >> q >> A >> B;

  upd(1, 1, n, A, 0);

  int prv = B;
  ll ans = 0;
  while(q--){
    int x;
    cin >> x;
    ll val = qry(1, 1, n, x) + ans;
    ans += abs(x - prv);
    upd(1, 1, n, prv, val - ans);
    prv = x;
  }

  cout << ans+t[1]<<'\n';
  return 0;
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n, w, d;
int p[110], s[110];
typedef tuple<int, int, int, int> tup;

int main(void){
	while(1){
		cin >> n >> w >> d;
		if(n == 0 && w == 0 && d == 0) break;
		rep(i, n){
			cin >> p[i] >> s[i];
		}
		priority_queue<tup, vector<tup>, greater<tup>> q[2]; //??\???????????? ??¢??? ????????????
		q[0].push(make_tuple(-1, w * d, w, d));
		rep(i, n){
			// printf("i %d\n", i);
			rep(j, p[i] - 1){
				int num, men, x, y; 
				tie(num, men, x, y) = q[i % 2].top(); q[i % 2].pop();
				// printf("%d %d %d %d\n", num, men, x, y);
				q[(i + 1) % 2].push(make_tuple(num, men, x, y));
			}

			//?????????
			int num, men, x, y; 
			tie(num, men, x, y) = q[i % 2].top(); q[i % 2].pop();
			// printf("%d %d %d %d\n", num, men, x, y);

			int len = s[i];
			len %= (x * 2 + y * 2);
			rep(j, 2){
				if(len - x < 0){
					int x1 = x - len, x2 = len;
					// printf("x %d %d\n", x1, x2);
					q[(i + 1) % 2].push(make_tuple(i, x1 * y, x1, y));
					q[(i + 1) % 2].push(make_tuple(i, x2 * y, x2, y));
					// printf("c %d %d %d %d\n", i, x1 * y, x1, y);
					// printf("c %d %d %d %d\n", i, x2 * y, x2, y);
					break;
				}
				len -= x;
				if(len - y < 0){
					int y1 = y - len, y2 = len;
					// printf("y %d %d\n", y1, y2);
					q[(i + 1) % 2].push(make_tuple(i, x * y1, x, y1));
					q[(i + 1) % 2].push(make_tuple(i, x * y2, x, y2));
					// printf("c %d %d %d %d\n", i, x * y1, x, y1);
					// printf("c %d %d %d %d\n", i, x * y1, x, y2);
					break;
				}
				len -= y;
			}

			while(!q[i % 2].empty()){
				int num, s, x, y; 
				tie(num, s, x, y) = q[i % 2].top(); q[i % 2].pop();
				// printf("%d %d %d %d\n", num, men, x, y);
				q[(i + 1) % 2].push(make_tuple(num, s, x, y));
			}
		}
		vector<int> ans;
		rep(i, 2){
			while(!q[i].empty()){
				int num, men, x, y; 
				tie(num, men, x, y) = q[i].top(); q[i].pop();
				ans.pb(men);
			}
		}
		sort(all(ans));
		rep(i, ans.size()){
			if(i == ans.size() - 1) printf("%d\n", ans[i]);
			else printf("%d ", ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <time.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#define ll long long
#define int64 long long
#define ull unsigned long long
#define pb push_back
#define INF 0x3f3f3f3f
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define pi 3.141592653589793238462

using namespace std;

const int maxn = 1e5 + 5;
const int maxm = 2e6 + 5;
const int mod = 1e9 + 7;
const int seed = 10007;
const double eps = 1e-5;
int n, k;
int a[maxn];


int main() {
    scanf("%d%d", &n, &k);
    int ma = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        ma = max(ma, a[i]);
        if (!flag && a[i] == k) {
            flag = 1;
            printf("POSSIBLE\n");
        }
    }
    if (!flag) {
        if (k > ma) {
            printf("IMPOSSIBLE");
        } else {
            sort(a, a + n);
            for (int i = 0; i < n && a[i] < k && !flag; i++) {
                int tar = k - a[i];
                int l = 0, r = n - 1, mid;
                while (l <= r) {
                    mid = (l + r) >> 1;
                    if (a[mid] < tar) {
                        l = mid + 1;
                    } else if (a[mid] > tar) {
                        r = mid - 1;
                    } else {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    printf("POSSIBLE\n");
                }
            }
            if (!flag) printf("IMPOSSIBLE\n");
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,arr[100003];
int dp[100003];
int f(int x)
{
    if(x==0) return 0;
    if(x<0) return 1987654321;
    if(dp[x]!=-1) return dp[x];
    int ret=1987654321;
    if(x>=1) ret=min(ret,f(x-1)+abs(arr[x]-arr[x-1]));
    if(x>=2) ret=min(ret,f(x-2)+abs(arr[x]-arr[x-2]));
    return dp[x] = ret;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&arr[i]);
    printf("%d",f(n-1));
}


Measured memory_bytes: 4096
package main

import (
	"fmt"
)

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func main() {
	var x, n int
	fmt.Scanf("%d %d", &x, &n)
	if (n == 0) {
		fmt.Printf("%d", x)
		return
	}

	p := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &p[i])
	}

	var left, right int
	for i := x; i >= 0; i-- {
		if (!contains(p, i)) {
			left = i
			break
		}
	}
	for i := x + 1; i <= 101; i++ {
		if (!contains(p, i)) {
			right = i
			break
		}
	}

	if (x - left <= right - x) {
		fmt.Printf("%d", left)
	} else {
		fmt.Printf("%d", right)
	}
}


Measured memory_bytes: 1824
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

long long int N, K, cnt = 1, P = 0;
vector<int> V;
vector<int> position;

void F(int A){
if(position[A - 1] != 0){P = A - 1;return;}
position[A - 1] = cnt;
cnt++;
F(V[A - 1]);
}

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

V.resize(N);position.resize(N);

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

F(V[0]);

if(K <= *max_element(ALL(position))){

for(int i = 0; i < N; i++){
if(K == position[i])cout << i + 1;

}

}


else{

int period = *max_element(ALL(position)) - position[P] + 1;
int X = K%period;

for(int i = 0; i < N; i++){
if(position[i] < position[P])continue;
if(X == position[i]%period)cout << i + 1;
}

}
}

Measured memory_bytes: 4816
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    while (1) {
    
    int h,w;
    scanf("%d %d",&h,&w);
    
        if(h==0 && w==0){
            break;
        }
        
    int i,j;
    for (i=0; i<h; i++) {
        for(j=0;j<w;j++){
            if(i > 0 && i<h-1 && j >0 && j < w-1){
                printf(".");
            }
            else{
                printf("#");
            }
        }
        printf("\n");
    }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include "stdio.h"
#include "math.h"
#include "stdlib.h"

void swap(int *a, int *b);
int main(){
  int i, p, s, u, N, L, sum = 0, a[200];

  scanf("%d %d", &N, &L);
  for(i = 0; i < N; i++){
    a[i] = L + i;
    sum = sum + a[i];
    a[i] = abs(a[i]);
  }
  for(p = 0; p < N; p++){
    for(s = 0; s < N - p; s++){
      if(a[s] < a[s + 1]){
        swap(&a[s], &a[s + 1]);
      }
    }
  }

  if((N + L) > 0){
    printf("%d", sum - a[N - 1]);
    return 0;
  }
  else{
    printf("%d", sum + a[N - 1]);
    return 0;
  }
}

void swap(int *a, int *b){
  int c;
  c = *a;
  *b = c;
  *a = *b;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[200020][13];
ll poww10[200010];

int main(){
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  int n=s.size();
  poww10[0]=1;
  for(int i=1;i<=n;i++){
    poww10[i]=poww10[i-1]*10;
    poww10[i]%=13;
  }
  if(s[0]=='?'){
    rep(i,10)dp[0][i]++;
  }else{
    dp[0][s[0]-'0']++;
  }
  for(int i=1;i<n;i++){
    if(s[i]!='?'){
      for(int j=0;j<13;j++){
        dp[i][(j+poww10[i]*(s[i]-'0'))%13]+=dp[i-1][j];
      }
    }else{
      rep(j,10){
        rep(k,13){
          dp[i][(poww10[i]*j+k)%13]+=dp[i-1][k];
          dp[i][(poww10[i]*j+k)%13]%=mod;
        }
      }
    }
  }
  /*
  rep(i,n){
    rep(j,13){
      cout << "(" << i << ',' << j << "):" << dp[i][j] << endl;
    }
    cout << endl;
  }
  */
  cout << dp[n-1][5] << endl;
return 0;}

Measured memory_bytes: 12032
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y]
s.sort()
for i, j in zip(enumerate(s), r):
    if i[1] > j:
        break
    else:
        s[i[0]] = j
print(sum(s))

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

const int N = 3e3+5;
int n;
double sm , p[N] , prod[N] , dp[N][N];

main(){
  cin >> n;
  prod[0] = 1;
  for(int i = 1 ; i <= n ; i++){cin >> p[i]; prod[i] = prod[i-1]*(1-p[i]);}

  for(int i = 1 ; i <= n ; i++){
    dp[i][1] = dp[i-1][1]*(1-p[i]) + prod[i-1]*p[i];
    for(int j = 2 ; j <= i ; j++) dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
  }

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

  for(int j = (n+1)/2 ; j <= n ; j++) sm += dp[n][j];
  printf("%.10lf\n",sm);
}

Measured memory_bytes: 69120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n), w(n);
    for(int i =0; i<n; i++) cin>>v[i];
    for(int i =0; i<n; i++) cin>>w[i];

    vector<int> a(n);
    int cnt = 0;
    for(int i =0; i<n; i++)
        a[i] = i+1;
    do
    {
        cnt++;
        if(v == a)
            break;
    } while (next_permutation(a.begin(), a.end()));
    
    for(int i =0; i<n; i++)
        a[i] = i+1;
    do
    {
        cnt--;
        if(w == a)
            break;
    } while (next_permutation(a.begin(), a.end()));

    cout<<abs(cnt)<<"\n";
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b,c,x;

  scanf("%d" "%d" "%d",&a,&b,&c);
  if(a>b){
    x=a;
    a=b;
    b=x;
  }

  if(b>c){
    x=b;
    b=c;
    c=x;
  }

  if(a>b){
    x=a;
    a=b;
    b=x;
  }

  printf("%d %d %d\n",a,b,c);

  return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    string s; cin >> s;
    set<char> st;
    rep(i,s.size()) {
        st.insert(s[i]);
    }
    if (st.size() == s.size()) cout << "yes" << endl;
    else cout << "no" << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,x = map(int, input().split())
    l = list(map(int, input().split()))
    res = 1
    c = 0
    for i in range(n):
        c += l[i]
        if c <= x:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import math
N = int(input())  # N個の駅
station = []  # 駅の情報
for _ in range(N-1):
    c, s, f = map(int, input().split())  # 次の駅までc秒, 開始からs秒後に最初の電車, 以後f秒置きに発車する
    station.append((c, s, f))

ans = []  # 最後に0を追加することを忘れないように
time = 0
for i in range(N-1):
    # 今i駅にいる状態
    time = station[i][1]  # 出発するまでにかかる時間
    time += station[i][0]  # 駅i+1にいくまでにかかる時間
    for j in range(i+1, N-1):  # 開始時は駅i+1にいる
        # まだ最初の電車が出ていないなら待つ
        if station[j][1] >= time:  # timeは今経過している時間
            time = station[j][1]  # 最初の時間まで待って出発
            time += station[j][0]  # 次の駅へc秒かかる
            continue  # 次の駅へ
        else:  # もし最初の電車はすでに出発していたなら（time > s）
        # 次の電車まで待つ必要がある
            tmp = time
            tmp -= station[j][1]
            teisuubai = math.ceil(tmp/station[j][2])
            time = station[j][1] + teisuubai * station[j][2]
            time += station[j][0]
    ans.append(time)

ans.append(0)

for a in ans:
    print(a)


Measured memory_bytes: 3188
import collections

h, w, m = map(int, input().split())

my_s = set()

h_ls = []
w_ls = []

for _ in range(m):
    h_e, w_e = map(int, input().split())
    my_s.add((h_e, w_e))
    h_ls.append(h_e)
    w_ls.append(w_e)

h_c = collections.Counter(h_ls)
w_c = collections.Counter(w_ls)

h_ls = h_c.most_common()
w_ls = w_c.most_common()

h_ptr = 0
w_ptr = 0
ret = 0

h_idx, h_cnt = h_ls[0]
w_idx, w_cnt = w_ls[0]
tmp = h_cnt + w_cnt
flag = False
if (h_idx, w_idx) not in my_s:
    ret = tmp
else:
    for i, item in enumerate(h_ls):
        _, h_cnt_tmp = item
        if h_cnt_tmp != h_cnt:
            h_ptr = i - 1
            break
        if i == len(h_ls) - 1:
            h_ptr = len(h_ls) - 1

    for i, item in enumerate(w_ls):
        _, w_cnt_tmp = item
        if w_cnt_tmp != w_cnt:
            w_ptr = i - 1
            break
        if i == len(w_ls) - 1:
            w_ptr = len(w_ls) - 1

    for i in range(h_ptr+1):
        for j in range(w_ptr+1):
            h_idx, _ = h_ls[i]
            w_idx, _ = w_ls[j]
            if (h_idx, w_idx) not in my_s:
                ret = tmp
                flag = True
                break
        if flag:
            break
    if not flag:
        ret = tmp - 1

print(ret)


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if(v <= w) {
    cout << "NO" << endl;
    return 0;
  }
  if((ll)ceil((double)abs(a-b)/(v-w)) <= t) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<pint> xy(N);
    for (int i = 0; i < N; ++i) cin >> xy[i].first >> xy[i].second;
    double res = 0;
    vector<int>v(N);
    for (int i = 0; i < N; ++i) v[i] = i;

    do {
        for (int i = 0; i < N-1; ++i) {
            double dx = xy[v[i]].first - xy[v[i+1]].first;
            double dy = xy[v[i]].second - xy[v[i+1]].second;
            res += pow(dx*dx + dy*dy, 0.5);
        }
    } while(next_permutation(v.begin(), v.end()));
    int count = 1;
    for (int i = 1; i <= N; ++i) count *= i;
    cout << setprecision(15) << fixed;
    cout << res / count << endl;
    return 0;
}

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}

int main(){
    iostream_init();
    LL n, m, d;
    cin >> n >> m >> d;
    // n - d
    double x = (d != 0 ? 2 * (n - d) : n);
    double y = 1.0 * x / n / n;
    double answer = 1.0 * y * (m - 1);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
  list($n, $m) = explode(" ", trim(fgets(STDIN)));

  $p = new SplMaxHeap();
  $a = explode(" ", trim(fgets(STDIN)));
  for ($i=0; $i<$n; $i++) {
    $p->insert($a[$i]);
  }

  for ($i=0; $i<$m; $i++) {
    $a = $p->extract();
//    echo $a.PHP_EOL;
    $p->insert(intdiv($a,2));
  }

  $ans = 0;
  foreach ($p as $money) {
    $ans+=$money;
  }

  echo $ans;
  

Measured memory_bytes: 16884
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(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;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}
ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
void Solve() {

	int n, m;
	cin >> n >> m;
	int a[15];
	int ar[] = { 0,2,5,5,4,5,6,3,7,6 };
	set<int> pt;
	for (size_t i = 0; i < m; i++)
	{
		cin >> a[i];
		pt.insert(ar[a[i]]);
	}
	sort(a, a + m);
	int pa[10];
	int pai = 0;
	for (set<int>::iterator i = pt.begin(); i != pt.end(); i++)
	{
		pa[pai] = *i;
		pai++;
	}

	string dp[10010];
	fill(dp, dp + n + 1, " ");
	dp[0] = "";

	for (int i = 0; i < pai; i++)
	{
		int v = pa[i];

		string vm = "";
		for (size_t j = 0; j < m; j++)
		{
			if (v == ar[a[j]]) {
 				vm = a[j] + '0';
			}
		}
		for (int j = 1; j <= n; j++)
		{
			if (v <= j && dp[j - v] != " ") {

				string tm = dp[j - v] + vm;
				sort(tm.begin(), tm.end());
				reverse(tm.begin(), tm.end());

				if (dp[j].size() < tm.size()) {

					dp[j] = tm;
				}
				else if (dp[j].size() == 1 + dp[j - v].size()) {
					dp[j] = max(dp[j], tm);

				}
			}
		}
	}
	cout << dp[n] << endl;
}


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



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

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

using namespace std;

int main(){
	int n,m; cin>>n>>m;
	int a=1,b=n;
	rep(i,m){
		int l,r; cin>>l>>r;
		a=max(a,l);
		b=min(b,r);
	}
	cout<<max(b-a+1,0)<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

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

    string ans;

    while (n > 0){
        ll rem = (n % 26);
        if (rem == 0){
            ans.pb ('z');
            n /= 26;
            n--;
        } else{
            ans.pb ((char)('a' + rem - 1));
            n /= 26;
        }
    }
    reverse (all (ans));
    cout << ans << endl;
}

int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



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

int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    long long A[X], B[Y], C[Z];
    rep(i, X){
        cin >> A[i];
    }
    rep(i, Y){
        cin >> B[i];
    }
    rep(i, Z){
        cin >> C[i];
    }
    sort(A, A+X, greater<long long>());
    sort(B, B+Y, greater<long long>());
    sort(C, C+Z, greater<long long>());
    priority_queue<vector <long long> > que;
    vector<long long> vec(4);

    vec[0] = A[0] + B[0] + C[0];
    vec[1] = 0;
    vec[2] = 0;
    vec[3] = 0;
    map<vector<long long>, bool> mp;
    que.push(vec);
    rep(i, K){
        cout << que.top()[0] << endl;
        int a = que.top()[1];
        int b = que.top()[2];
        int c = que.top()[3];
        vector<long long> que0 = que.top();
        que.pop();
        vector<long long> vec1(4), vec2(4), vec3(4);
        if(a + 1 < X){
            vec1[0] = A[a+1] + B[b] + C[c];
            vec1[1] = a + 1;
            vec1[2] = b;
            vec1[3] = c;
            if(!mp.count(vec1)){
                mp[vec1] = false;
                que.push(vec1);
            }
        }
        if(b + 1 < Y){
            vec2[0] = A[a] + B[b+1] + C[c];
            vec2[1] = a;
            vec2[2] = b + 1;
            vec2[3] = c;
            if(!mp.count(vec2)){
                mp[vec2] = false;
                que.push(vec2);
            }
        }
        if(c + 1 < Z){
            vec3[0] = A[a] + B[b] + C[c+1];
            vec3[1] = a;
            vec3[2] = b;
            vec3[3] = c + 1;
            if(!mp.count(vec3)){
                mp[vec3] = false;
                que.push(vec3);
            }
        }
    }
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
	#define author          "Sihare0riginals"
	#define ss       		string 
	#define lli      		long long int
	#define ld       		long double
	#define f        		first
	#define s        		second
	#define all(v)   		v.begin(),v.end()
	#define I(a,i)			memset(a,i,sizeof(a));
	#define pb       		push_back
	#define mp       		make_pair
	#define L(i,start,end)  for(lli i=start;i<=end;i++)
	#define R(i,start,end)  for(lli i=start;i>=end;i--)
	#define ip(n) 			cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=1e9+7;
void Bl0ck_M0mb0();
ss ans="";
void solve(lli n)
{
	if(n==0)
		return ;
	lli x=26,k=1;
	while(n>x)
	{
		k++;
		lli p1=pow(26,k);
		x=(p1+x);
	}
	lli val=pow(26,k-1);
	x-=(val*26);
	L(i,1,26)
	{
		if((x+(i)*val)>=n)
		{
			ans+='a'+i-1;
			n-=(i*val);
			return solve(n);
			break;
		}
	}
	return ;
}
signed main()
{
	Bl0ck_M0mb0();
	lli t=1;
	//cin>>t;
	while(t--){
		lli n;
		cin>>n;
		ans="";
		solve(n);
		cout<<ans<<endl;
	}
	return 0;
}


















void Bl0ck_M0mb0(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("ip.txt","r",stdin);
	freopen("op.txt","w",stdout);
	#endif
}
/*
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for(lli i=s1;i<=e1;i++){cout<<i<<"th :";for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}
#define M map<lli,lli> \n #define sz(s) s.size()-1
#define P pair<lli,lli> 
#define V vector<lli>
lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
 	lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); } */

Measured memory_bytes: 4040
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *next;
  struct Node *prev;
};

struct Node *data;

struct Node* search(int);
void In();
void Print();
void deletN(struct Node*);
void deleF();
void deleL();
void det(int);
void insert(int);


int main(){
  int i,n,key;
  int size=0,p=0,d=0;
  char rei[20];

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

   for(i=0;i<n;i++){
     scanf("%s%d",rei,&key);
    if(rei[0]=='i'){
      insert(key);
      p++;
      size++;
    }
    else if(rei[0]=='d'){
      if(strlen(rei)>6){
        if(rei[6]=='F')  deleF();
        else if(rei[6]=='L')  deleL();
      }else{
        det(key);
        d++;
      }
      size++;
    }
   }
  Print();
  return 0;
}



void Print(){
struct Node *a;
int x=0;

 a=data->next;
 while(1){
   if(a==data) {
     break;
   }
   if(x++>0){
     printf(" ");
   }
   printf("%d",a->key);
   a=a->next;
 }
 printf("\n");
}


void In(){
  data=(struct Node *)malloc(sizeof(struct Node));
  data->next=data;
  data->prev=data;
}

void deletN(struct Node *t){
  if(t==data)  return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

struct Node* search(int key){
  struct Node *a;
  a=data->next;
  while(a!=data&&a->key!=key){
    a=a->next;
  }
  return a;
}

void deleF(){
  deletN(data->next);
}

void deleL(){
  deletN(data->prev);
}

void det(int key){
  deletN(search(key));
}

void insert(int key){
  struct Node *a;
  a=(struct Node *)malloc(sizeof(struct Node));
  a->key=key;
  a->next=data->next;
  data->next->prev=a;
  data->next=a;
  a->prev=data;
}


Measured memory_bytes: 32952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
int main() {
    long long int n,i,j,count,ans;
    ans=0;
    cin>>n;
    vector<long long int> h(n+1);
    h[0]=0;
    for(i=1;i<=n;i++){
        cin>>h[i];
    }
    for(i=1;i<n;i++){
        if(h[i-1]<h[i]){
            count=0;
            for(j=i;j<n;j++){
               if(h[j]>=h[j+1]){
                   count++;
                   ans=max(ans,count);
               }else{
                   break;
               }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
	int n, i, p, max=-1000000, min=1000000;
	long long int sum=0;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &p);
		if(p<min){
			min = p;
		}
		if(p>max){
			max=p;
		}
		sum+=p;
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 600