akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int mi = 1000000007, ma = 0;
	string s;
	cin >> s;
	int n = s.size();
	sort(s.begin(), s.end());
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			a++;
		}
		if (s[i] == 'b') {
			b++;
		}
		if (s[i] == 'c') {
			c++;
		}
	}
	mi = min(a, min(b, c));
	ma = max(a, max(b, c));
	if (ma - mi > 1) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;
int score[110];

int main() {
  cin >> N;
  for (int i=0; i<N*(N-1)/2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c == d) {
      score[a-1]++;
      score[b-1]++;
    }
    else if (c > d) score[a-1] += 3;
    else            score[b-1] += 3;
  }
  vector<int> t;
  for (int i=0; i<N; i++) t.push_back(score[i]);
  sort(t.begin(), t.end());

  int x = 0;
  for (int i=0; i<N; i++) {
    cout << N - (upper_bound(t.begin(), t.end(), score[i]) - t.begin() - 1) << "\n";
  }
  return 0;
}

Measured memory_bytes: 3156
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

int main()
{
    for(;;){
        int c, d, w, x; // næAúAÌÍAß§ú
        cin >> c >> d >> w >> x;
        if(c == 0)
            return 0;

        vector<vector<int> > e(c, vector<int>(d)); // v
        vector<vector<int> > f(c, vector<int>(d)); // S
        for(int i=0; i<c; ++i){
            for(int j=0; j<d; ++j){
                cin >> e[i][j];
            }
        }
        for(int i=0; i<c; ++i){
            for(int j=0; j<d; ++j){
                cin >> f[i][j];
            }
        }

        vector<vector<int> > dp(x+1, vector<int>(w+1, 0));
        for(int i=0; i<d; ++i){
            vector<vector<int> > next = dp;
            for(int j=0; j<c; ++j){
                int sumE = 0;
                int sumF = 0;
                for(int k=j; k<c; ++k){
                    if(e[k][i] == 0)
                        break;
                    sumE += e[k][i];
                    sumF += f[k][i];
                    for(int a=0; a<=x; ++a){
                        for(int b=0; b<=w; ++b){
                            if(j == k){
                                if(b-sumF >= 0)
                                    next[a][b-sumF] = max(next[a][b-sumF], dp[a][b] + sumE);
                            }else{
                                if(a-1 >= 0 && b-sumF >= 0)
                                    next[a-1][b-sumF] = max(next[a-1][b-sumF], dp[a][b] + sumE);
                            }
                        }
                    }
                }
            }
            dp.swap(next);
        }

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

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

int gcd(int a, int b) {
   int r;
   do{
       r=a%b;
       a=b;
       b=r;
   }while(r != 0);
   
   return a;
}

   int main(void){
   int a,b;
   while(cin >> a >> b) {
      int lcm = a/gcd(a,b)*b;
     cout << gcd(a,b) << " " << lcm << endl;
   }
   return 0;
}



Measured memory_bytes: 3068
def C():
    temp = [int(n) for n in input().split()]
    N = temp[0]
    K = temp[1]
    S = temp[2]
    if S == 10**9:
        ans = [str(S)]*K + [str(S-1)]*(N-K)
    else:
        ans = [str(S)]*K + [str(S+1)]*(N-K)
    print(' '.join(ans))
C()

Measured memory_bytes: 7012
#include <stdio.h>

int main(){
    int N;
    unsigned long Y; 
    int d;
    int a,b,c;

    scanf("%d", &N);
    scanf("%lu", &Y);

    d = (Y / 1000) - N;

    for(a = 0;a <= N;a++){
        for(b = 0;b <= N;b++){
          if (a + b > N) continue;
          if ((10000 * a + 5000 * b + 1000 * (N - a - b)) == Y){
               printf("%d %d %d",a,b,N-a-b);
               return 0;
           } 
        }
    }

    printf("-1 -1 -1");

    return 0;
}

Measured memory_bytes: 128
import sys
N = int(input())
if N == 0:
    print("0")
    sys.exit()
ans = ""
while N != 0:
    if N % 2 == 1:
        ans = "1" + ans
        if N > 0:
            N = N // 2 *(-1)
        else:
            N = N // -2 + 1
    else:
        ans = "0" + ans
        N //= -2
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int planA = N*A;
		int planB = B;
		
		
		if (planA <= planB){
			 System.out.println(planA);	
		}else {
			 System.out.println(planB);
		}
		
		
	}
}

Measured memory_bytes: 21844
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/
int main(){
    int n;
    static char s[200000][20];
    ll cnt[5]={};

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
        switch(s[i][0]){
            case 'M':
                cnt[0]++;
                break;
            case 'A':
                cnt[1]++;
                break;
            case 'R':
                cnt[2]++;
                break;
            case 'C':
                cnt[3]++;
                break;
            case 'H':
                cnt[4]++;
                break;
        }
    }

    for(int i=0;i<5;i++){
        //printf("%d : %d\n",i,cnt[i]);
    }
    ll ans=0;
    ll max=MAX;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans+=cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 2176
