akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    int n;
    cin >> n;
    int a[200000];
    for(int i=0;i<n;i++)cin >> a[i];

    int maxima = 0;
    int secondory = 0;

    for(int i=0;i<n;i++){
        if(maxima < a[i]){
          secondory = maxima;
          maxima = a[i];
        }
        else if(maxima == a[i]){
          secondory = maxima;
        }
        else if(secondory < a[i]){
          secondory = a[i];
        }
    }

    for(int i=0;i<n;i++){
      if(a[i] == maxima){
        cout << secondory << endl;
      }
      else{
        cout << maxima << endl;
      }
    }
    return 0;
}


Measured memory_bytes: 2432
#include<stdio.h>
int main(){
  int n,i,j,b;
  int a[4][14];
  char s;
  for(i=0;i<=13;i++){
    a[0][i]=0;
    a[1][i]=0;
    a[2][i]=0;
    a[3][i]=0;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&s,&b);
    if(s=='S'){
      a[0][b]=1;
    }else if(s=='H'){
      a[1][b]=1;
    }else if(s=='C'){
      a[2][b]=1;
    }else if(s=='D'){
      a[3][b]=1;
    }
  }
  for(i=0;i<4;i++){
    for(j=1;j<=13;j++){
      if(a[i][j]!=1){
    if(i==0){
      s='S';
    }else if(i==1){
      s='H';
    }else if(i==2){
      s='C';
    }else if(i==3){
      s='D';
    }
    printf("%c %d\n",s,j);
      }
    }
  }
  return (0);
}

Measured memory_bytes: 1808
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    double n;
    int a;
    double b;
    boolean d8, d4;
    int[] i, d;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextDouble();
	    if(n<0) break;
	    
	    d8 = true; d4 = true;
	    i = new int[8];
	    d = new int[4];
	    a = (int)n/1;
	    b = n-a;
	    solveI();
	    solveD();

	    if(d8&&d4)
		show();
	    else System.out.println("NA");
	}
    }

    void solveI(){
	if(a > 255){
	    d8 = false;
	    return;
	}
	int s=128;
	for(int k=0; k<i.length; k++){
	    if(a>=s){
		i[k] = 1;
		a -= s;
	    }
	    s /= 2;
	}
	if(a!=0) d8 = false;
    }

    void solveD(){
	double s=0.5;
	for(int k=0; k<d.length; k++){
	    if(b>=s){
		d[k] = 1;
		b -= s;
	    }
	    s /= 2;
	}
	if(b!=0) d8 = false;
    }

    void show(){
	for(int k=0; k<i.length; k++)
	    System.out.print(i[k]);
	System.out.print(".");
	for(int k=0; k<d.length; k++)
	    System.out.print(d[k]);
	System.out.println();
    }
}

