akhauriyash/Code-Regression huggingface dataset:
def ascan; gets.split.map(&:to_i);end
def bye(s);puts s;exit;end

n = gets.to_i
aa = ascan
bb = ascan

asum = aa.reduce(:+)
bsum = bb.reduce(:+)

k = bsum-asum

if k < 0
    bye "No"
end
if k == 0
    bye "Yes" if aa == bb
    bye "No"
end

ak = k
bk = k
n.times do |i|
    if aa[i] > bb[i]
        bk -= aa[i] - bb[i]
    elsif aa[i] < bb[i]
        if (bb[i]-aa[i]).even?
            ak -= (bb[i]-aa[i])/2
        else
            ak -= (bb[i]-aa[i]+1)/2
            bk -= 1
        end
    end
end

bye "No" if ak < 0 || bk < 0
bye "Yes"


Measured memory_bytes: 4988
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define	       MEM(a,b)         memset(a,(b),sizeof(a))
#define	       CLR(p)           memset(p,0,sizeof(p))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
#define	       ff               first
#define	       sc              second
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
#define MAX 1000005
#define precision(a) fixed << setprecision(a)

#define mod 1000000007

ll ar[MAX],ans[MAX];

int main()
{
 //O_O ;
   ll n,k;
   cin>>n>>k;
   for(ll i=1;i<=n;i++)
    cin>>ar[i];
    //for(ll i=n;i>=n-k;i--)
   // ans[i]=ar[i];
   ans[n]=0;
  // ans[n-1]=abs(ar[n-1]-ar[n]);

   for(ll i=n-1;i>=1;i--)
   {
       ll mn=INT_MAX;
       for(ll j=i+1;j<=min(i+k,n);j++)

       mn=min((abs(ar[i]-ar[j])+ans[j]),mn);
       ans[i]=mn;
      // cout<<<<ss<<i<<nn;
       // cout<<(abs(ar[i]-ar[i+2])+ans[i+2])<<ss<<i<<nn;
       }
  // for(ll i=1;i<=n;i++)
   // cout<<ans[i]<<ss;cout<<nn;
   cout<<ans[1]<<nn;

    return 0;
}


Measured memory_bytes: 5160
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int K = sc.nextInt();
        int[] l = new int[N+1];
        int a = N+1;
        boolean f = false;
        for(int i = 1;i <= N;i++){
            l[i] = sc.nextInt();
            if(l[i] >= 0 && !f){
                a = i;
                f = true;
            }
        }
        int mi = 0;
        int Mi = 0;
        if(a-1 >= K){
            Mi = a-1;
            mi = a-K;
        }else{
            mi = 1;
            Mi = K;
        }
        long ans = Long.MAX_VALUE;
        while(mi <= a && Mi <= N){
            if(Mi < a){
                ans = Math.min(ans, -l[mi]);
            }else if(mi == a){
                ans = Math.min(ans, l[Mi]);
            }else{
                long c = Math.min(l[Mi], -l[mi]);
                long cc = Math.max(l[Mi], -l[mi]);
                ans = Math.min(ans, c*2+cc);
            }
            mi++;
            Mi++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50328
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong()-1
  var m = n

  var d = 26L
  var i = 1
  while (d <= m) {
    m -= d
    d *= 26
    i += 1
  }

  var ans = ""

  while (i > 0) {
    ans = s"${('a' + m % 26).toChar}$ans"
    m /= 26
    i -= 1
  }

  println(ans)
}



Measured memory_bytes: 55304
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

string toString(const int d) {
		ostringstream ost;
		ost << d;
		return ost.str();
}

string ope(string s) {
	int cnt = 1;
	char c = s[0];
	string res;

	for (int i = 1; i < (int)s.size(); i++) {
		if (s[i] != c) {
			res += toString(cnt) + c;
			cnt = 1;
			c = s[i];
		}else {
			cnt++;
		}
	}

	res += toString(cnt) + c;

	return res;
}