nm = gets.split(" ").map(&:to_i)

mat = Array.new
i = 0
nm[0].times do
  mat[i] = gets.split(" ").map(&:to_i)
  i += 1
end

v = Array.new
i = 0
nm[1].times do
  v[i] = gets.to_i
  i += 1
end

for i in 0..nm[0]-1 do
  sum = 0
  for j in 0..nm[1]-1 do
    sum += mat[i][j] * v[j]
  end
  printf "%d\n", sum
end

Measured memory_bytes: 8924
/******* all required header files *******/
#include<iostream>
#include<algorithm>
#include<cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b;
	cin>>a>>b;
	if(a == 1) a = a + 13;
	if(b == 1) b = b + 13;
	if(a > b) cout<<"Alice";
	if(b > a) cout<<"Bob";
	if(b == a) cout<<"Draw";
	return 0;
}


Measured memory_bytes: 256
<?php
  	fscanf(STDIN, "%d", $format);

	$former = floor($format/100);
	$latter = $format%100;
	$YYMM = FALSE;
	$MMYY = FALSE;

	if ($former <= 12 && $former > 0) $MMYY = TRUE;
	if ($latter <= 12 && $latter > 0) $YYMM = TRUE;

	if ($YYMM && $MMYY) echo "AMBIGUOUS\n";	
	else if ($YYMM) echo "YYMM\n";
	else if ($MMYY) echo "MMYY\n";
	else echo "NA\n";
	


Measured memory_bytes: 4604
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>H(N);
  for(int i=0;i<=N-1;i++){
  
    cin>>H[i];
  }
  for(int i=N-1;i>0;i--){
  
    if(H[i-1]-H[i]==1){
    
      H[i-1]--;
    }
    if(H[i]>=H[i-1]){
    
      
    }
    else {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}

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

int main(){

  int a, b, valid, cnt;

  cnt = 0;
  while(cin >> a >> b){
    if(a == 0 && b == 0) break;
    valid = 0;
    if(cnt != 0) cout << endl;
    
    for(int i=a; i<=b; i++){
      if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)){
        cout << i << endl;
        valid = 1;
      }
    }

    if(valid == 0) cout << "NA" << endl;
    cnt++;

  }

  return 0;

}

Measured memory_bytes: 1156
#include <cstdio>
using namespace std;

int main(void)
{
    int cost[10];
    int cost_sum;
    int v1, v2;
    int ans_place;
    
    
    while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &cost[0], &cost[1], &cost[2], &cost[3], &cost[4], &cost[5], &cost[6], &cost[7], &cost[8], &cost[9], &v1, &v2) != EOF){
        cost_sum = ans_place = 0;
        
        for (int i = 0; i < 10; i++){
            cost_sum += cost[i];
        }
        
        double tmp = (double)cost_sum / (double)(v1 + v2);
        
        cost_sum = 0;
        
        while (cost_sum < (tmp * v1)){
            cost_sum += cost[ans_place];
            ans_place++;
        }
        
        printf("%d\n", ans_place);
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 2012345678;
int main() {
	int N, P;
	cin >> N >> P;
	vector<vector<int> > G(N);
	vector<int> deg(N);
	vector<int> A(P), B(P), C1(P), C2(P);
	for (int i = 0; i < P; ++i) {
		cin >> A[i] >> B[i] >> C1[i] >> C2[i]; --A[i], --B[i];
		G[A[i]].push_back(B[i]);
		++deg[B[i]];
	}
	queue<int> que;
	for (int i = 0; i < N; ++i) {
		if (deg[i] == 0) que.push(i);
	}
	vector<int> ord(N, -1);
	int cur = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		ord[u] = cur++;
		for (int i : G[u]) {
			--deg[i];
			if (deg[i] == 0) que.push(i);
		}
	}
	vector<int> perm(P);
	for (int i = 0; i < P; ++i) perm[i] = i;
	sort(perm.begin(), perm.end(), [&](int i, int j) {
		return B[i] != B[j] ? ord[B[i]] < ord[B[j]] : ord[A[i]] < ord[A[j]];
	});
	vector<int> ip(N);
	for (int i = 0; i < N; ++i) ip[ord[i]] = i;
	vector<int> rip = ip;
	reverse(rip.begin(), rip.end());
	vector<vector<int> > dp(N, vector<int>(N, inf));
	dp[0][0] = 0;
	for (int i : perm) {
		for (int j : rip) {
			dp[B[i]][j] = min(dp[B[i]][j], dp[A[i]][j] + C1[i]);
			dp[j][B[i]] = min(dp[j][B[i]], dp[j][A[i]] + C1[i]);
		}
		dp[B[i]][B[i]] = min(dp[B[i]][B[i]], dp[A[i]][A[i]] + C1[i] + C2[i]);
	}
	cout << dp[N - 1][N - 1] << endl;
	return 0;
}