Measured memory_bytes: 28024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  long K;
  cin >> S >> K;
  for(int i=0;i<K;i++){
    if(S.at(i)!='1'){
      cout << S.at(i) << endl;
      return 0;}
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "2", "11 1 U", "11 47 D" ].solve == "230" );
	assert( [ "4", "20 30 U", "30 20 R", "20 10 D", "10 20 L" ].solve == "SAFE" );
	assert( [ "8", "168 224 U", "130 175 R", "111 198 D", "121 188 L", "201 116 U", "112 121 R", "145 239 D", "185 107 L" ].solve == "100" );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xyus = new Tuple!( long, long, dchar )[ n ];
	foreach( ref xyu; xyus )
	{
		input.popFront;
		auto as = input.front.split;
		xyu = tuple( as[ 0 ].to!( long ), as[ 1 ].to!( long ), as[ 2 ].to!( dchar ) );
	}
	
	// 衝突判定用基準値を作成
	long[][ long ] udss;
	long[][ long ] duss;
	long[][ long ] rlss;
	long[][ long ] lrss;
	long[][ long ] urss;
	long[][ long ] ulss;
	long[][ long ] drss;
	long[][ long ] dlss;
	long[][ long ] russ;
	long[][ long ] rdss;
	long[][ long ] ldss;
	long[][ long ] luss;
	foreach( i, xyu; xyus )
	{
		auto a = xyu[ 1 ] + xyu[ 0 ];
		auto b = xyu[ 1 ] - xyu[ 0 ];
		final switch( xyu[ 2 ] )
		{
			case 'U':
				udss[ xyu[ 0 ] ] ~= xyu[ 1 ];
				urss[ a ] ~= xyu[ 0 ];
				ulss[ b ] ~= xyu[ 0 ];
				break;
			
			case 'D':
				duss[ xyu[ 0 ] ] ~= xyu[ 1 ];
				drss[ b ] ~= xyu[ 0 ];
				dlss[ a ] ~= xyu[ 0 ];
				break;
			
			case 'R':
				rlss[ xyu[ 1 ] ] ~= xyu[ 0 ];
				russ[ a ] ~= xyu[ 0 ];
				rdss[ b ] ~= xyu[ 0 ];
				break;
			
			case 'L':
				lrss[ xyu[ 1 ] ] ~= xyu[ 0 ];
				luss[ b ] ~= xyu[ 0 ];
				ldss[ a ] ~= xyu[ 0 ];
				break;
		}
	}
	
	// 一番早い衝突の時間を計算
	auto a = solve2( udss, duss ) / 2;
	auto b = solve2( rlss, lrss ) / 2;
	auto c = solve2( russ, urss );
	auto d = solve2( ulss, luss );
	auto e = solve2( rdss, drss );
	auto f = solve2( dlss, ldss );
	auto ans = min( a, b, c, d, e, f );
	return ( ans == long.max / 2 ) ? "SAFE" : ans.to!( string );
}

auto solve2( long[][ long ] abss, long[][ long ] bass )
{
	auto t = long.max;
	foreach( k, ref abs; abss )
	{
		if( k !in bass ) continue;
		auto bas = bass[ k ];
		abs.sort;
		bas.sort;
		LOOP: for( auto i = 0L, j = 0L; i < abs.length; i++ )
		{
			while( bas[ j ] < abs[ i ] )
			{
				j++;
				if( bas.length <= j ) break LOOP;
			}
			auto tt = ( bas[ j ] - abs[ i ] ) * 10;
			t = min( t, tt );
		}
	}
	return t;
}


Measured memory_bytes: 69188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(isr);
        String str[];
        int n, m, a, b;
        int cost[][] = new int[100][100];
        int time[][] = new int[100][100];
         
        while(true){
            str = reader.readLine().split(" ");
            n = Integer.valueOf(str[0]);
            m = Integer.valueOf(str[1]);
            if(n == 0 && m == 0) break;
            for(int i = 0; i < m; i++){
                for(int j = 0; j < m; j++){
                    cost[i][j] = time[i][j] = 1000 * 1000;
                }
            }
            for(int i = 0; i < n; i++){
                str = reader.readLine().split(" ");
                a = Integer.valueOf(str[0]) - 1;
                b = Integer.valueOf(str[1]) - 1;
                cost[a][b] = cost[b][a] = Integer.valueOf(str[2]);
                time[a][b] = time[b][a] = Integer.valueOf(str[3]);
            }
            for(int i = 0; i < m; i++){
                for(int j = 0; j < m; j++){
                    for(int k = 0; k < m; k++){
                        cost[j][k] = Math.min(cost[j][k], cost[j][i] + cost[i][k]);
                        time[j][k] = Math.min(time[j][k], time[j][i] + time[i][k]);
                    }
                }
            }
            n = Integer.valueOf(reader.readLine());
            for(int i = 0; i < n; i++){
                str = reader.readLine().split(" ");
                a = Integer.valueOf(str[0]) - 1;
                b = Integer.valueOf(str[1]) - 1;
                switch(Integer.valueOf(str[2])){
                case 0 : System.out.println(cost[b][a]); break;
                case 1 : System.out.println(time[b][a]);
                }
            }
        }
        reader.close();
    }
}


Measured memory_bytes: 64644
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;

const uint32_t M = 998244353;