int main(void) {
	int n;
	string s;

	while (cin >> n, n) {
		cin >> s;

		for (int i = 0; i < n; i++) {
			s = ope(s);
		}

		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 1356
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

LL dp[101010][3];
int main() {
    int n;
    cin >> n;
    vector<vector<int> > v(n, vector<int>(3, 0));
    rep(i, n) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    rep(i, 3) {
        dp[0][i] = v[0][i];
    }

    for (int i = 1; i < n; i++) {
        dp[i][0] = v[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = v[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = v[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    LL res = 0;
    rep(i, 3) {
        res = max(res, dp[n - 1][i]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8064
/*
  AUTHOR:SOURABH
  CREATED:26:10:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32
#define PI 3.14159265

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll a,b,x;
    cin>>a>>b;
    if(a<=9 && b<=9)
        cout<<a*b;
    else
        cout<<-1;
    return 0;
}
















Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 22:52:39 2018

@author: Yuki
"""

N = int(input())
S = {}
S['M'] = []
S['A'] = []
S['R'] = []
S['C'] = []
S['H'] = []

for i in range(N):
    tmp = input()
    if tmp[0] == 'M':
        S['M'].append(tmp)
    elif tmp[0] == 'A':
        S['A'].append(tmp)
    elif tmp[0] == 'R':
        S['R'].append(tmp)
    elif tmp[0] == 'C':
        S['C'].append(tmp)
    elif tmp[0] == 'H':
        S['H'].append(tmp)

def get_factorial(number = 2):
    if number == 1:
        return 1
    else:
        return number * get_factorial(number-1)
def get_initial_from_2sin(string):
    res = []
    if string[0] == '1':
        res.append('M')
    if string[1] == '1':
        res.append('A')
    if string[2] == '1':
        res.append('R')
    if string[3] == '1':
        res.append('C')
    if string[4] == '1':
        res.append('H')
    return res

        
res_cnt = 0
for i in range(2**5):
    tmp = bin(i)[2:].zfill(5)
    result = get_initial_from_2sin(tmp)
    if len(result) == 3:
        res_cnt += len(S[result[0]]) * len(S[result[1]]) * len(S[result[2]])
print(res_cnt)



Measured memory_bytes: 10100
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

//ダブり→一緒に抜き出せば確実に1,2枚は減らせる
//→ダブっているものを選んで減らすという行為を繰り返せばいい

int main(){
    ll ans=0,n;
    cin >>n;
    map<ll,int> a;
    vector<ll> al;
    for(int i=0;i<n;i++){
        ll b;
        cin >>b;
        map<ll,int>::iterator itr = a.find(b);
        if (itr==a.end()){
            a.insert(make_pair(b,al.size()+1));
            al.push_back(1);
        }else{
            dbg cout <<b<<" "<<a.at(b)<<" "<<al.size()<<endl;
            al[a.at(b)-1]++;
        }
    }
    dbg cout <<"ok"<<endl;
    ll twocnt=0;
    for(int i=0;i<al.size();i++){
        if(al[i]>=3)al[i]=(al[i]%2==0) ? 2 : 1;
        if(al[i]==2)twocnt++;
        ans+=al[i];
    }
    ans-=(twocnt%2==0)?twocnt:twocnt+1;



    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
signed main()
{
    speed
    int n;cin>>n;
    vector<int> a(n+1),b(n);
    for(int i=0;i<=n;++i){cin>>a[i];}
    for(int i=0;i<n;++i){cin>>b[i];}
    int ans=0;
    for(int i=0;i<n;++i)
    {
        if(a[i]>b[i]){ans+=b[i];}
        else
        {
            ans+=a[i];
            int diff=b[i]-a[i];
            if(a[i+1]>=diff)
            {
                a[i+1]-=diff;
                ans+=diff;
            }
            else
            {
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<ans<<"\n";
}

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

int main(){
  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>

using namespace std;

#define forsn(i,s,n) for(int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)

typedef long long int tint;

tint n, m, v, p; 
tint a[100010];
tint psums[100010];

bool doable(int i) {
	if (i < p) return true;
	
	tint pth = a[p - 1];
	if (a[i] + m < pth) {
		return false;
	}
	
	tint toBeAddedInRange = max(0LL, v - (p - 1) - (n - i));
	tint toBeAddedToRange = toBeAddedInRange * m;
	tint sumInRange = psums[i] - psums[p - 1];
	
	tint amountInRange = i - (p - 1);
	assert(amountInRange >= 0);
	
	return sumInRange + toBeAddedToRange <= (a[i] + m) * amountInRange;
}

int main() {
	cin >> n >> m >> v >> p;
	
	forn(i, n) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	
	psums[0] = 0;
	partial_sum(a, a + n, psums + 1);
	
	int res = 0;
	forn(i,n) res += doable(i);
	
	cout << res << endl;
}


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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


const int MAX = 10000000;
bool is_prime[MAX + 1];

int quad(int n)
{
	for (int i = n; ; --i)
	{
		if (is_prime[i] && is_prime[i-2] && is_prime[i-6] && is_prime[i-8])
			return i;
	}
}
int main()
{
	fill(is_prime, is_prime + MAX + 1, true);
	for (int i = 2, until = (int)sqrt((double)MAX)+1; i <= until; ++i)
	{
		if (is_prime[i])
		{
			for (int j = 2*i; j <= MAX; j += i)
				is_prime[j] = false;
		}
	}

	int q = -1;

	int n;
	while (scanf("%d", &n), n)
		printf("%d\n", quad(n));

	return 0;
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
int main()
{
	ll n,W;
	cin>>n>>W;
	ll v[n],w[n];
	for(ll i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][W+1];
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=W;j++)
		{
			dp[i][j]=0;
		}
	}
	ll ans=0;
	for(ll i=n-1;i>=0;i--)
	{
		for(ll j=0;j<=W;j++)
		{
			if(w[i]<=j)
			{
				dp[i][j]+=v[i];
				if(i!=n-1)
				{
					dp[i][j]+=dp[i+1][j-w[i]];
				}
			}
			dp[i][j]=max(dp[i][j],dp[i+1][j]);
			ans=max(ans,dp[i][j]);
		}
	}
//	for(ll i=0;i<n;i++)
//	{
//		for(ll j=0;j<=W;j++)
//		{
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<ans;
}


Measured memory_bytes: 79104
#include<stdio.h>
int main(){
int n,a,b;
scanf("%d %d %d",&n,&a,&b);
int ans=0;

for(int i=0;i<=n;i++){
	int num=i;
	int sum=0;
	while(num){
		sum=sum+num%10;
		num=num/10;
    }
	if((a<=sum)*(sum<=b)){
		ans=ans+i;
	}
}

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

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

using namespace std;

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll conv(int a) {
  return a / 2 * (a -1);
}

int main(int argc, char const *argv[]) {
  int k,s; cin >> k >> s;
  ll ans = 0;

  REP(i,k + 1) {
    REP(j,k + 1) {
      if (s - i - j >= 0 && s - j - i <= k) 
        ans++;
    }
  }

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

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;

string s1,s2;
int ok;

int main()
{
	cin>>s1>>s2;
	if(s1.length()!=s2.length())
	{
		if(s1.length()>s2.length()) cout<<"GREATER"<<endl;
		else cout<<"LESS";
		ok=1;
 	}
 	else
 	{
		for(int i=0;i<s1.length();++i)
		{
			if(s1[i]>s2[i])
			{
				ok=1;
				cout<<"GREATER"<<endl;
				break;
			}
			if(s2[i]>s1[i]) 
			{
				ok=1;
				cout<<"LESS"<<endl;
				break;
			}
		}
	}
	if(!ok) cout<<"EQUAL"<<endl;
	return 0;
}

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

using namespace std;

const int N = 100;
const int W = (int) 1e5;
int64_t maxv[N + 1][W + 1];
int w[N + 1];
int v[N + 1];
int n;
int cap;

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

    cin >> n >> cap;

    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }

    for (int w = 0; w <= cap; w++) {
        maxv[0][w] = 0;
    }

    for (int i = 1; i <= n; i++) {
        for (int c = 0; c <= cap; c++) {
            if (w[i] > c) {
                maxv[i][c] = maxv[i - 1][c];
            }
            else {
                maxv[i][c] = max(maxv[i - 1][c],
                                  maxv[i - 1][c - w[i]] + v[i]);
            }
        }
    }

    cout << maxv[n][cap] << '\n';

    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<ll> que;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        que.push(a);
    }
    for (int i = 0; i < m; i++) {
        ll cur = que.top();
        que.pop();
        que.push(cur / 2);
    }
    ll sum = 0;
    while (!que.empty()) {
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1400
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define print(x) (cout << x << endl)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // const int M = 1e9 + 7;

  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }

  vector<vector<ll>> dp(n + 1, vector<ll> (W + 1)); // plus 1
  
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= W; j++) {
      if (w[i - 1] > j) dp[i][j] = dp[i - 1][j];
      else dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
    }
  }
  cout << dp[n][W] << endl;
}
    // cout << "Case #" << C++ << ": " << cur_max << endl;  



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

int gcd(int a, int b){
	if(b > 0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

int lcm(int a, int b){
	return ((a / gcd(a, b)) * b);
}

int main(){
	int a, b;

	while( cin >> a >> b ){
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
}

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

int main(){
	long long X , A , B;
	cin >> X >> A >> B;
	if(A > B) swap(A , B);
	if((B - A) % 2 == 0) cout << (B - A) / 2;
	else cout << (B - A) / 2 + 1 + min(A - 1 , X - B);
	return 0;
}

Measured memory_bytes: 256
import math
S = input()
K = int(input())
# 5000兆
chou = 5*(10**15)

for c in S:
  # 倍率
  mag = int(c)
  if mag == 1:
    if K == 1:
      print(1)
      quit()
    else:
      K -= 1
      continue
  if chou >= math.log(K,mag):
    print(c)
    quit()
  # これはたぶんいらない
  else:
    K -= mag**chou
    print(K)

Measured memory_bytes: 3060
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	
	long long n;
	
	
	while(cin>>n,n!=-1){
		bool f=false;
		string s="";
		for(int k=9;k>=0;k--){
			int i=int(pow(4,k));
			int count=0;
			for(int j=0;j<3;j++){
				if(n-i>=0){
					n=n-i;
					count++;
				}
				else
					break;
			}
			if(count!=0||f)
			s=s+to_string(count);
			if(s!="")
				f=true;
			
		}
		if(!f)
			s="0";
		cout<<s<<endl;
	}
			

}

Measured memory_bytes: 3276
#include <iostream>
#include <cstdio>
using namespace std;
int gcd(int a, int b)
{ 
    int r;  
    while((r = a % b) != 0)  
    {      
        a = b;    
        b = r;
        }  
return b
;}
int main(void)
{  
    int a, b, tmp;  
    if (a < b){     
        tmp = b;
        b = a;
        a = tmp;   
        } 
        while(cin >> a >> b) {  
            int lcm = b / gcd(a,b)*a;   
            cout << gcd(a,b) << " " << lcm << endl;    
            
        }   
return 0;
    
}



Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define NFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); --i)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e9
#define mod 1000000007
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
// #define lli int
typedef long long int lli;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef complex <long double> complex_t;
const long double PI = acos((long double)-1.0);

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

ll a[200010];
ll d[200010];
ll s[200010];
int n, m;

ll add(int index1, ll val) {
    for(;index1 < 2*m; index1 += index1&(-index1)) {
        d[index1] += val;
    }
}

ll query(int index1) {
    ll answer1 = 0;
    for(; index1 > 0; index1 -= index1 & (-index1)) {
        answer1 += d[index1];
    }
    return answer1;
}

int main() {
    cin >> n >> m;
    ll t = 0;
    FOR(i, 1, n) {
        ll temp; cin >> temp; a[i] = temp;
    }
    ll a1 = a[1];
    FOR(i, 2, n) {
        ll a2 = a[i];
        if (a2-a1 > 1) {
            add(a1+2, 1);
            add(a2+1, -a2+a1);
            add(a2+2, a2-a1-1);
        }
        if (a1-a2 > 0 && a2+m-a1>1) {
            add(a1+2, 1);
            add(a2+m+1, -a2-m+a1);
            add(a2+m+2, a2+m-a1-1);
        }
        if (a2 > a1) t+=(a2-a1);
        if (a1 > a2) t+=(a2+m-a1);
        a1 = a2;
    }
    FOR(i, 1, 2*m-1) {
        s[i] = s[i-1] + query(i);
    }
    ll r = 0;
    FOR(i, 1, m) {
        r = max(r, s[i] + s[m+i]);
    }
    cout << t - r << endl;
return 0;}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;



int main() {
    int x,y,z,a,b,c;
    cin >> x >> y >> z;
    c=y;
    b=x;
    a=z;
    cout << a <<" " << b << " " << c << endl;
    
}



Measured memory_bytes: 3592
//abc147_d.cpp
//Sun Dec  8 21:42:24 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll MOD = 1000000007;
	ll n;
	cin >> n;

	ll a[n];
	ll keta[60];
	fill(keta,keta+60,0);
	for (int i=0;i<n;i++){
		cin >> a[i];
		for (int j=0;j<60;j++){
			if (a[i]>>j&1){
				keta[j]++;
			}
		}
	}


	ll ans = 0;
	for (int i=0;i<60;i++){
		ll temp = keta[i]*(n-keta[i])%MOD;
		ll another = pow(2,i);
		another = another%MOD;
		temp = temp*another%MOD;
		ans = (ans + temp) % MOD;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define FILE_IN freopen("in", "r", stdin);
#define FILE_OUT freopen("out", "w", stdout);
#define fr(i,a,b) for(int i =a;i<b;i++)

bool debug = 0;
#define prin(a) if(debug) cout << #a << " = " << (a) << endl
#define par(a) if(debug) printf("%d/%d\n", (a.first), (a.second))
#define separa() if(debug) cout << endl

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll, ll>

const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
#define N 100100

vector<pii> edges;

void add(int a, pii b) {
	edges.pb({a,b.fi});
	if(b.se != -1) edges.pb({a, b.se});
}

int main () {

	int n;
	
	vector<pii> a;
	cin >> n;

	int maxi = n%2 ? n-1 : n;
	for(int i=1;i<=maxi/2;i++) {
		a.pb({i, maxi-i+1});
		
	}

	if(n % 2) a.pb({n, -1});

	for(auto x : a) par(x);

	for(int i=0;i<a.size();i++) {
		for(int j=i+1;j<a.size();j++) {
			add(a[i].fi, a[j]);
			add(a[i].se, a[j]);
		}
	}


	printf("%d\n", (int)edges.size());
	for(auto i : edges) {
		printf("%d %d\n", i.fi, i.se);
	}

	return 0;

}





Measured memory_bytes: 384
#include<stdio.h>

int main(void){

int a,b,c,n,x;
int q=0;

while(1){
scanf("%d",&n); scanf("%d",&x);

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

for(a=1;a<=n-2;a++)
for(b=a+1;b<=n-1;b++)
for(c=b+1;c<=n;c++)
if(a+b+c==x)
 q++;

printf("%d\n",q);
q=0;
}

return 0;
}



Measured memory_bytes: 2060
#include<stdio.h>

int tax(int i, int x) {
	return i*(100 + x) / 100;
}

int main(void) {
	int x, y, s, max = 0,i,j;
	while (1) {
		max = 0;
		scanf("%d %d %d", &x, &y, &s);
		if (x == 0 && y == 0 && s == 0) break;
		for (i = 1; i < s; i++) {
			for (j = 1; j < s; j++) {
				if (tax(i, x) + tax(j, x) == s && max < tax(i, y) + tax(j, y)) {
					max = tax(i, y) + tax(j, y);
				}
			}
		}
		printf("%d\n", max);
	}
	return 0;
}

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

#define INF (1<<30)
#define MAX 2001
#define BLACK 0
#define GRAY 1
#define WHITE 2

vector< pair<int,int> > graph[2001];
int N,X,Y;

int cnt[2001];


void dijkstra(int s){
	int color[MAX], d[MAX];
	for(int i=1;i<=N;i++){
		d[i]=INF;	color[i]=WHITE;
	}

	priority_queue< pair<int,int> > PQ;

	d[s]=0;
	PQ.push({0,s});	// 距離、ノード番号
	color[s]=GRAY;

	while(PQ.empty()==false){
		pair<int,int> f=PQ.top();	PQ.pop();
		int u=f.second;		color[u]=BLACK;

		int cost=f.first*(-1);
		if(d[u]<cost) continue;

		for(int j=0; j<graph[u].size(); j++){
			int v=graph[u][j].first;
			if(color[v]==BLACK)continue;

			if(d[v]>(d[u]+graph[u][j].second)){
				d[v]=d[u]+graph[u][j].second;
				PQ.push({d[v]*(-1), v});	// 距離、ノード番号
				color[v]=GRAY;
			}
		}
	}

	for(int i=1;i<=N;i++){
		if(i<=s||d[i]==INF)continue;
		cnt[ d[i] ]++;
	}


}

int main(){
	cin>>N>>X>>Y;

	for(int i=1;i<N;i++){
		graph[i].push_back({i+1,1});
		graph[i+1].push_back({i,1});
	}
	graph[X].push_back({Y,1});	graph[Y].push_back({X,1});

	for(int s=1; s<=N; s++){
		dijkstra(s);		
	}

	for(int i=1;i<N;i++){
		cout<<cnt[i]<<endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N, K;
int H[300];
ll dp[300][301][301];
int que_si;
pl que[301];

int main() {
    cin >> N >> K;
    rep(i,N) cin >> H[i];
    vector<int> T(N+1);
    rep(i,N) T[i] = H[i];
    T[N] = 0;
    sort(T.begin(), T.end());
    T.erase(unique(T.begin(), T.end()), T.end());
    rep(i,N) {
        rep(j,T.size()) {
            if (H[i] == T[j]) H[i] = j;
        }
    }
    rep(i,N) rep(j,N+1) rep(k,N+1) dp[i][j][k] = linf;
    dp[0][1][0] = 0;
    dp[0][0][H[0]] = T[H[0]];
    for (int i = 1; i < N; i++) {
        for (int k = 0; k <= K; k++) {
            for (int h = N; h >= 0; h--) {
                if (k) dp[i][k][h] = min(dp[i][k][h], dp[i-1][k-1][h]);
                if (h >= H[i]) dp[i][k][H[i]] = min(dp[i][k][H[i]], dp[i-1][k][h]);
                else dp[i][k][H[i]] = min(dp[i][k][H[i]], dp[i-1][k][h]+T[H[i]]-T[h]);
            }
        }
    }
    ll ans = linf;
    rep(k,K+1) {
        rep(h,N+1) {
            ans = min(ans, dp[N-1][k][h]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 212608
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

    ll n, k, ans=0, MOD=998244353;
    cin >> n >> k;
    vector<pair<ll, ll> > v(k);
    for(ll i=0; i<k; i++){
        ll l, r;
        cin >> l >> r;
        v[i]={l, r};
    }
    vector<ll> dp(n, 0);
    dp[0]=1;
    for(ll i=1; i<n; i++){
        for(ll j=0; j<k; j++){
            ll l=v[j].first, r=v[j].second;
            if(i-l>=0) dp[i]=(dp[i]+dp[i-l])%MOD;
            if(i-r-1>=0) dp[i]=(dp[i]+MOD-dp[i-r-1])%MOD;
            if(i==n-1){
                if(i-l>=0) ans=(ans+dp[i-l])%MOD;
                if(i-r-1>=0) ans=(ans+MOD-dp[i-r-1])%MOD;
            }
        }
        dp[i]=(dp[i]+dp[i-1])%MOD;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4752
def main():
    from collections import namedtuple
    import sys
    input = sys.stdin.readline

    Sushi = namedtuple('Sushi', 'x cal')

    n, c = map(int, input().split())

    a = []
    for _ in range(n):
        x, v = map(int, input().split())
        a.append(Sushi(x=x, cal=v))
    # x昇順ソート済

    clock = [0] * (n + 1)  # 注目する寿司以前で離脱する最大摂取カロリー
    clock_to_0 = [0] * (n + 1)  # 時計回り->初期位置の最大摂取カロリー
    ma = 0  # 注目する寿司以前で離脱する最大摂取カロリー
    ma0 = 0  # 時計回り->初期位置の最大摂取カロリー
    curr = 0  # 現在のカロリー(移動によるカロリー消費を無視)
    for i, s in enumerate(a, start=1):
        curr += s.cal
        ma = max(ma, curr - s.x)
        ma0 = max(ma0, curr - s.x * 2)
        clock[i] = ma
        clock_to_0[i] = ma0

    anti = [0] * (n + 1)  # 注目する寿司以前で離脱する最大摂取カロリー
    anti_to_0 = [0] * (n + 1)  # 反時計回り->初期位置の最大摂取カロリー
    ma = 0  # 注目する寿司以前で離脱する最大摂取カロリー
    ma0 = 0  # 時計回り->初期位置の最大摂取カロリー
    curr = 0  # 現在のカロリー(移動によるカロリー消費を無視)
    for i, s in zip(range(n, -1, -1), reversed(a)):
        curr += s.cal
        ma = max(ma, curr - (c - s.x))
        ma0 = max(ma0, curr - (c - s.x) * 2)
        anti[i] = ma
        anti_to_0[i] = ma0

    ans = 0
    for exit_pos in range(1, n + 1):
        ans = max(
            ans,
            clock_to_0[exit_pos - 1] + anti[exit_pos],
            anti_to_0[(exit_pos + 1) % (n + 1)] + clock[exit_pos]
        )

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 1000006;
int res[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int m, k;
    scanf("%d %d", &m, &k);
    if (k > (1 << m) - 1) return printf("-1"), 0;
    int n = 1 << (m + 1), mx = (1 << m) - 1;
    if (k == 0) {
        for (int i = 0; i <= mx; i++) {
            printf("%d %d ", i, i);
        }
        return 0;
    }
    if (m == 1) return printf("-1"), 0;
    vector <pair <int, int> > v;
    for (int i = 0; i <= mx; i++) {
        if ((k ^ i) < i) continue;
        v.pb({i, k ^ i});
    }
    pair <int, int> p = v.back();
    v.pop_back();
    res[n/2-1] = p.fi;
    res[n/2] = p.se;
    res[0] = p.fi;
    res[n-1] = p.se;
    int j = 0;
    for (int i = 1; i < n / 2 - 1; i += 2) {
        res[i] = v[j].fi;
        res[i+1] = v[j].se;
        j++;
    }
    j = 0;
    for (int i = n - 2; i > n / 2; i -= 2) {
        res[i] = v[j].fi;
        res[i-1] = v[j].se;
        j++;
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", res[i]);
    }
    return 0;
}


Measured memory_bytes: 4860
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX


int n,ln;

int bn=0;
int non = 0;
int bit[800005]={};
vector<int> dats;

map<int,int> poss;

int bget(int p){
	int res=0;
	while(p){
		res+=bit[p];
		p -= (p&(-p));
	}
	return res;
}

void bset(int p,int q){//1.indexd
	while(p<=bn){
		bit[p]+=q;
		p += (p&(-p));
	}
}


int ordtopos(int p){
	int l = 0,r = dats.size();
	r--;
	
	while(l+1<r){
		int tyu = (l+r)/2;
		int no = bget(tyu);
		if(no>=p)r = tyu;
		else l = tyu;
	}
	return r;
}


void enkanbypos(int p){
	bset(p,-1);
	non--;
}


int main(void){
	/*
	bn = 10000;
	bset(1,1);
	bset(2,3);
	printf("%d\n",bget(2));
	printf("%d\n",bget(1));
	bset(1,-5);
	printf("%d\n",bget(2));
	printf("%d\n",bget(1));
	*/
	
	while(1){
		scanf("%d%d",&n,&ln);
		if(n==0)break;
		poss.clear();
		dats.clear();
		memset(bit,0,sizeof(bit));
		bn = 1;
		non = 0;
		while(bn<=n+5)bn*=2;
		dats.push_back(-10000);
		
		rep(i,n){
			int a,b;
			scanf("%d%d",&a,&b);//input .. 1.indexed
			//printf("%d %d\n",a,b);
			switch(a){
			case 0:
				{
					int no = ((int)dats.size());
					poss[b] = no;
					dats.push_back(b);
					bset(no,1);
					non++;
					if(non>ln)enkanbypos(ordtopos(1));
				}
				break;
			case 1:
				enkanbypos(ordtopos(b));
				break;
			case 2:
				printf("%d\n",dats[ordtopos(b)]);
				break;
			case 3:
				enkanbypos(poss[b]);
				break;
			}
			/*
			if(a==0){
				printf("ordpos .. %d is %d\n",1,ordtopos(1));
			}
			else if(a==1 || a==2){
				printf("ordpos .. %d is %d\n",b,ordtopos(b));
			}
			printf("non .. %d\n",non);
			rep(k,dats.size()){
				printf("(%d %d) ",dats[k],bget(k));
			}
			printf("\n\n");*/
		}
		printf("end\n");
	}
	
	return 0;
}

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

int main(){
  int n, m, p, x[101], ans;

  while(cin >> n >> m >> p && n){
    int sum=0;
    for(int i=1; i<=n; i++){
      cin >> x[i];
      sum+=x[i];
    }
    if(x[m]!=0){
      ans = sum * (100-p) / x[m];
      cout << ans << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,k;
string s[100000];

int main() {
  cin >> n ;
  rep(i,n) cin >> s[i];
  map<char,int> mp;
  for(char c='a';c<='z';c++) mp[c]=1e9;
  rep(i,n)for(char c='a';c<='z';c++){
    int cnt=count(all(s[i]),c);
    mp[c]=min(mp[c],cnt);
  }
  string ans;
  for(char c='a';c<='z';c++){
    rep(i,mp[c]) ans+=c;
  }
  cout << ans << endl;
}

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

using i64 = int64_t;

constexpr i64 MAX_N = 2e5;

i64 prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1];   // is_prime[i]がtrueならばiは素数

// n以下の素数の数を返す
i64 sieve(i64 n) {
    i64 p = 0;
    for (i64 i = 0; i <= n; i++)
        is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    for (i64 i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (i64 j = 2 * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    i64 x;
    cin >> x;
    sieve(MAX_N-1);
    for(int i=2;i<MAX_N;++i){
        if(i >= x && is_prime[i]){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, d, a;
  cin >> n >> d >> a;
  ll x[n], h[n];
  pair<ll, ll> xh[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> h[i];
    xh[i] = pair<ll, ll>(x[i], h[i]);
  }
  sort(xh, xh + n);
  pair<ll, ll> bomb_effect[n];
  int current = 0;
  ll damage = 0;
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = current; j < i; j++) {
      if(bomb_effect[j].first + 2 * d < xh[i].first) {
        //cout << "current\n";
        current += 1;
        damage -= bomb_effect[j].second;
      } else {
        //cout << "bombs\n";
        //cout << bomb_effect[j].first << "\n";
        //cout << bomb_effect[j].second << "\n";
        //cout << d << "\n";
        //cout << xh[i].first << "\n";
        break;
      }
    }
    //cout << "Damage: " << damage << "\n";
    xh[i].second -= damage;
    bomb_effect[i].first = xh[i].first;
    if(xh[i].second <= 0) {
      bomb_effect[i].second = 0;
    } else {
      ll bombs = (xh[i].second - 1) / a + 1;
      bomb_effect[i].second = bombs * a;
      ans += bombs;
      damage += bombs * a;
      //cout << "Bombs at: " << x[i] << "\n";
      //cout << bombs << " times" << "\n";
    }
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }
constexpr int INF = 1 << 30;
int main()
{
    int N, E, Q;
    cin >> N >> E >> Q;
    vector<map<int, int>> c(N);
    auto addEdge = [&](const int u, const int v) -> void { c[u][v] = c[v][u] = 1; };
    auto cutEdge = [&](const int u, const int v) -> void { c[u].erase(v), c[v].erase(u); };
    auto flow = [&](const int s, const int t, const int limit) {
        vector<bool> used(N, false);
        auto dfs = fix([&](auto&& self, const int s, const int t, const int f) -> int {
            if (s == t) { return f; }
            used[s] = true;
            for (auto& e : c[s]) {
                if (used[e.first] or e.second == 0) { continue; }
                const int res = min(f, e.second);
                const int d = self(self, e.first, t, res);
                if (d == 0) { continue; }
                return e.second -= d, c[e.first][s] += d, d;
            }
            return 0;
        });
        for (int flow = 0; flow < limit;) {
            fill(used.begin(), used.end(), false);
            const int f = dfs(s, t, limit - flow);
            if (f == 0) { return flow; }
            flow += f;
        }
        return limit;
    };
    for (int i = 0, F, T; i < E; i++) {
        cin >> F >> T;
        addEdge(F - 1, T - 1);
    }
    int ans = flow(0, N - 1, INF);
    for (int q = 0; q < Q; q++) {
        int M, A, B;
        cin >> M >> A >> B;
        A--, B--;
        if (M == 1) {
            addEdge(A, B);
        } else {
            const int cap = c[A][B];
            cutEdge(A, B);
            if (cap == 2) { swap(A, B); }
            if (cap != 1 and flow(A, B, 1) == 0) { ans--, flow(A, 0, 1), flow(N - 1, B, 1); }
        }
        cout << (ans += flow(0, N - 1, 1)) << endl;
    }

    return 0;
}



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

int main(){
    int N; cin >> N;
    vector<int> H(N);
    for( int i = 0; i < N; i++ ) cin >> H[i];

    for( int i = N-1; i >= 0; i-- ){
        int check = H[i] - H[i-1];
        if( check >= 0 ){continue;}
        else if( check == -1 ){ H[i-1]--; continue; }
        else {cout << "No" << endl; return 0;}
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=sum(A)-A[0]
b=sum(B)-B[-1]

if N==1:
    print(A[0]+B[0])
    exit()

ans=0
const=A[0]+B[-1]
for i in range(N-1):
    ans=max(ans,a+const,b+const)
    a-=A[i+1]
    b-=B[i]
    const+=A[i+1]

print(ans)




Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
N = int(input())

matrix = [list(map(int, input().split(' '))) for _ in range(N)]
buf = [list(m) for m in matrix]

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            buf[i][j] = min(buf[i][j],  buf[i][k] + buf[k][j])

for i in range(N):
    for j in range(N):
        if buf[i][j] != matrix[i][j]:
            print(-1)
            exit()

is_used = [[True for _ in range(N)] for m in matrix]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if k != i and k != j:
                if matrix[i][k] + matrix[k][j] == matrix[i][j]:
                    is_used[i][j] = False

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if is_used[i][j]:
            ans += matrix[i][j]

# ans = (sum([sum(b) for b in matrix]) - diff) // 2
print(ans)



Measured memory_bytes: 46556
#include <iostream>

using namespace std;

int ReturnDigitsSum( int n ) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    long sum;
    long sum_soms = 0;
    for (int i = 1; i < n + 1; i++) {
        sum = ReturnDigitsSum(i);
        if (sum >= a && sum <= b) sum_soms += i;
    }
    cout << sum_soms << endl;
}

Measured memory_bytes: 3596
iter :: [Int] -> (Bool,Int,[Int])
iter []     = (False,0,[])
iter (x:[]) = (False,0,(x:[]))
iter (x0:x1:xs) =
  let (f,n,x) = if x0 > x1
                then iter (x0:xs)
                else iter (x1:xs)
  in
    if x0 > x1
    then (True,n+1,x1:x)
    else (f,   n  ,x0:x)

ans n x = 
  let (f,n',x') = iter x
  in 
    if f
    then ans (n'+n) x'
    else (n'+n,x')

main = do
  n <- getLine
  c <- getLine
  let i = map read $ words c :: [Int]
      (n,x) = ans 0 i
  putStrLn $ unwords $ map show x
  print n

Measured memory_bytes: 4412
N,M = map(int,input().split())
H = list(map(int,input().split()))
c = [0] * N
for i in range(M):
    A,B = map(int,input().split())
    if H[A -1] >= H[B -1]:
        c[B - 1] += 1
    if H[B - 1] >= H[A - 1]:
        c[A - 1] += 1
print(c.count(0))

Measured memory_bytes: 20112
# coding: utf-8
try:
    from math import gcd
except:
    from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
l = []
for i in range(N):
    tmp = (x[i+1] - x[i])
    if tmp != 0:
        l.append(tmp)
l.sort()
ans = l[0]
for i in range(1, len(l)):
    ans = gcd(ans, l[i])
print(ans)

Measured memory_bytes: 16244
import java.util.Arrays;
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
}


class Solve{


	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();

		 String[] S = new String[N];
		 String[] s = new String[N];
		 int[] p = new int[N];
		 int[] P = new int[N];
		 int sub;
		 int[] res = new int[N];
		
		 for(int i = 0;i<N;i++) {
			 s[i]=sc.next();
			 p[i]=sc.nextInt();
			 S[i]=s[i];
		 }
		 	
		 
		 Arrays.sort(s);
		 
		 for(int i = 0;i<N;i++) {
			 for(int j=0;j<N;j++) {
				 if(s[i].equals(S[j])) {
					 P[i]=p[j];
					 S[j]="";
					 j=N;
				 }
			 }
			 
		 }
		 

		 for(int i = 0;i<N;i++) {
			//Arrays.fill(P,-1);
			
			for(int j = 0;j<N-1;j++) {
				if(s[j].equals(s[j+1])) {
					if(P[j]<P[j+1]) {
						sub=P[j];
						P[j]=P[j+1];
						P[j+1]=sub;
						
					}
				}
			}
			
		 }		     
		 for(int i = 0;i<N;i++) {
			 
			 for(int j =0;j<N;j++) {
				 if(P[i]==p[j]) {
					 res[i]=j+1;
				 }
			 }
			 System.out.println(res[i]);
		 }


		 }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=2e6+5;
char x[N], y[N];
void print(char *s) {
	int len=N;
	while(s[len-1]==0) --len;
	std::reverse(s, s+len);
	for(int i=0; i<len; ++i) s[i]+=48;
	puts(s);
}
int main() {
	int n, m, k;
	std::vector<int> valid;
	assert(scanf("%d%d%d%s%s", &n, &m, &k, x, y)==5);
	std::reverse(x, x+n);
	std::reverse(y, y+m);
	for(int i=0; i<n; ++i) x[i]-=48;
	for(int i=0; i<m; ++i) y[i]-=48;
	for(int i=std::max(n, m); i--; )
		if(x[i]&&y[i]) {
			std::vector<int> update;
			x[i]=y[i]=0;
			for(int j=i, r=k, up=3; ; ++j) {
				if(up==3) {
					if(valid.empty()||r<valid.back()-j) {
						j+=r;
						x[j]=y[j]=1;
						update.push_back(j);
						break;
					}
					r-=valid.back()-j;
					j=valid.back();
				}
				if(x[j]==1) {
					valid.pop_back();
					if(up==1) {
						if(--r<0) {
							x[j]=y[j]=1;
							update.push_back(j);
							break;
						}
						x[j]=y[j]=0, up=3;
					} else if(up==2) {
						x[j]=y[j]=0;
					} else {
						x[j]=0, y[j]=1, up=2;
						update.push_back(j);
					}
				} else if(y[j]==1) {
					valid.pop_back();
					if(up==2) {
						if(--r<0) {
							x[j]=y[j]=1;
							update.push_back(j);
							break;
						}
						x[j]=y[j]=0, up=3;
					} else if(up==1) {
						x[j]=y[j]=0;
					} else {
						x[j]=1, y[j]=0, up=1;
						update.push_back(j);
					}
				} else {
					x[j]=up/2;
					y[j]=up%2;
					update.push_back(j);
					break;
				}
			}
			while(!update.empty()) {
				valid.push_back(update.back());
				update.pop_back();
			}
		} else if(x[i]||y[i])
			valid.push_back(i);
	print(x), print(y);
	return 0;
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


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


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>21){
    cout<<"bust"<<endl;
    return 0;
  }
  else{
    cout<<"win"<<endl;
  }
}

Measured memory_bytes: 256