Measured memory_bytes: 6844
S = input()
ans = 0
for i in range(len(S)):
  for j in range(len(S)):
    tmp = S[i:j+1]
    for k in tmp:
      if k != 'A' and k != 'C' and k != 'G' and k != 'T':
        break
    else:
      if ans <= len(tmp):
        ans = len(tmp)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  rrep(i,2000050)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

ll nCr(ll N,ll K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

ll nHr(ll N,ll K){
  if(!N&&!K)return 1;
  if(!N)return 0;
  return nCr(N+K-1, K);
}

void Main() {
  ll n,k;
  cin >> n >> k;
  k=min(n-1,k);
  init();
  ll ans=0;
  rep(i,k+1) {
    ans+=nCr(n,i)*nHr(n-i,i);
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 31488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = new int[n];
        for(int i = 0; i < n; i++) S[i] = Integer.parseInt(sc.next());
        int q = sc.nextInt();
        int ans = 0;
        label:
        for(int i = 0; i < q; i++) {
            int t = Integer.parseInt(sc.next());
            int l = 0;
            int u = n-1;
            while(l <= u) {
                int m = (l + u) / 2;
                if(S[m] == t) {
                    ans++;
                    continue label;
                }
                if(S[m] < t) l = m+1;
                else u = m-1;
            }
        }
        System.out.println(ans);
    }
}


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

vector<int> s[2];
vector<ull> u[2];

const int N = 500;
int n;
int val[2][N];
int d[N][N];

void flip() {
	rep(i, n)rep(j, i) {
		swap(d[i][j], d[j][i]);
	}
}
bool solve() {
	rep(i, n)rep(j, n) d[i][j] = -1;
	rep(k, 2) {
		rep(i, n) {
			int x = val[k][i];
			if (s[k][i] != x) {
				rep(j, n) {
					if (d[i][j] == !x) return false;
					d[i][j] = x;
				}
			}
		}
		flip();
	}
	rep(_, 2) {
		rep(k, 2) {
			rep(i, n) {
				int x = val[k][i];
				if (s[k][i] == x) {
					vector<int> p;
					bool ok = false;
					rep(j, n) {
						if (d[i][j] == -1) p.push_back(j);
						if (d[i][j] == x) ok = true;
					}
					if (ok) continue;
					if (p.size() == 0) return false;
					if (p.size() == 1) {
						d[i][p[0]] = x;
					}
				}
			}
			flip();
		}
	}

	vector<int> is, js;
	rep(i, n) {
		bool filled = true;
		rep(j, n) if (d[i][j] == -1) filled = false;
		if (!filled) is.push_back(i);
	}
	rep(j, n) {
		bool filled = true;
		rep(i, n) if (d[i][j] == -1) filled = false;
		if (!filled) js.push_back(j);
	}
	rep(i, is.size())rep(j, js.size()) {
		d[is[i]][js[j]] = (i + j) % 2;
	}
	return true;
}

ull ans[N][N];

int main() {
	cin >> n;
	rep(i, 2) {
		s[i] = vector<int>(n);
		rep(j, n) cin >> s[i][j];
	}
	rep(i, 2) {
		u[i] = vector<ull>(n);
		rep(j, n) cin >> u[i][j];
	}

	rep(b, 64) {
		rep(i, 2)rep(j, n) val[i][j] = u[i][j] >> b & 1;
		if (!solve()) {
			cout << "-1" << endl;
			return 0;
		}
		rep(i, n)rep(j, n) ans[i][j] |= ull(d[i][j]) << b;
	}
	rep(i, n) {
		rep(j, n) {
			cout << ans[i][j] << (j == n - 1 ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 9372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] a = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			a[i] = Integer.parseInt(scan.next());
			sum += a[i];
		}
		float ave = (float)sum / (float)N;
		float min_dis = Math.abs(ave - (float)a[0]);
		int min_index = 0;
		for (int i = 1; i < N; i++) {
			if (Math.abs(ave - (float)a[i]) < min_dis) {
				min_dis = Math.abs(ave - a[i]);
				min_index = i;
			}
		}
		System.out.println(min_index);
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    string in = "";
    cin >> in;
    int cnt_s = 0, ans = 0;
    for (char c : in) {
        if (c == 'S') {
            cnt_s++;
        }
        else {
            if (cnt_s == 0) {
                ans++;
            }
            else {
                cnt_s--;
            }
        }
    }
    cout << ans * 2 << endl;    
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
   int N;
 
   scanf("%d",&N);
   
   
   if((N%10==2)||(N%10==4)||(N%10==2)||(N%10==5)||(N%10==7)||(N%10==9)){
      printf("hon\n");
   } else if((N%10==0)||(N%10==1)||(N%10==6)||(N%10==8)){
      printf("pon\n");
   } else if(N%10==3){
      printf("bon\n");
   }
   return 0;
}

Measured memory_bytes: 1656
// 2018/12/27 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;

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

	for(int j=1; j<=M; j++){
		for(int i=0; i<N-1; i++){
			if(A[i]%j>A[i+1]%j){
				swap(A[i], A[i+1]);
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int N;
  cin >> N;

  vector<int> a(N);
  REP(i, N) cin >> a[i];
  
  sort(ALL(a));
  // queue<int> b;
  // int MAX = 1;
  // REP(i,N){
  //   if(b.empty()){
  //     b.push(a.at(i));
  //   }else{
  //     if(a.at(i)-b.front()<=2){
  //       b.push(a.at(i));
  //     }else{
  //       MAX=max(MAX,int(b.size()));
  //       b.push(a.at(i));
  //       int c = b.front();
  //       while(b.front()==c){
  //         b.pop();
  //       }
  //     }
  //   }
  //   if(i==N-1){
  //     MAX = max(MAX,int(b.size()));
  //   }
  // }

  // cout << MAX << endl;

  map<int,int> b;
  REP(i,N){
    b[a.at(i)]++;
  }
  int MAX = 1;
  FOR(i,a.at(0),a.at(N-1)+1){
    MAX = max(MAX,b[i]+b[i-1]+b[i+1]);
  }
  cout << MAX << endl;
}

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


int main(){
	int x, y;
	
	while(true) {
		cin >> x >> y;
		if(x == 0 && y == 0) break;
		if(x > y) swap(x, y);
		cout << x << " " << y << endl;
	}


	return 0;
}





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

typedef long long ll;
const ll mod=1e9+7;
const ll N=3e5+1;
const ll INF=1e10;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<ll> a(n);
	for(ll &i:a) cin>>i;
	ll sum=0,ans=0;
	for(int i=0;i<n;i++){
		ans=(ans+sum*a[i])%mod;
		sum=(sum+a[i])%mod;
	}
	cout<<ans;
} 


Measured memory_bytes: 4780
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int n, d, x,ans=0,input;
	cin >> n >> d >> x;
	REP(i, n) {
		cin >> input;
		for (int day = 1; day <= d;day+=input) {
			ans++;
		}
	}
	ans += x;
	cout << ans;

	return(0);
}

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

using namespace std;

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

typedef complex<double> P;
typedef vector<P> Polygon;

double const EPS = 1e-7;
double const inf = 1e10;

struct Line : public vector<P>
{
  Line() {}
  Line(P const& a, P const& b) {
    push_back(a), push_back(b);
  }
  P vectorize() { return (*this)[1]-(*this)[0]; }
  double length() { return abs((*this)[1]-(*this)[0]); }
};

inline double dot(P const& a, P const& b) { return real(conj(a)*b); }
inline double cross(P const& a, P const& b) { return imag(conj(a)*b); }

enum { counter_clockwise = +1, clockwise = -1, cab_online = +2, abc_online = -2, on_segment = 0 };
int ccw(P a, P b, P c) {
  b -= a, c -= a;
  if(cross(b, c) > 0) return counter_clockwise;
  if(cross(b, c) < 0) return clockwise;
  if(dot(b, c) < 0) return cab_online;
  if(norm(b) < norm(c)) return abc_online;
  return on_segment;
}

typedef Line Segment;


P crosspoint(Line const& l, Line const& m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  if(abs(A) < EPS && abs(B) < EPS) { return m[0]; } // same line
  if(abs(A) < EPS) { return P(inf, inf); }
  return m[0] + B / A * (m[1]-m[0]);
}

// Notice: Return left part of the polygon.
Polygon convex_cut(Polygon const& G, Line const& l) {
  Polygon left_part;
  rep(i, G.size()) {
    P const& a = G[i], b = G[(i+1)%G.size()];
    Line const& ab = Line(a, b);
    if(ccw(l[0], l[1], a) != clockwise) { left_part.push_back(a); }
    if(ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0) {
      P r = crosspoint(ab, l);
      if(r == P(inf, inf)) { continue; }
      left_part.push_back(r);
    }
  }
  return left_part;
}

// Notice: The border of the polygon in counterclockwise order.
bool able_polygon(Polygon const& G, double x) {
  int N = G.size();
  /*
    Polygon A;
    A.push_back(P(inf,inf)); A.push_back(P(-inf,inf));
    A.push_back(P(-inf,-inf)); A.push_back(P(inf,-inf));
  */
  Polygon A = {{-inf, -inf}, {inf, -inf}, {inf, inf}, {-inf, inf}};
  rep(i, N) {
    Line ln(G[i], G[(i+1)%N]);
    P shift = ln.vectorize()*polar(x/ln.length(), M_PI/2.);
    A = convex_cut(A, Line(G[i] + shift, G[(i+1)%G.size()] + shift));
  }
  return !A.empty();
}

double solve(Polygon const& G) {
  double L = 0., R = inf;
  rep(loop, 1000) {
    double M = (L+R) / 2.;
    if(able_polygon(G, M)) { L = M; }
    else { R = M; }
  }
  return L;
}

int main() {
  
  int N;
  while(cin >> N && N) {
    Polygon G(N);
    rep(i, N) {
      double x, y; cin >> x >> y;
      G[i] = P(x, y);
    }
    printf("%.8f\n", solve(G));
  }
  return 0;
}

Measured memory_bytes: 1272
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        String[] siritori = new String[a];
        String end="";
        String head="";
        HashSet<String> hs = new HashSet<String>();
        int tmp;
        boolean chkFlg=true;
        for(int i=0;i<a;i++) {
        	siritori[i]=scanner.next();
        	tmp = hs.size();
    		hs.add(siritori[i]);
        	// 単語の1つ目は任意の単語なので、チェックを行わず、ループの2回目から判定を行う
        	if(i!=0) {
        		// headに今の単語の最初の1文字を入れる
        		head=siritori[i].substring(0,1);

        		// 今の単語の頭文字と前の単語の末尾の文字が不一致の場合、しりとりにならないので終了
        		if(!head.equals(end)){
        			System.out.println("No");
        			chkFlg=false;
        			break;
        		}
        		// 今の単語が今より前に出現していた場合、しりとりにならないので終了
        		/*
        		for(int j=0;j<i;j++) {
        			if(siritori[j].equals(siritori[i])) {
        				System.out.println("No");
        				chkFlg=false;
        				break;
        			}
        		}
        		*/
        		if(tmp==hs.size()) {
        			System.out.println("No");
    				chkFlg=false;
    				break;
        		}
        	}
        	// endに今の単語の最後の1文字を入れる
        	end=siritori[i].substring(siritori[i].length()-1, siritori[i].length());
        }
        // 最後までループが回る場合はしりとり成功
        if(chkFlg) {
        	System.out.println("Yes");
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll mod = 998244353;

const ll INF = 1e15;

template<typename T>
void cmpmax(T & reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> as(n);
	rep(i, n) {
		ll a, b, c;
		cin >> a >> b >> c;
		as[i].push_back(a);
		as[i].push_back(b);
		as[i].push_back(c);
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(3, 0));
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (j == k) continue;
				cmpmax(dp[i + 1][j], dp[i][k] + as[i][k]);
			}
		}
	}
	ll upper = 0;
	rep(i, 3) {
		cmpmax(upper, dp[n][i]);
	}
	cout << upper << endl;
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 200005;

int a[MAX_N];
int k[MAX_N];
int bit[MAX_N+1],n;
map<int,int> mp;

//i???????????§??????????¨??????????(i???1????????????)
int sum(int i)
{
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
//i???????????????x????????????(i???1????????????)
void add(int i,int x)
{
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}
}

int main()
{
	cin >> n;
	rep(i,n){
		scanf("%d",&a[i]);
		k[i] = a[i];
		mp[a[i]] = i;
	}
	sort(a,a+n);
	rep(i,n){
		k[mp[a[i]]] = i+1;
	}
	ll ans = 0;
	rep(j,n){
		ans += j - sum(k[j]);
		add(k[j],1);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int n, a;
int x[50];
ll dp[51][51][2501];
ll ans = 0;

int main(){
	cin >> n >> a;
	rep(i,n) cin >> x[i];
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++){
		rep(j,51) rep(k,2501) dp[i+1][j][k] += dp[i][j][k];
		for(int j = 1; j <= 50; j++){
			for(int k = x[i]; k <= 2500; k++){
				dp[i+1][j][k] += dp[i][j-1][k-x[i]];
			}
		}
	}
	for(int i = 1; i <= n; i++){
		ans += dp[n][i][a*i];
	}
	cout << ans << endl;
}





Measured memory_bytes: 50048
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <unordered_map>

using namespace std;
using ll = long long;

struct Block {
    ll w;
    ll s;
    ll v;
};

const int NNODES = 1009;
const int NWEIGHTS = 1e7 + 7;
Block b[NNODES];
// int dp[NNODES][NWEIGHTS];
ll dp[NWEIGHTS];
ll t[NWEIGHTS];

bool cmp(Block a, Block b) {
    return (a.s + a.w) < (b.s + b.w);
}

ll solve(int n) {
    ll maxV = 0;
    dp[b[0].w] = b[0].v;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            if (j-b[i].w > 0 && dp[j-b[i].w] > 0) {
                t[j] = max(t[j], dp[j-b[i].w] + b[i].v);
                // printf("rrr %d %lld %lld\n", j, b[i].w, dp[j]);
            }
        }
        t[b[i].w] = max(t[b[i].w], b[i].v);
        // printf("rrr %lld %lld\n", b[i].w, dp[b[i].w]);

        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            dp[j] = max(dp[j], t[j]);
            t[j] = 0;
        }
    }
    
    for (int j = 0; j <= NWEIGHTS; j++) {
        maxV = max(maxV, dp[j]);
        // if (dp[j] > 0) {
        //     printf("sss %d %lld\n", j, dp[j]);
        // }
    }
    return maxV;
}
int main() {
    memset(dp, 0, sizeof(dp));
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll tw, ts, tv;
        cin >> tw >> ts >> tv;
        b[i] = Block{tw, ts, tv};
    }
    sort(b, b+n, cmp);
    // for (int i = 0; i < n; i++) {
    //     printf("%lld %lld %lld\n", b[i].w, b[i].s, b[i].v);
    // }
    printf("%lld\n", solve(n));
    return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")