struct modint {
	uint32_t v;
	modint(int x) : v(x % M) {}
	modint pow(uint32_t p) {
		modint x = 1, a = v;
		while (p) {
			if (p & 1) {
				x = x * a;
			}
			a = a * a;
			p >>= 1;
		}
		return x;
	}
	modint() : modint(0) {}
	modint operator+(modint x) { uint32_t s = v + x.v; return s > M ? s - M : s; }
	modint operator-() { return v ? M - v : 0; }
	modint operator*(modint x) { return (uint64_t)v * x.v % M; }
	modint operator/(modint x) { return operator*(x.pow(M - 2)); }
};

const int N = 3e5 + 64;
modint fa[N];

modint cnk(int n, int k) {
	assert(0 <= k && k <= n && n < N);
	return fa[n] / (fa[k] * fa[n - k]);
}

int main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	fa[0] = 1;
	for (int i = 1; i < N; ++i) {
		fa[i] = fa[i - 1] * i;
	}
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	modint answer = 0;
	for (int x = 0; x <= n && a * x <= k; ++x) {
		ll l = (k - a * x);
		if (l % b) {
			continue;
		}
		int y = l / b;
		if (y < 0 || y > n) {
			continue;
		}
		answer = answer + cnk(n, x) * cnk(n, y);
	}
	cout << answer.v << "\n";
	return 0;
}


Measured memory_bytes: 1408
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 

signed main()
{
 
    fast;
    string s ; cin >> s ;
    if(s=="RRR") cout<<3<<endl;
    else if(s=="RRS" || s=="SRR" ) cout<<2<<endl;
    else if(s=="SSS") cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}

/* Pooja Yadav */

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

int r0,w0,c,r;
double conc;
int x;

int main(){
  while(1){
    cin >> r0 >> w0 >> c >> r;
    if(r0+w0+c+r==0)break;
    x = 0;
    while(1){
      //cout << (double)(r0+x*r)/c << (double)(r0+x*r)/c-w0 << endl;
      if((double)(r0+x*r)/c-w0>=0)break;
      x++;
    }
    cout << x << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    vi data(0);
    int i = 0;
    while(true) {
        int a;
        cin >> a;
        if(a == 0) break;
        data.push_back(a);
        i++;
    }
    for(int j = 0; j < i; j++) cout << "Case " << j + 1 << ": " << data[j] << endl;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
const int mod = 1e9 + 7;
ll power(ll a, ll b)
{
    ll ans = 1 % mod;
    while (b > 0)
    {
        if (b & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    ll mx = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        //mx = max(mx, a[i]);
    }
    ll ans = 0;
    for (int bit = 0; bit < 60; bit++)
    {
        ll cnt0 = 0, cnt1 = 0;
        for (int i = 1; i <= n; i++)
        {
            ll cur = a[i];
            if ((cur >> bit) & 1)
            {
                cnt1++;
            }
            else
            {
                cnt0++;
            }
        }
        ans = (ans + cnt0 % mod * cnt1 % mod * ((1ll << bit) % mod) % mod) % mod;
    }
    cout << ans << "\n";
    //cout << len << "\n";
    return 0;
}

Measured memory_bytes: 5508
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m,k;cin>>m>>k;
  int sum=0;
  rep(i,1<<m)sum^=i;
  if(k==0)
  {
    rep(i,1<<m)
    {
      cout<<i<<" ";
      cout<<i<<" ";
    }
  }
  else if(k>=(1<<m))
  {
    cout<<-1;
  }
  else if(k==(sum^k))
  {
    rep(i,1<<m)
    {
      if(k!=i)cout<<i<<" ";
    }
    cout<<k<<" ";
    rep(j,1<<m)
    {
      int i=(1<<m)-1-j;
      if(k!=i)cout<<i<<" ";
    }
    cout<<k<<" ";

  }
  else cout<<-1;
  cout<<endl;


  return 0;

}


Measured memory_bytes: 1792
N, K = map(int, input().split())
*D, = map(int, input().split())
D = set(D)
L = {1,2,3,4,5,6,7,8,9,0} - D
for i in range(N, N*10):
    tmp = i
    num = set()
    while i > 0:
        num.add(i%10)
        i = i // 10
    if num.isdisjoint(D):
        print(tmp)
        exit()


Measured memory_bytes: 3060
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
// #include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 7;

int cnt[MAX];
int main(){
#ifdef DEBUG
    freopen("in","r", stdin);
#endif
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    if(x > y) swap(x, y);
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            int ans;
            if(i <=x and j >= y){
                // ans = j - i - (y-x) + 1; 
                ans = j-y+x-i + 1;
            }
            else if(i <= x and j >= x and j < y){
                ans = x-i+min(j-x, y-j+1);
            }
            else if(i <= x and j <= x){
                ans = j-i;
            }
            else if(i >= x and i <= y and j >= y){
                ans = min(i-x+1, y-i) + j - y;
            }
            else if(i >= x and i <= y and j <= y){
                ans = min(j-i, i-x+y-j+1);
            }
            else if(i >= y and j >= y){
                ans = j-i;
            }
            // printf("%d %d %d\n",i, j, ans);
            cnt[ans]++;
        }
    }
    for(int i = 1; i < n; i++){
        printf("%d\n", cnt[i]);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long n;
    cin >> n;
    vector<tuple<long,long,long>> c;
    rep(i,n){
        long a,b;
        cin >> a >> b;
        c.push_back(make_tuple(a+b,a,b));
    } 
    sort(c.begin(),c.end());
  	reverse(c.begin(),c.end());
    long t =0,a=0,flag = 1;
    for(auto i:c){
        long x,y,z;
        tie(x,y,z) = i;
        if(flag%2) t += y; 
        else a += z;
        flag++;
    }
    cout << t-a << endl;
}


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef pair <int, pii> piii;
#define fr first
#define sc second
#define pb push_back
#define ppb pop_back()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define mpr make_pair
int n, x, cnt, a[1001];
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> x;
	for(int i = 1;i <= n; ++ i){
		cin >> a[i];
	}	
	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n && a[i] <= x; ++ i){
		++cnt;
		x -= a[i];
	}
	cout << cnt - (cnt == n && x);
	return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappush, heappop, heapify

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    N = in_n()
    x = [0] * N
    y = [0] * N

    for i in range(N):
        x[i], y[i] = in_nn()

    sort_ind_x = sorted(range(N), key=lambda i: x[i])
    sort_ind_y = sorted(range(N), key=lambda i: y[i])

    cost = [[] for _ in range(N)]
    for i in range(N - 1):
        j1, j2 = sort_ind_x[i], sort_ind_x[i + 1]
        c = abs(x[j1] - x[j2])
        cost[j1].append((c, j2))
        cost[j2].append((c, j1))

        j1, j2 = sort_ind_y[i], sort_ind_y[i + 1]
        c = abs(y[j1] - y[j2])
        cost[j1].append((c, j2))
        cost[j2].append((c, j1))

    used = [0] * N
    used[0] = 1
    que = [(c, w) for c, w in cost[0]]
    heapify(que)

    ans = 0
    while que:
        cv, v = heappop(que)
        if used[v]:
            continue
        used[v] = 1
        ans += cv
        for c, w in cost[v]:
            if used[w]:
                continue
            heappush(que, (c, w))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 118644
#include <stdio.h>
#include <ctype.h>


int main (int argc, char* argv[]) {
  int n, k;
  scanf("%d %d", &n, &k);

  char s[n];
  scanf("%s", s);

  s[k-1] = tolower(s[k-1]);

  printf("%s\n", s);

  return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,A,B;
  cin>>N>>A>>B;
  cout<<min(N*A,B)<<endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1e9 + 7;
int main() {
  string a, b;
  cin >> a >> b;
  cout << (a[0] == b[0]) + (a[1] == b[1]) + (a[2] == b[2]);
}

Measured memory_bytes: 256
//author:happylkx
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string.h>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
int c[500], s[500], f[500];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N-1;i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int j = 0;j < N-1;j++) {
		int t = 0;
		for (int i = j;i <= N - 2;i++) {
			if (t < s[i]) {
				t = s[i] + c[i];
				continue;
			}
			if (t%f[i] != 0)t = ((t/f[i]) + 1)*f[i];
				t += c[i];
		}
		cout << t << endl;
	}
	cout << 0;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