#define MAX 110000

template<class RandomAccessIterator>
void comb_sort(RandomAccessIterator first, RandomAccessIterator second){
	long long N = second-first, h = N*10/13;
	bool flag = true;
	while(flag){
		flag = false;
		if(h==9||h==10) h = 11;
		for(int j = N-1; j-h >= 0; j--){
			if(*(first+j) < *(first+j-h)){
				swap(*(first+j),*(first+j-h));
				flag = 1;
			}
		}
		if(h>1)flag = true,h = h*10/13;
		else h = 1;
	}
}

int h[MAX];
signed main(){
	cout<<fixed<<setprecision(7);
	int N, K, ans = INF;
	
	cin>>N>>K;
	
	for(int i = 0; i < N; i++){
		cin>>h[i];
	}
	
	comb_sort(h, h+N);
	
	for(int i = 0; i + K - 1< N; i++){
		ans = min(ans, h[i+K-1]-h[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
from collections import deque 
d = deque()
n, q = map(int, input().split())
for i in range(n):
    d.append(input().split())
now = 0
while d:
    name, time = d.popleft()
    time = int(time)
    if time <= q:
        now += time
        print(name, now)
    else:
        time -= q
        d.append([name, time])
        now += q

Measured memory_bytes: 20112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxm=2e6+5;
char s[maxm];
int n;
struct SAM{
    int ch[maxm][26];
    int fa[maxm],l[maxm];//l[]是等价类的最长字符串长度len
    int last=1,tot=1;//tot是节点数量
    //
    int lc[maxm],rc[maxm];
    int cnt[maxm];
    int idx[maxm];
    int solve(){
        for(int i=0;i<=tot;i++)cnt[i]=0;
        for(int i=1;i<=tot;i++)cnt[l[i]]++;
        for(int i=1;i<=tot;i++)cnt[i]+=cnt[i-1];
        for(int i=1;i<=tot;i++)idx[cnt[l[i]]--]=i;
        //
        for(int i=tot;i>=1;i--){
            int x=idx[i];
            if(!lc[fa[x]]||lc[x]<lc[fa[x]]){
                lc[fa[x]]=lc[x];
            }
            if(!rc[fa[x]]||rc[x]>rc[fa[x]]){
                rc[fa[x]]=rc[x];
            }
        }
        int ans=0;
        for(int i=2;i<=tot;i++){
            ans=max(ans,min(rc[i]-lc[i],l[i]));
        }
        return ans;
    }
    //
    void add(int c,int pos){//传入s[i]-'a'而不是s[i]
        int p=last,np=++tot;last=np;l[np]=l[p]+1;
        for(;p&&!ch[p][c];p=fa[p])ch[p][c]=np;
        if(!p)fa[np]=1;
        else{
            int q=ch[p][c];
            if(l[p]+1==l[q])fa[np]=q;
            else{
                int nq=++tot;l[nq]=l[p]+1;
                memcpy(ch[nq],ch[q],sizeof ch[q]);
                fa[nq]=fa[q];fa[q]=fa[np]=nq;
                for(;ch[p][c]==q;p=fa[p])ch[p][c]=nq;
            }
        }
        //记录最左和最右位置
        lc[np]=rc[np]=pos;
    }
    void init(){
        for(int i=1;i<=tot;i++){
            memset(ch[i],0,sizeof ch[i]);
            fa[i]=l[i]=0;
        }
        last=tot=1;
    }
}S;
signed main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    S.init();
    for(int i=1;i<=n;i++){
        S.add(s[i]-'a',i);
    }
    int ans=S.solve();
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  cout << v.at(n-1)-v.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  char d[2];
  cin >> n >> m;
  int a[n],b,c;
  for(int i = 0;i < n;i++) a[i] = i+1;
  for(int i = 0;i < m;i++){
    cin >> b >> d[0] >> c;
    swap(a[b-1],a[c-1]);
  }
  for(int i = 0;i < n;i++)cout << a[i] << endl;
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    int mx = max({a, b, c});
    int ans = 0;
    if(a < mx){
        int k = (mx-a)/2;
        ans += k;
        a += k*2;
    }
    if(b < mx){
        int k = (mx-b)/2;
        ans += k;
        b += k*2;
    }
    if(c < mx){
        int k = (mx-c)/2;
        ans += k;
        c += k*2;
    }
    int da = mx-a;
    int db = mx-b;
    int dc = mx-c;
    if(da == 0 && db == 0 && dc == 0) ans += 0;
    if(da == 0 && db == 0 && dc == 1) ans += 2;
    if(da == 0 && db == 1 && dc == 0) ans += 2;
    if(da == 1 && db == 0 && dc == 0) ans += 2;
    if(da == 0 && db == 1 && dc == 1) ans += 1;
    if(da == 1 && db == 0 && dc == 1) ans += 1;
    if(da == 1 && db == 1 && dc == 0) ans += 1;
    if(da == 1 && db == 1 && dc == 1) ans += 2;
    cout << ans << endl;
    return 0;
}


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

int main(){
 UL N; cin>>N;
 UL ans=N/50*2;
 N %= 50;
 ans += N%5;
 N /= 5;
 UL M[10] = {0,1,1,2,2,1,2,2,3,3};
 ans += M[N];
 cout<<ans<<endl;
 return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  string s;
  int n;
  cin >> s;
  n = s.length();
  int cur = 0;
  int ans = 0;
  rep(i, n) {
    if(s[i] == 'S') cur++;
    else if(cur == 0) ans++;
    else cur--;

  }
  cout << ans * 2 << endl;
}

Measured memory_bytes: 640
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        mut s: chars,
    }
    s.reverse();
    let mut cnt = vec![0; 2020];
    let mut p = 1;
    let mut cur = 0;
    let mut ans = 0;
    for i in 0..s.len() {
        cur += p * (s[i] as usize - '0' as usize);
        cur %= 2019;
        if cur == 0 {
            ans += 1;
        }
        ans += cnt[cur];
        cnt[cur] += 1;
        p *= 10;
        p %= 2019;
    }
    println!("{}", ans);
}


Measured memory_bytes: 3152
import sys
sys.setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [2, 5, 5, 4, 5, 6, 3, 7, 6]
INF = 10 ** 8

for i in range(9):
    if i + 1 not in A:
        num[i] = INF

dp = [-INF] * (N + 1)
dp[0] = 0

for i in range(1, N + 1):
    for j in range(9):
        k = i - num[j]
        if k >= 0:
            dp[i] = max(dp[i], dp[k] + 1)

ans = ''
rest = N
for i in range(dp[N]):
    t = 0
    for j in range(8, -1, -1):
        k = rest - num[j]
        if k >= 0:
            if dp[rest - num[j]] == dp[rest] - 1:
                t = max(t, j + 1)
    ans += str(t)
    rest -= num[t - 1]

print(int(ans))


Measured memory_bytes: 42860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// https://www.youtube.com/watch?v=UTVg7wzMWQc&feature=youtu.be
// https://atcoder.jp/contests/abc152/submissions/9635583
int n;
struct Edge {
  int to, id;
  Edge(int to, int id) : to(to), id(id) {}
};
vector<vector<Edge> > G;
vector<int> es;
vector<ll> eset; // es を bit で管理

bool dfs(int v, int tv, int p = -1) { // target v
  if (v == tv) {
    es = vector<int>();
    return true;
  }
  for (auto e : G[v]) {
    if (e.to == p) continue;
    if (dfs(e.to, tv, v)) {
      es.eb(e.id);
      return true;
    }
  }
  return false;
}
void solve() {
  cin >> n;
  G.resize(n);

  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b, i);
    G[b].eb(a, i);
  }

  int m;
  cin >> m;
  eset.resize(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    dfs(a, b);
    rep(j, sz(es)) eset[i] |= 1LL << es[j];
  }

  // 包除原理
  ll ans = 0;
  // (すべての塗り方) - (1つ満たさない塗り方) + ...
  rep(i, 1 << m) {
    int cnt = __builtin_popcount(i);
    ll bit = 0;
    rep(j, m) {
      if (i & (1 << j)) {
        bit |= eset[j];
      }
    }
    int cnt_bit = __builtin_popcountll(bit); // debuged, ll
    cnt_bit = n - 1 - cnt_bit; // bit が 0
    ll add = 1LL << cnt_bit;
    if (cnt % 2) ans -= add;
    else ans += add; // i=0, すべての塗り方
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
str1 = ["A", "C", "G", "T"]
s = gets.chomp
result = ""
s.each_char { |ch|
  if str1.include?(ch) == true
    result = result + "1"
  else
    result = result + "0"
  end
}
sepstr = result.split("0")
sepstr << ""
puts sepstr.max.length


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

int main() {
    auto transposemat = [](const auto& a) -> vector<vector<unsigned long>>{
        auto N = a[0].size(), M = a.size();
        vector<vector<unsigned long>> ret(N, vector<unsigned long>(M));
        for(unsigned long i = 0; i != N; ++i)
            for(unsigned long j = 0; j != M; ++j)
                ret[i][j] = a[j][i];
        return ret;
    };
    auto multimat = [&transposemat](const auto& a, const auto& b) -> vector<vector<unsigned long>>{
        auto bt = transposemat(b);
        auto N = a.size(), M = b[0].size();
        vector<vector<unsigned long>> ret(N, vector<unsigned long>(M));
        for(unsigned long i = 0; i != N; ++i)
            for(unsigned long j = 0; j != M; ++j)
                ret[i][j] = inner_product(a[i].begin(), a[i].end(), bt[j].begin(), 0UL) % 1000000007;
        return ret;
    };
    auto modpowmat = [&multimat](const auto& _a, size_t n) -> vector<vector<unsigned long>>{
        auto N = _a.size();
        vector<vector<unsigned long>> a(_a), ret(N, vector<unsigned long>(N, 0));
        for(unsigned long i = 0; i < N; ++i)ret[i][i] = 1;
        while(n){
            if(n & 1)ret = multimat(ret, a);
            a = multimat(a, a);
            n >>= 1;
        }
        return ret;
    };
    auto modpow = [](unsigned long a, size_t n){
        unsigned long ret{1};
        while(n){
            if(n & 1){
                ret *= a;
                ret %= 1000000007;
            }
            a *= a;
            a %= 1000000007;
            n >>= 1;
        }
        return ret;
    };
    vector<vector<unsigned long>> a({{2,0,1,1,0,0,0,0,0,0},{0,4,0,0,0,0,0,0,0,0},{0,0,1,0,1,1,1,0,0,0},{2,0,0,1,0,0,0,1,0,0},{2,1,1,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,1,1,1},{2,0,1,0,0,0,0,0,1,0},{0,1,1,0,0,1,1,0,0,0},{1,1,0,1,0,0,0,1,0,0},{1,1,1,1,0,0,0,0,0,0}});

    unsigned long N;
    cin >> N;

    cout << (modpow(4, N) + 1000000007 - modpowmat(a, N)[0][1]) % 1000000007 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;

    ll num_w = 0, num_r = 0;
    for(ll i=0;i<n;++i){
        if(s[i] == 'W'){
            num_w++;
        }else{
            num_r++;
        }
    }
    

    ll ans = 0;
    ll time = min(num_w, num_r);
    for(ll i=0;i<num_r;++i){
        if(s[i] == 'W'){
            ans++;
        }
    }    
    ans = min(ans, time);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5220
n,k=map(int,input().split())
X=list(map(int,input().split()))

minti=abs(X[0])*2+abs(X[n-1])*2

for i in range(n-k+1):
    le=X[i]
    ri=X[i+k-1]
    if (le>=0 and ri>=0) or (le<=0 and ri<=0):
        ti=max(abs(le),abs(ri))
    else:
        ti=min(abs(le),abs(ri))*2+max(abs(le),abs(ri))
    minti=min(ti,minti)

print(minti)


Measured memory_bytes: 14252
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct sb
{
	int x,y;
}f[10005];
int main()
{
	int n,i,j,min=10000000,max=-10000000,maxi,mini,a[105],o=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>max)
		max=a[i],maxi=i;
		if(a[i]<min)
		min=a[i],mini=i;
	}
	if(fabs(max)>fabs(min))
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]<0)
			{
				a[i]+=max;
				f[o].x=maxi;
				f[o].y=i;
				o++;
			}
		}
		for(i=1;i<n;i++)
		{
			if(a[i]>a[i+1])
			{
				a[i+1]+=a[i];
				f[o].x=i;
				f[o].y=i+1;
				o++;
			}
		}
	}
	else
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]>0)
			{
				a[i]+=min;
				f[o].x=mini;
				f[o].y=i;
				o++;
			}
		}
		for(i=n;i>1;i--)
		{
			if(a[i-1]>a[i])
			{
				a[i-1]+=a[i];
				f[o].x=i;
				f[o].y=i-1;
				o++;
			}
		}
	}
	printf("%d\n",o);
	for(i=0;i<o;i++)
	printf("%d %d\n",f[i].x,f[i].y);
}

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

int main()
{

ll x;
cin>>x;


ll ans=0;
ll balance =100;
while(balance<x)
{
    ans++;
    balance+=(ll)balance/100;
}
cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628