x.sort(key = lambda x: x[1])
total = 0
flag = 0
for i in range(n):
    if x[i][1]-total >= x[i][0]:
        total += x[i][0]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 41180
package main

import (
  "fmt"
)

func min(a, b int) int {
  if a < b {
    return a
  }
  return b
}

func main() {
  var n int
  var s string
  fmt.Scan(&n, &s)

  b := make([]int, n + 1)
  w := make([]int, n + 1)
  for i := 0; i < n; i++ {
    w[i + 1] = w[i]
    b[i + 1] = b[i]
    if s[i] == '.' {
      w[i + 1]++
    } else {
      b[i + 1]++
    }
  }
  ans := n
  for i := 0; i <= n; i++ {
    ans = min(ans, b[i] + (w[n] - w[i]))
  }
  fmt.Println(ans)
}


Measured memory_bytes: 5248
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
long long A, B, C;
int main() {
	cin >> A >> B >> C;
	bool f = false;
	for (int i = 0; i <= 100000; i++) {
		if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
			cout << i << endl; f = true;
			break;
		}
		long long p = (B + C) / 2, q = (C + A) / 2, r = (A + B) / 2;
		A = p; B = q; C = r;
	}
	if (!f) cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t=1;
	// cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll> a(n), suff(n);
		for(int i = 0; i < n; i++) cin>>a[i];
		suff[n-1]=a[n-1];
		ll mod = 1000000007, ans = 0;

		for(int i = n-2; i >=0; i--) suff[i]=(suff[i+1]%mod+a[i]%mod)%mod;
		// for(auto i:suff) cout<<i<<" ";
		// 	cout<<endl;
		for(int i = 0; i < n-1; i++)
		{
			ans=(ans%mod+(a[i]%mod*suff[i+1]%mod)%mod)%mod;
		}
		cout<<ans%mod<<endl;
	}
	return 0;
}

Measured memory_bytes: 6384
import math
a,b=map(int,input().split())
gcd=math.gcd(a,b)

def prime_factorization(n):
  i=2
  prime=[]
  while i*i<=n and n>1:
    if n%i:
      i+=1
    else:
      n//=i
      prime.append(i)
      while n%i==0:
        n//=i
  if n>1:
    prime.append(n)
  return prime

print(len(prime_factorization(gcd))+1)
#print(prime_factorization(gcd))

Measured memory_bytes: 9084
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
using namespace std;
const int64_t INF=10000000000000000;

int main(){
	string s;
	cin>>s;
	if(s=="AAA"||s=="BBB"){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}


}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
  int n;scanf("%d",&n);
  vector<ll> a(n);
  for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  vector<ll> score(2,0);
  for (int i = 0; i < n; ++i)
  {
    score[i%2] += a[i];
  }
  printf("%d\n", score[0] - score[1]);
}

Measured memory_bytes: 256
n=int(input())
a=[]
mx=0
sec=0
for i in range(0,n):
  a.append(int(input()))
  if a[i]>sec:
    if a[i]>mx:
      sec=mx
      mx=a[i]
    else:
      sec=a[i]

for x in a:
  if x==mx:
    print(sec)
  else:
    print(mx)



Measured memory_bytes: 12532
#include <iostream>
#include <vector>

int main() {
	int N, M, C;
	std::cin >> N >> M >> C;

	std::vector<int> B(M);
	for(int &n : B) {
		std::cin >> n;
	}

	int result = 0;
	for(int i = 0; i < N; i++) {
		std::vector<int> A(M);
		for(int &n : A) {
			std::cin >> n;
		}

		int value = C;
		for(int j = 0; j < M; j++) {
			value += A.at(j) * B.at(j);
		}

		if(value > 0) {
			result++;
		}
	}

	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections

def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

#X = str(raw_input()).split()
AB = str(raw_input()).split()
A = int(AB[0])
B = int(AB[1])

ans = A * B / gcd(A,B)

print(ans);


Measured memory_bytes: 17796
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    mni = (N - 1) // 2
    mxi = mni if N & 1 else mni + 1
    AB.sort(key=lambda x: x[0])
    mmn = (AB[mni][0] + AB[mxi][0]) / 2
    AB.sort(key=lambda x: x[1])
    mmx = (AB[mni][1] + AB[mxi][1]) / 2
    t = 1 if N & 1 else 2
    print(int((mmx - mmn) * t) + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 107760
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    if (A == B && B == C && C == A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

int main()
{
	int N, K, time = 0;
	cin >> N >> K;
	vector<int> X(N);
	int i;
	rep(i, N) cin >> X[i];
	int min_ = inf;

	for (int i = 0; i <= N - K; i++)
	{
		int ans = abs(X[i] - X[i + K - 1]) + min(abs(X[i]), abs(X[i + K - 1]));
		min_ = min(min_, ans);
	}

	cout << min_ << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std; 
string a;
int main(void)
{
	cin >> a;
	if(a == "SAT")
		printf("1\n");
	else if(a == "SUN")
		printf("7\n");
	else if(a == "MON")
		printf("6\n");
	else if(a == "TUE")
		printf("5\n");
	else if(a == "WED")
		printf("4\n");
	else if(a == "THU")
		printf("3\n");
	else if(a == "FRI")
		printf("2\n");
	return 0;
}

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

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int H,N;
#define MAXN  100001
int A[MAXN];
int main(){
    cin >> H >> N;
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    if(H <= sum)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 640
s = str(input())
n = int(input())

for i in range(n):
  cmd = list(str(input()).split())
  
  if cmd[0] == 'print':
    print(s[int(cmd[1]):int(cmd[2])+1])
  elif cmd[0] == 'reverse':
    temp = s[int(cmd[1]):int(cmd[2])+1]
    s = s[:int(cmd[1])] + temp[::-1] + s[int(cmd[2])+1:] 
  else: #replace
    s = s[:int(cmd[1])] + cmd[3] + s[int(cmd[2])+1:] 


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    string model = "CODEFESTIVAL2016";
    int ans = 0;
    rep(i,s.size()) if (s[i] != model[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3572
// Boy_of_KutBilim
#include <iostream>
#include <algorithm>
using namespace std;

#define endl '\n'
#define ll long long
#define ull unsigned ll

typedef string BigInt;

int a[3 + 100000];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	
	ll n, x;
	cin >> n;
	while(n--){
		cin >> x;
		a[x] ++;
		a[x + 1] ++;
		a[x + 2]++;
	}
	cout << *max_element(a, a + 100003);
	return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int Ha[N+1], Aa[M+1], Ba[M+1];
    vector<int> R[N+1];

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

    for(int i=1; i<=M; i++)
    {
        cin >> Aa[i] >> Ba[i];
    }

    for(int i=1; i<=M; i++)
    {
        R[Aa[i]].push_back(Ba[i]);
        R[Ba[i]].push_back(Aa[i]);
    }

    int G = 0;
    for(int i=1; i<=N; i++)
    {
        G = G + 1;
        for(int j=0; j<R[i].size(); j++)
        {
            if(Ha[i] <= Ha[R[i][j]])
            {
                G = G - 1;
                break;
            }
        }

    }

    cout << G;



    return 0;

}



Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    ll N; cin >> N;
    vector<ll> a(N+1, 0);
    ll sum = 0;
    repr(i, 1, N+1) cin >> a[i], sum += a[i];
    vector<ll> cum(N+1, 0);
    repr(i, 1, N+1) cum[i] = cum[i-1] + a[i];

    ll ans = 1LL<<60;
    repr(i, 1, N){
        ll val = abs(cum[N] - 2*cum[i]);
        chmin(ans, val);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int N, L;
VI a, dp;
int solve(int now) {
	if (dp[now] != -1) return dp[now];
	if (a[now] == -1) return 0;

	int tmp = L - a[now];
	if (a[now - 1] < a[now] && a[now] > a[now + 1]) {
		return dp[now] = tmp;
	}

	int ret = 0;
	if (a[now - 1] > a[now]) {
		ret = solve(now - 1);
	}
	if (a[now + 1] > a[now]) {
		ret = max(ret, solve(now + 1));
	}

	return dp[now] = tmp + ret;
}

int main() {
	cin >> N >> L;
	a = dp= VI(N + 2, -1);
	rep(i, N) cin >> a[i + 1];

	int ans = 0;
	for(int i=1; i<=N; i++){
		if (dp[i] == -1) {
			dp[i] = solve(i);
		}
		ans = max(ans, dp[i]);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 5508
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

vector<vector<long long> > g;
vector<char> used;

void dfs(long long v){
  used[v] = true;
  for(long long i : g[v])
     if(!used[i]) dfs(i);
}


int main(){
  long long n, m, x, y, z;
  cin >> n >> m;
  g.resize(n + 1);
  used.assign(n + 1, false);
  vector<long long> a(n + 1, 0);
  for(int i = 0; i < m; ++i){
    cin >> x >> y >> z;
    g[x].push_back(y);
    g[y].push_back(x);
    a[x] = a[y] = 1;
  }
  long long ans = 0;
  for(int i = 1; i <= n; ++i){
    if(a[i] && !used[i]){
      ans++;
      dfs(i);
    }
    if(!a[i]) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 9728
#![allow(unused_imports)]

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

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        s: String,
    }
    let n = s.len();
    let mut blue = 0;
    for c in s.chars() {
        if c == '1' { blue += 1; }
    }
    println!("{}", 2 * min(n - blue, blue));
}


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

int main() {
    string S; cin >> S;
    vector<string> D(7);
    D =  {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    int ans;
    for(int i = 7; i > 0; i--) {
        if(S == D.at(7-i)) 
            ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#AC
n,x = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
d = 0
count = 1
for i in 0..(n-1)
  d += arr[i]
  if d > x
    break
  end
  count += 1
end
puts count

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

int main() {
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]=='s'){
        s+="es";
    }
    else {
        s+='s';
    }
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N, ll H, vector<ll> A, vector<ll> B){
    ll ans = 0;
    sort(RALL(A)), sort(RALL(B));
    ll mx = A[0];

    rep(i,N) if(B[i] >= mx) {
        H -= B[i];
        ans++;
        if(H <= 0) return ans;
    }
    
    ans += devc(H,mx);

    return ans;
}

int main(){
    ll N,H; cin >> N >> H;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];
    pr(solve(N,H,A,B));
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
#define Android ios::sync_with_stdio(false), cin.tie(NULL)
#define F(i, n) for(int i=0, _iter_max=(n); i<_iter_max; i++)
#define range(i, l, r) for(int i=(l), _iter_max=(r); i<_iter_max; i++)
#define debug(s, r) std::cerr << #s << ": " << (s) << (r==0?' ':'\n')
#define pii pair<int, int>  

using namespace std;

void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }

const int maxn = 2e5 + 1000;
unsigned ll n, a, b, ans1=0, ans2=0;
void solve(){
    cin >> n >> a >> b;
    if(a > b) swap(a, b);
    if((b - a) % 2 == 0){
        cout << (b - a) / 2 << endl;
    }else{
        {
            unsigned ll ta = a, tb = b;
            ans1 += ta, tb -= ta;
            ans1 += tb / 2;
        }
        {
            unsigned ll ta = a, tb = b;
            ans2 += n-tb+1, ta += n-tb+1, tb=n;
            ans2 += (tb - ta) / 2;
        }
        cout << min(ans1, ans2) << endl;
    }
}

signed main(){
    Android;
    solve();
}


Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
string l[5];

string doit(string x,int i){
	string y;
	if(i == 0){
		if(x<l[0]){
			y = x;
			x = l[0];
			l[0] = y;
			return x;
		}
		else return x;
	}
	if(x<l[i]){
		y = l[i];
		l[i] = doit(x,i-1);
		return y;	
	}
	else return x;
}
int main(){
	string s;
	cin>>s;
	int n,k;
	cin>>k;
	n = s.length();
	for(int i=0;i<5;i++)
		l[i] = "zzzzz";
	string x;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k&&i+j<=n;j++){
			x = s.substr(i,j);
			if(l[0]==x||l[1]==x||l[2]==x||l[3]==x||l[4]==x)
				continue;
			if(x==doit(x,4))
				break;
		}
	}
	cout<<l[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	 
	scanf("%d %d %d", &a, &b, &c);

	if (a == b && b != c || b == c && c != a || c == a && a != b)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	//ll M=pow(10,9)+7;
	int t=1;
	while(t)
	{
		int n; cin>>n;
		if(n>=400&&n<=599) cout<<"8\n";
		if(n>=600&&n<=799) cout<<"7\n";
		if(n>=800&&n<=999) cout<<"6\n";
		if(n>=1000&&n<=1199) cout<<"5\n";
		if(n>=1200&&n<=1399) cout<<"4\n";
		if(n>=1400&&n<=1599) cout<<"3\n";
		if(n>=1600&&n<=1799) cout<<"2\n";
		if(n>=1800&&n<=1999) cout<<"1\n";
		t--;
	}
	return 0;
}

Measured memory_bytes: 3636
H, N = map(int, input().split())
A=[]
B=[]
for i in range(N):
	a,b = map(int, input().split())
	A.append(a)
	B.append(b)
#dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp=[[float("inf")]*(H+1) for _ in range(N+1)]

for i in range(N):
	for h in range(H+1):
		if A[i]>=h:
			dp[i+1][h] = min(dp[i][h], B[i])
		else:
			dp[i+1][h] = min(dp[i][h], dp[i+1][h-A[i]]+B[i])
print(dp[-1][-1])

Measured memory_bytes: 229068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
int pre[N];
int main()
{
       int n;
       cin>>n;
       int a[n];
       arrin(a,n);
       sort(a,a+n);
       memset(pre,0,sizeof pre);
       fri(i,0,n){
              pre[a[i]] = i+1;
       }
       fri(i,1,N){
              if(pre[i]==0){
                     pre[i] = pre[i-1];
              }
       }
       int sum = 0;
       fri(i,1,N){
              if(pre[i-1] == n/2){
                     sum++;
              }
       }
       cout<<sum<<endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

std::string to_binString(unsigned int val)
{
  if( !val )
    return std::string("0");
  std::string str;
  while( val != 0 ) {
    if( (val & 1) == 0 )
      str.insert(str.begin(), '0');
    else
      str.insert(str.begin(), '1');
    val >>= 1;
  }
  return str;
}

vector<ll> v;
set<ll> s;
set<ll> bits;
void dfs(ll bit, ll t){
  if(find(all(bits),bit) != bits.end() || t < 0){
    return;
  }
  bits.insert(bit);
  if(t == 0){
    vector<ll> lis;
    rep(i,v.size()){
      if(bit & (1 << i)){
        lis.push_back(v[i]);
      }
    }
    ll cnt = 0;
    do{
      ll num = 0;
      rep(i,lis.size()){
//         cout << lis[i] << " ";
        if(lis[i] < 10){
          num = num * 10 + lis[i];
        }
        else{
          num = num * 100 + lis[i];
        }
      }
      if(s.insert(num).se){
      }
      ++cnt;
    }while(next_permutation(all(lis)));
//     debug(cnt);
  }
  else{
    REP(i,0,v.size()){
      if(!(bit & (1 << i))){
        dfs(bit | (1 << i),t-1);
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  while(cin >> n >> k && n && k){
    v.resize(n);
    s.clear();
    bits.clear();
    rep(i,n){
      cin >> v[i];
    }
    sort(all(v));
    rep(i,n){
      dfs((1 << i),k-1);
    }
    cout << s.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3172