akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define N 2000000
#define INFTY 5000000

void maxHeap(int);
int heapExtractMax(void);
void heapIncreaseKey(int,int);
void insert(int);

int H = 0;
int order[N+1];

int main(){
    char str[8];
    int key;

    while(1){
        scanf("%s",str);
        if(strcmp(str,"end") == 0){
            break;
        }
        if(strcmp(str,"insert") == 0){
            scanf("%d",&key);
            insert(key);
        }
        else{
            printf("%d\n",heapExtractMax());
        }
    }

    return 0;
}

void maxHeap(int i){
    int l,r,largest,tmp;

    l = 2*i;
    r = 2*i+1;

    if(l <= H && order[l] > order[i]){
        largest = l;
    }
    else{
        largest = i;
    }
    if(r <= H && order[r] > order[largest]){
        largest = r;
    }

    if(largest != i){
        tmp = order[i];
        order[i] = order[largest];
        order[largest] = tmp;
        maxHeap(largest);
    }
}

int heapExtractMax(){
    int max;

    if(H<1) return -INFTY;
    max = order[1];
    order[1] = order[H];
    H--;
    maxHeap(1);
    return max;
}

void heapIncreaseKey(int i,int key){
    int tmp;

    if(key < order[i]){
        return;
    }
    order[i] = key;
    while(i > 1 && order[i/2] < order[i]){
        tmp = order[i];
        order[i] = order[i/2];
        order[i/2] = tmp;
        i = i/2;
    }
}

void insert(int key){
    H++;
    order[H] = -INFTY;
    heapIncreaseKey(H,key);
}


Measured memory_bytes: 5568
h,n = map(int,input().split())
spel = [list(map(int,input().split())) for i in range(n)]
dp = [float('inf')]*(h+1)
dp[0] = 0
for i in range(h):
  for damage,cost in spel:
    n_i = min(i+damage,h)
    dp[n_i] = min(dp[n_i],dp[i]+cost)
print(dp[h])

Measured memory_bytes: 74472
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> s(m, vector<int>());
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            x--;
            s[i].emplace_back(x);
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); ++bit) {
        vector<bool> on(n, false);
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)) on[i] = true;
        }
        bool ok = true;
        for (int i = 0; i < m; ++i) {
            int cnt = 0;
            for(auto &j : s[i]){
                if (on[j]) ++cnt;
            }
            if (cnt % 2 != p[i]){
                ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll,ll> pll;

int N;
vector<pll> V,ans;
ll child[100010];
ll dp[100010];
map<ll,ll> mp;
ll sum = 0;
bool flag;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        ll d;
        scanf("%lld",&d);
        V.push_back(mk(d,i + 1));
    }

    sort(V.begin(),V.end());

    for(int i = 0; i < V.size(); i++)mp[V[i].fi] = i + 1;
    for(int i = 0; i <= N; i++)child[i] = 1;

    for(int i = V.size() - 1; i > 0; i--)
    {
        ll val = V[i].fi - abs((N - child[i]) - child[i]);
        if(mp[val] != 0 && val < V[i].fi)
        {
            int tmp = mp[val];
            tmp--;
            ans.push_back(mk(V[i].se,V[tmp].se));
            sum += child[i];
            child[tmp] += child[i];
        }
        else flag = true;
    }

    if(V[0].fi != sum || flag)printf("-1\n");
    else
    {
        for(int i = 0; i < ans.size(); i++)
        {
            printf("%lld %lld\n",ans[i].fi,ans[i].se);
        }
    }
    return 0;
}


Measured memory_bytes: 13552
fun main (args : Array<String>) {
	val (p, q, r) = readLine()!!.split(" ").map(String::toInt)
	var P : Int = p.toInt()
	var Q : Int = q.toInt()
	var R : Int = r.toInt()
	var result : Int = 0
	if (P >= Q && P >= R) {
		result = Q + R
		println("${result}")
	} else if (Q >= P && Q >= R) {
		result = P + R
		println("${result}")
	} else if (R >= P && R >= Q) {
		result = P + Q
		println("${result}")
	}
}

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

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine()
                .Select(x => int.Parse(x.ToString()))
                .ToList();

            if (s.Count() == 1)
            {
                Console.WriteLine(0);
                return;
            }

            var p1 = new List<int>();
            var p2 = new List<int>();

            for (int i = 0; i < s.Count(); i++)
            {
                if (i % 2 == 0)
                {
                    p1.Add(0);
                    p2.Add(1);
                }
                else
                {
                    p1.Add(1);
                    p2.Add(0);
                }
            }

            var count1 = 0;
            var count2 = 0;

            for (int i = 0; i < s.Count(); i++)
            {
                count1 += s[i] ^ p1[i];
                count2 += s[i] ^ p2[i];
            }

            Console.WriteLine(Math.Min(count1,count2));
        }
    }
}

Measured memory_bytes: 16608
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i,j,n,c=0;
    string str;
    cin>>n;
    cin>>str;
    for(i=0;i<=str.length()-3;i++)
    {
        if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
            c++;
    }
    cout<<c;
return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type process struct {
	name string
	time int
}

type queue struct {
	a    []process
	n    int
	head int
	tail int
}

func (q *queue) init(n int) {
	q.a = make([]process, n+1)
	q.n = n + 1
}

func (q *queue) push(p process) {
	if q.full() {
		panic("overflow")
	}
	q.a[q.tail] = p
	q.tail = (q.tail + 1) % q.n
}

func (q *queue) pop() process {
	if q.empty() {
		panic("empty")
	}
	p := q.a[q.head]
	q.head = (q.head + 1) % q.n
	return p
}

func (q *queue) full() bool {
	return q.head == (q.tail+1)%q.n
}

func (q *queue) empty() bool {
	return q.head == q.tail
}

func main() {
	var n, q int
	fmt.Scan(&n, &q)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var qu queue
	qu.init(n)
	for i := 0; i < n; i++ {
		sc.Scan()
		name := sc.Text()
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		qu.push(process{name, t})
	}
	// simulate
	now := 0
	for !qu.empty() {
		p := qu.pop()
		if p.time <= q {
			fmt.Println(p.name, now+p.time)
			now += p.time
		} else {
			p.time -= q
			now += q
			qu.push(p)
		}
	}
}



Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

   int n, k;
   cin >> n >> k;
   vector<int> l(n);
   rep(i, 0, n) cin >> l[i];
   sort(l.begin(), l.end(), greater<int>());
   int sum = 0;
   rep(i, 0, k) sum += l[i];
   cout << sum << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 3000000;

int main() {
    VI d(N,1), primes;
    FOR(i,2,N-1){
        if (!d[i] || (i % 7 != 1 && i % 7 != 6)) continue;
        primes.push_back(i);
        int x = 2*i;
        while (x < N) {
            d[x] = 0;
            x += i;
        }
    }

    int n;
    while (cin >> n && n != 1) {
        cout << n << ":";
        REP(i,primes.size()){
            if (n % primes[i] == 0){
                cout << " " << primes[i];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 16376
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

typedef pair<int, int> P;
int bfs();
char stage[1010][1010];
int d[1010][1010];
int h,w;
int sx,sy,gx,gy;

int main(){
	int n;
	scanf("%d%d%d",&h,&w,&n);

	int x_d[10],y_d[10];

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			scanf(" %c",&stage[j][i]);
			if(stage[j][i] == 'S'){
				sx = j;
				sy = i;
			}
			if(48 < stage[j][i] && stage[j][i] < 58){
				x_d[stage[j][i]-48] = j;
				y_d[stage[j][i]-48] = i;
			}
		}
	}

	int ans = 0;
	gx = x_d[1];
	gy = y_d[1];
	for(int i = 0; i < n; i++){
		ans += bfs();
		sx = x_d[i+1],sy = y_d[i+1];
		gx = x_d[i+2],gy = y_d[i+2];
	}
	printf("%d\n",ans);
	return 0;
}

int bfs(){
	queue<P> Q;
	int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
	memset(d,-1,sizeof(d));
	Q.push(P(sx,sy));
	d[sx][sy] = 0;

	while(Q.size()){
		P p = Q.front();
		Q.pop();
		if(p.first == gx && p.second == gy){
			break;
		}

		for(int i = 0; i < 4; i++){
			int nx = p.first + dx[i] , ny = p.second + dy[i];

			if(0 <= nx && nx < w && 0 <= ny && ny < h){
				if(stage[nx][ny] != 'X' && d[nx][ny] == -1){
					Q.push(P(nx,ny));
					d[nx][ny] = d[p.first][p.second] + 1;
				}
			}
		}
	}
	return d[gx][gy];
}

Measured memory_bytes: 6024
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		
		String s=sc.next();
		String mon=s.substring(5,7);
		
		System.out.println(mon.equals("01")||mon.equals("02")||mon.equals("03")||mon.equals("04")?"Heisei":"TBD");
	}
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e6 + 10;
ll s[ 41 ];
int a[ N ];
int n , cnt;
bool vis[ N ];
map< int , int > t;
int check1( int x ){//二分寻找第一个比他大的2次幂 
   int l = 0 , r = 32;
   while( l < r ){
   	int mid = ( l + r )/2;
   	if( s[ mid ] > x ) r = mid  ;else
   	l = mid + 1 ;
   }
   return l;
}
int check2( int j , int x ){
	int l = 1 ,  r = j;
    while( l < r ){
     int mid = ( l + r )/2;
     if( a[ mid ] == x  ) return mid;
     if( a[ mid ] > x ) r = mid;else
	 l = mid + 1; 
	}
	if( a[ l ] != x ) return -1;
	return l ;
}
int main( ){
//	freopen("powers.in" , "r" , stdin );
//	freopen("powers.out" , "w" , stdout );
    memset( vis , false , sizeof( vis ) );
	scanf("%d" , &n );
	s[ 0 ] = 1;
	for( int i = 1 ; i <= 32 ; i ++ ) s[ i ] = s[ i - 1 ] * 2; 
	for( int i = 1 ; i <= n ; i ++ ){
	 scanf("%d" , &a[ i ] );
	 t[ a[ i ] ] ++;
    }
	sort( a + 1  , a + n + 1 );
    for( int i = n ; i >= 1 ; i -- ){
	 int q = check1( a[ i ] );
     int p = check2( i , s[ q ] - a[ i ] );
//     cout<<p<<" "<<i<<" "<<q<<" "<<a[ i ]<<" "<<t[ a[ i ] ]<<endl;
     if( t[ a[ p ] ] == 0 ) continue; 
     if( t[ a[ i ] ] == 0 ) continue;
	 if( p == -1 ) continue;
	 if( a[ p ] == a[ i ] ) if( t[ a[ p ] ] < 2 ) continue;
	 t[ a[ i ] ]--;
	 t[ a[ p ] ]--;
	 cnt ++;
	} 
	cout<<cnt;
} 

Measured memory_bytes: 13696
def we_like_agc(n)
  dp = Array.new(n + 1) do
    Array.new(4) do
      Array.new(4) do
        Array.new(4, 0)
      end
    end
  end

  dp[0][3][3][3] = 1

  0.upto(n - 1) do |len|
    0.upto(3) do |c1|
      0.upto(3) do |c2|
        0.upto(3) do |c3|
          next if dp[len][c1][c2][c3] == 0

          0.upto(3) do |a|
            next if a == 2 && c1 == 1 && c2 == 0
            next if a == 2 && c1 == 0 && c2 == 1
            next if a == 1 && c1 == 2 && c2 == 0
            next if a == 2 && c1 == 1 && c3 == 0
            next if a == 2 && c2 == 1 && c3 == 0

            dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3]
          end
        end
      end
    end
  end

  ans = 0
  0.upto(3) do |c1|
    0.upto(3) do |c2|
      0.upto(3) do |c3|
        ans += dp[n][c1][c2][c3]
      end
    end
  end

  ans % (10 ** 9 + 7)
end

p we_like_agc(gets.to_i)

Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>

#define fill(v,val) fill((v).begin(), (v).end(), (val))
#define fillt(tab, n, val) fill((t), (t) + (n) ,(val))
#define MAX 100005
#define INF 9999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()  
#define mp         make_pair
/**
*
* @Author Mehdi Maick
*/

using namespace std;
 map<int, int> num;
bool test(int a){
    while(a){
        if(num.count(a%10))
            return false;
        a /= 10;
    }
    return true;
}
int main(int argc , char* argv[]) {
    
    int n, k;
   
       cin >> n >> k;
    for (int i = 0; i < k; i++) {
        int a; cin >> a;
        num[a] = 1;
    }
    for(int N = n; true; N++){
        
        if(test(N))
        {
            cout << N << endl;
            return 0;
        }
        
    }
    return 0;
}



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

using namespace std;

typedef long long ll;

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

    vector<ll> An(N+2,0);
    for (int i=1;i<=N+1;i++) {
        cin >> An[i];
    }

    vector<ll> Bn(N+2,0);
    for (int i=1;i<=N;i++) {
        cin >> Bn[i];
    }

    ll sum=0;

    for (int i=1;i<=N+1;i++) {
        if (An[i] <= Bn[i-1]) {
            sum += An[i];
            int sub = Bn[i-1] - An[i];
            An[i] = 0;
            Bn[i-1] = sub;
        } else {
            sum += Bn[i-1];
            int sub = An[i] - Bn[i-1];
            An[i] = sub;
            Bn[i-1] = 0;
        }

        if (An[i] <= Bn[i]) {
            sum += An[i];
            int sub = Bn[i] - An[i];
            An[i] = 0;
            Bn[i] = sub;
        } else {
            sum += Bn[i];
            int sub = An[i] - Bn[i];
            An[i] = sub;
            Bn[i] = 0;
        }
    }

    cout << sum << endl;

    return 0;
}

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

int main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  if (C<D) {
    int hoge = 0;
    for (int i=A-1; i<D; i++){
      if (S[i]=='.') hoge = 0;
      else hoge++;
      if (hoge>1){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  } else {
    int hoge = 0;
    for (int i=A-1; i<C; i++){
      if (S[i]=='.') hoge = 0;
      else hoge++;
      if (hoge>1){
        cout << "No" << endl;
        return 0;
      }
    }
    int fuga = 0;
    for (int i=B-2; i<=D; i++){
      if (S[i] == '.') fuga++;
      else fuga = 0;
      if (fuga > 2){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sp <<" "<<
bool isprime(ll n){
    if (n <= 1)return false;ll g=sqrt(n);
    for (ll i = 2; i <= g; i++)if (n % i == 0)return false;
    return true;
}
ll MOD=LLONG_MAX;
ll power(ll base, ll exp)
{
    if(exp==1)return base;
    else{if(exp%2==0){ll base1=(pow(power(base, exp/2),2));return base1%MOD;}
        else{ll ans=(base*pow(power(base,(exp-1)/2),2));return ans%MOD;}}
}
ll temp,temp1,temp2;
int main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(k<=(x/d))
        cout<<x-(k*d);
    else
    {
        k-=x/d;
        if(k%2)
            cout<<abs((x%d)-d);
        else
        {
            cout<<x%d;
        }
        
    }
    

    return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int  N = 1e5 + 5;
vector<P> v[N] ;
int dis[N] ;
void dj( int st){
	set<P> s ;
	s.insert({0,st}) ;
	dis[st] = 0 ;
	while( s.empty() == false){
		int ss = s.begin()->second ;
		s.erase( s.begin()) ;
		for( auto it : v[ss]) {
			if( dis[it.first] > dis[ss] + it.second){
				s.erase( {dis[it.first ] , it.first}) ;
				dis[it.first] = dis[ss] + it.second ;
				s.insert( {dis[it.first] , it.first}) ;
			}
		}
	}
}
signed main(){
	int n; 
	cin >>n ;
	rep(i , 0 , 100000 ) dis[i] = N ;
	for( int i = 1; i<=n ;i++){
		v[i%n].pb({(i+1)%n , 1}) ;
		v[i%n].pb( {(i*10)%n , 0}) ;
	}

	dj(1) ;
	cout << dis[0] + 1 ;
}

Measured memory_bytes: 11008
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,t=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    AB.sort()

    ans=0
    dp=[0]*t
    for a,b in AB:
        ans=max(ans,dp[-1]+b)
        ndp=dp[:]
        for i in range(t):
            if(i+a<t):
                ndp[i+a]=max(ndp[i+a],dp[i]+b)
        dp=ndp

    print(ans)
resolve()

Measured memory_bytes: 42732
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

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

    string sd, t;
    cin >> sd >> t;

    Int sds = sd.size(), ts = t.size();

    bool mayex = true;
    if (sds < ts) {
        mayex = false;
    }

    set<string> s;
    Int ro = sds - ts + 1;
    for (Int i = 0; i < ro; i++) {
        string ans;
        bool isok = true;
        for (Int j = 0; j < ts; j++) {
            if (t[j] != sd[i + j]) {
                if (sd[i + j] != '?') {
                    isok = false;
                    break;
                }
            }
        }

        if (isok) {
            for (Int j = 0; j < sds; j++) {
                if (i <= j && j < i + ts) {
                    ans += t[j - i];
                } else {
                    if (sd[j] == '?') {
                        ans += 'a';
                    } else {
                        ans += sd[j];
                    }
                }
            }

            s.insert(ans);
        }
    }

    if (mayex && s.size() != 0) {
        cout << *s.begin() << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 3672
a = gets.chomp.split.sort
n = a.size

mwc = 0
mw = mx = a[0]
c = 1
a.each { |x|
  if mx == x
    c += 1
  elsif c > mwc
    mw = mx
    mx = x
    mwc	= c
    c = 1
  else
    mx = x
    c = 1
  end
}
if c > mwc
  mw = mx
end

lwc = 0
lw = a[0]
a.each { |x|
  if x.length > lwc
    lw = x
    lwc = x.length
  end
}

puts mw + " " + lw

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,u;
    cin>>N;
    for(int i=0; i<=7; i++)
    {
        u=pow(2,i);
        if(u>N)
        {
            u=pow(2,i-1);
            cout<<u<<endl;
            break;
        }
    }
    return 0;
}

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

int main(){
  int n, u, k, v; //nは頂点の数, kはuの出次数, vはuに隣接する頂点
  int adj[MAX+1][MAX+1] = {};
  int i, j;

  //1オリジンで
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d %d", &u, &k);
    for(j=0;j<k;j++){
      scanf("%d", &v);
      adj[u][v] = 1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j == n) printf("%d\n", adj[i][j]);
      else printf("%d ", adj[i][j]);
    }
  }
  
  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main { 
			public static void main(String[] args) {
				// ?¨??????\??????????????????????????????????????? 
				Scanner sc = new Scanner(System.in); 
				// 2?????????????????????????????????????????´??°?????¨???????????????????????? 
				int a = sc.nextInt(); int b = sc.nextInt(); 
				int area = a*b; 
				int length = a*2+b*2;
				System.out.println(area + " " + length); 
				}
			}

Measured memory_bytes: 25972
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181

"""
import sys
from sys import stdin
input = stdin.readline


def Cond(m, n, mid, books):
    if max(books) > mid:
        return False

    rem = mid
    while books:
        while rem >= books[0]:
            rem -= books[0]
            books = books[1:]
            if len(books) == 0:
                break
        rem = mid
        m -= 1

    if m >= 0:
        return True
    else:
        return False


def solve(m, n, books):
    ub = 1500000
    lb = min(books)
    min_width = float('inf')

    for i in range(30):
        mid = (ub + lb) // 2
        if Cond(m, n, mid, books):
            min_width = min(min_width, mid)
            ub = mid
        else:
            lb = mid

    return min_width



def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        books = [int(input()) for _ in range(n)]
        result = solve(m, n, books)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7696
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut it = buf.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let n = it.next().unwrap();
    let m = it.next().unwrap();
    buf.clear();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut it = buf.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    // let a : Vec<i64> = it.collect();
    let v = it.fold(0, |acc, x| acc + x);
    
    println!("{}", std::cmp::max(n - v, -1));
}


Measured memory_bytes: 2136
#include <iostream>
#include <map>

constexpr int MAX_N=(int)1e5;

int n;

std::map<int,int> map;

int main() {

    std::cin>>n;

    int a;

    for(int i=0;i<n;++i){
        std::cin>>a;
        ++map[a];
    }

    int ans=0;

    for(auto p : map){
        if(p.first<=p.second)
            ans+=p.second-p.first;
        else
            ans+=p.second;
    }

    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 4736
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val sqrtLimit = (Math.sqrt(n).toInt - 3) / 2

    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def notPrime(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    def next(i: Int): Int = if((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {
      /*
      for{
        i <- 0 to sqrtLimit
        if isPrime(i)
        j <- Range(((2 * i + 3)*(2 * i + 3)-3)/2, top, (2 * i + 3))
      } notPrime(j)
      */
      (0 to sqrtLimit).map{ i =>
        val p = 2 * i + 3
        if(isPrime(i))Range((p*p-3)/2, top, p).map{notPrime}
      }
      if(n==2)Iterator.single(2)
      else Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) / 2)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 305820
/*https://atcoder.jp/contests/abc063/tasks/abc063_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	vector <char> v;
	char c;
	int count = 0;
	while (cin >> c)
		v.push_back(c), count++;
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	if (v.size() == count)
		cout << "yes";
	else
		cout << "no";
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<int> p(n);

	for(int i=0; i<n; i++)
	{
		cin>>p[i];
	}
	int count = 0;
	for(int i=0; i<n-2; i++)
	{
		//cout<<i<<endl;
		if( (p[i]<p[i+1] && p[i+1]<p[i+2]) || (p[i]>p[i+1] && p[i+1]>p[i+2]) )
		{
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
#include<cassert>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, string>
#define Pint pair<int, int>
const int INF = INT_MAX / 2;
const int MAX_M = 2000;

string human[MAX_M][MAX_M];
map<string, Pint > human_map;

bool tmpCheck(int y, int x){
    if(y >= MAX_M) return false;
    if(x >= MAX_M) return false;
    if(y < 0) return false;
    if(x < 0) return false;
    return true;
}

P cntSpace(string str){
    int cnt = 0;
    while(str[cnt] == ' ' && cnt < str.size() - 1) cnt++;
    return P(cnt, str.substr(cnt));
}

string getParent(string x){
	int depth = human_map[x].second - 1, id = human_map[x].first - 1;
	while(id >= 0 && depth >= 0){
		if(human[id][depth] != "") return human[id][depth];
		id--;
	}
	return "_"; // FAILED
}

bool checkAncestor(string x, string y){
	while(y != "_"){
		if(x == y) return true;
		y = getParent(y);
	}
}

bool checkParent(string x, string y){
	return getParent(y) == x;
}

bool checkSibling(string x, string y){
	x = getParent(x);
	y = getParent(y);
	
	if(x == "_" || y == "_") return false;
	return x == y;
}

bool checkQ(string str){
    stringstream ss(str);
    vector<string> vec;
    string tmp;
    while(ss >>tmp) vec.push_back(tmp);

    string y = vec[5].erase(vec[5].size() - 1);
    if(vec[3] == "child") return checkParent(y, vec[0]);
    else if(vec[3] == "parent") return checkParent(vec[0], y);
    else if(vec[3] == "sibling") return checkSibling(vec[0], y);
    else if(vec[3] == "descendant") return checkAncestor(y, vec[0]);
    else if(vec[3] == "ancestor") return checkAncestor(vec[0], y);
	else assert(0);
}

int main(){
    while(true){
        int m, n;
        string st;
        getline(cin, st);
        stringstream ss(st);
        ss >>m >>n;
        if(!n && !m) break;

        REP(i, MAX_M) REP(j, MAX_M) human[i][j] = "";
        human_map.clear();

        REP(i, m){
            string str;
            getline(cin, str);
            P tmp = cntSpace(str);
            human[i][tmp.first] = tmp.second;
            human_map[tmp.second] = Pint(i, tmp.first);
        }

        REP(i, n){
            string str;
            getline(cin, str);
            if(checkQ(str) == true) cout <<"True" <<endl;
            else cout <<"False" <<endl;
        }
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 32640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pll;
typedef pair<pll,int> tri;

int h[100100];
vector<pll> g[100100];
bool vis[100100];

ll solve(void){
  int n,m,x,a,b,l;
  scanf("%d%d%d",&n,&m,&x);
  for(int i=0;i<n;i++)scanf("%d",&h[i]);

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&l);
    a--; b--;
    g[a].push_back(pll(b,l));
    g[b].push_back(pll(a,l));
  }

  priority_queue<tri> q;
  q.push(tri(pll(x,0),0));

  while(q.size()){
    tri p = q.top(); q.pop();
    int hight = p.first.first, tree = p.second;
    ll cost = -p.first.second;

    if(vis[tree])continue;
    vis[tree] = 1;

    if(tree == n-1)return cost + h[n-1]-hight;

    for(pll e : g[tree]){
      int nxt = e.first,  t = e.second, nxth = hight;
      ll nxtc = cost;
      if(h[tree]<t)continue;

      if(hight<t){
	nxtc += 2*t-hight;
	nxth = 0;
      }else if(h[nxt]<hight-t){
	nxtc += hight-h[nxt];
	nxth = h[nxt];
      }else{
	nxtc += t;
	nxth -= t;
      }
      q.push(tri(pll(nxth,-nxtc),nxt));
    }
  }
  return -1;
}

int main(){
  printf("%lld\n",solve());
}

Measured memory_bytes: 33528
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	int n,k;cin>>n>>k;
    vector<int> h(n);
    rep(i,0,n) cin>>h[i];
    vector<ll> dp(n,10000000000);
    dp[0] = 0;
    rep(i,1,n){
        rep(j,1,k+1){
            if (i-j>=0) dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4584
/*input
15 8 5
*/

#include <bits/stdc++.h>

using namespace std;

const int H = 104, W = 10;
const int mod = 1e9 + 7;

int add(int a, int b) {
  int x = a + b;
  if (x >= mod) x -= mod;
  return x;
}

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int dp[H][W];
int fib[W + 4];
int h, w, k;

int getfib(int k) {
  return k < 0 ? 0 : k < 1 ? 1 : fib[k];
}

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

  fib[1] = 1, fib[2] = 2;
  for (int i = 3; i <= w; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }

  dp[0][1] = 1;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      dp[i][j] = add(add(
        mul(dp[i - 1][j - 1], mul(getfib(j - 2), getfib(w - j))),
        mul(dp[i - 1][j + 1], mul(getfib(j - 1), getfib(w - j - 1)))),
        mul(dp[i - 1][j], mul(getfib(j - 1), getfib(w - j)))
      );
      // printf("%d%d ", j - 1, w - j - 1);
    }
    // puts("");
  }

  printf("%d\n", dp[h][k]);
  return 0;
}

Measured memory_bytes: 256
n = int(input())

i = 1
cnt = 1
flag = False
while True:
    cnt += 1
    if i == n:
        flag = True
        break
    if i > n:
        break
    i += cnt

if not flag:
    print("No")
    exit()

print("Yes")
print(cnt)
li = [[] for i in range(cnt)]
num = 1
for i in range(cnt):
    tmp_num = num
    for _ in range(cnt - i - 1):
        li[i].append(tmp_num)
        tmp_num += 1
    for j in range(i+1, cnt):
        li[j].append(num)
        num += 1
for li2 in li:
    print(len(li2), *li2)

Measured memory_bytes: 47708
#include<stdio.h>

int main(void){

  int i;
  int month,day;
  int today;
  int year[12] = {31,29,31,30,31,30,31,31,30,31,30,31};

  while(1){
    scanf("%d %d",&month,&day);
    if(!month && !day)break;

    today = 3;
    for(i=0;i<month-1;i++)today += year[i];
    today += day;

    if(today % 7 == 0)printf("Sunday\n");
    else if(today % 7 == 1)printf("Monday\n");
    else if(today % 7 == 2)printf("Tuesday\n");
    else if(today % 7 == 3)printf("Wednesday\n");
    else if(today % 7 == 4)printf("Thursday\n");
    else if(today % 7 == 5)printf("Friday\n");
    else if(today % 7 == 6)printf("Saturday\n");
  }

  return 0;
}

Measured memory_bytes: 0
from bisect import bisect_left
n = int(input())
lst = list(map(int,input().split()))
ans = 0

lst.sort()

for i in range(n):
    for j in range(i+1,n):
        b,c = lst[i],lst[j]
        posr = bisect_left(lst,b+c)
        posl = max(j+1,bisect_left(lst,abs(b-c)))
        ans += (posr - posl)
print(ans)

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

const long long MAX = 100010;
const long long MOD = 1000000000 + 7;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
long long COM(long long n, long long k) {
  if (n < 0 || k < 0 || k > n) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  
  COMinit();
  
  long long N, K;
  cin >> N >> K;
  
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A.begin(), A.end());
  
  vector<pair<pair<long long, long long>, long long>> data;
  
  long long a, b;
  a = 0;
  b = 0;
  
  for(int i = 0; i < N; i++) {
    if (i == N - 1 || A[i] != A[i + 1]) {
      b++;
      data.push_back({{b, a}, A[i]});
      a = b;
    }
    else {
      b++;
    }
  }
  
  long long ans1 = 0;
  
  for (int i = 0; i < data.size(); i++) {
    long long x = data[i].first.first;
    long long y = data[i].first.second;
    long long p = data[i].second;
    ans1 += (MOD + COM(x, K) - COM(y, K)) * p;
    ans1 %= MOD;
  }
  
  reverse(A.begin(), A.end());
  
  vector<pair<pair<long long, long long>, long long>> data2;
  
  a = 0;
  b = 0;
  
  for(int i = 0; i < N; i++) {
    if (i == N - 1 || A[i] != A[i + 1]) {
      b++;
      data2.push_back({{b, a}, A[i]});
      a = b;
    }
    else {
      b++;
    }
  }
  
  long long ans2 = 0;
  
  for (int i = 0; i < data.size(); i++) {
    long long x = data2[i].first.first;
    long long y = data2[i].first.second;
    long long p = data2[i].second;
    ans2 += (MOD + COM(x, K) - COM(y, K)) * p;
    ans2 %= MOD;
  }
  
  cout << (ans1 + MOD - ans2) % MOD << endl;
  
}

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

#define ll              long long
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             (int)(1e18)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(i,j,n)      for(int i=j;i<n;i++)
#define all(p)          p.begin(),p.end()
#define ub(a,b)         upper_bound(all(a),b)
#define lb(a,b)         lower_bound(all(a),b)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
string ans;
string s, t;
vector<vector<int>> dp;
void lcs(int n, int m)
{
	if (s[n] == t[m])
	{
		ans += s[n];
		if (n > 0 and m > 0)
		{
			lcs(n - 1, m - 1);
		}
	}
	else {
		if (n == 0 and m > 0)
		{
			lcs(n, m - 1);
		}
		else if (n > 0 and m == 0)
		{
			lcs(n - 1, m);
		}
		else if (n > 0 and m > 0) {
			if (dp[n - 1][m] > dp[n][m - 1])
			{
				lcs(n - 1, m);
			}
			else {
				lcs(n, m - 1);
			}
		}
	}
	return;
}
int32_t main()
{
	run();
	cin >> s >> t;
	int n = s.length(), m = t.length();
	dp.resize(n, vector<int>(m));
	dp[0][0] = (s[0] == t[0]);
	for (int i = 1; i < n; i++)
	{
		if (s[i] == t[0] or dp[i - 1][0] == 1)
		{
			dp[i][0] = 1;
		}
		else {
			dp[i][0] = 0;
		}
	}
	for (int i = 1; i < m; i++)
	{
		if (s[0] == t[i] or dp[0][i - 1] == 1)
		{
			dp[0][i] = 1;
		}
		else {
			dp[0][i] = 0;
		}
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			if (s[i] == t[j])
			{
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	lcs(n - 1, m - 1);
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
/******memore********/
#define maxn
#define inf

int main()
{
	char a, b, c;
	scanf("%c %c",&a, &b);
	if (a == 'D')
	{
		if (b == 'D')
			c = 'H';
		else c = 'D'; 
	}
	else
	{
		if (b == 'D')
			c = 'D';
		else c = 'H';
	}
	printf("%c\n", c);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <sstream>
using namespace std;
  
priority_queue<string> top;
priority_queue<string, vector<string>, greater<string> > bottom;
string encrypt;
int answer = 0;
  
void rec(int index, string str) {
    if (index == encrypt.size()) {
        answer++;
        if (bottom.size() < 10) {
            bottom.push(str);
        } else {
            string temp = bottom.top();
            if (str > temp) {
                bottom.pop();
                bottom.push(str);
            }
        }
  
        if (top.size() < 5) {
            top.push(str);
        } else {
            string temp = top.top();
            if (str < temp) {
                top.pop();
                top.push(str);
            }
        }
        return;
    }
  
    bool can_change = encrypt[index] != 'z', can_remain = encrypt[index] == 'a';
    bool find_y = false;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == encrypt[index] + 1) {
            can_change = false;
        }
        if (str[i] == encrypt[index]) {
            can_remain = true;
        }
        if (str[i] == 'y') find_y = true;
    }
  
    if (can_change && encrypt[index] != 'z') {
        str.push_back(encrypt[index] + 1);
        rec(index + 1, str);
        str.pop_back();
    }
    if (can_remain) {
        str.push_back(encrypt[index]);
        rec(index + 1, str);
        str.pop_back();
    }
}
  
int main() {
    while (cin >> encrypt, encrypt != "#") {
        while (!top.empty()) top.pop();
        while (!bottom.empty()) bottom.pop();
        answer = 0;
  
        rec(0, "");
  
        cout << answer << endl;
  
        if (answer <= 10) {
            while (!bottom.empty()) {
                cout << bottom.top() << endl;
                bottom.pop();
            }
        } else {
            vector<string> S;
            for (int i = 0; i < 5; i++) {
                S.push_back(top.top()); top.pop();
            }
            for(int i=0;i<5;i++){
                cout << S[4-i] << endl;
            }
            for(int i=0;i<5;i++)bottom.pop();
            for (int i = 0; i < 5; i++) {
                cout << bottom.top() << endl;
                bottom.pop();
            }
        }
    }
    return 0;
}

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

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

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

  int x, y;
  cin >> x >> y;

  cout << x + y / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
class AOJ
{
    public static void Main()
    {
        for (;;)
        {
            string[] str = Console.ReadLine().Split();
            int m = int.Parse(str[0]); int f = int.Parse(str[1]); int r = int.Parse(str[2]); int d = m + f;
            String Hantei;
            if (m == -1 && f == -1 && r == -1)
                break;
            else if (d > 79)
                Hantei = "A";
            else if (m + f <= 79 && m + f > 64)
                Hantei = "B";
            else if (m + f >= 50 && m + f <= 64)
                Hantei="C";
            else if (m + f >= 30 && m + f <= 50 && r >= 50)
                Hantei="C";
            else if (m + f >= 30 && m + f <= 50 && r <= 50)
                Hantei="D";
            else
                Hantei="F";
            if (m == -1 || f == -1) { Hantei = "F"; }
            Console.WriteLine(Hantei);
        }

    }
}



Measured memory_bytes: 17936
n,*s=map(int,open(0).read().split());s,t,f,g=[s[i*n:i*n+n]for i in range(4)];a=[n*[0]for _ in[0]*n];r=range(n)
for b in range(64):
 e=1<<b;u=[k&e for k in f];v=[k&e for k in g];l=[0]*n;m=l[:]
 for i in r:
  for j in r:
   if(u[i]&v[j])|((s[i]^1)*u[i])|((t[j]^1)*v[j]):a[i][j]|=e;l[i]+=1;m[j]+=1
 for i in r:
  if(l[i]==0)*s[i]*u[i]:
   for j in r:
    if(t[j]^1)*(n-m[j]>1):a[i][j]|=e;m[j]+=1;break
 for j in r:
  if(m[j]==0)*t[j]*v[j]:
   for i in r:
    if(s[i]^1)*(n-l[i]>1):a[i][j]|=e;l[i]+=1;break
h=a[0][:];w=[i[0]for i in a]
for i in r:
 for j in r:w[i]=(w[i]|a[i][j]if s[i]else w[i]&a[i][j]);h[j]=(h[j]|a[i][j]if t[j]else h[j]&a[i][j])
if(g!=h)|(f!=w):print(-1);exit() 
for i in a:print(*i)


Measured memory_bytes: 99388
#include <stdio.h>
int main(){
  
   int i , x;
   i = 1;
   while(1){
      scanf("%d" , &x);
      if(x == 0){
        break;
      }
      printf("Case %d: %d\n" , i , x);   
      i++;
    }


    return 0;

}



Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n,m;
int dx[]={-1,-1,0,0,1,1};
int dy[]={0,-1,1,-1,1,0};
const int inf=1000000010;
int main(){
	while(cin>>n>>m,n){
		vvi used(200,vi(200,inf));
		rep(i,m){
			int a,b;cin>>a>>b;
			a+=100;b+=100;
			used[a][b]=-1;
		}
		int a,b;cin>>a>>b;
		a+=100;b+=100;
		queue<pii>q;
		q.push({a,b});
		used[a][b]=0;
		while(!q.empty()){
			pii t=q.front();
			q.pop();
			rep(i,6){
				int x=t.first+dx[i];
				int y=t.second+dy[i];
				int c=used[t.first][t.second]+1;
				if(used[x][y]==-1)continue;
				if(c<used[x][y]&&c<=n){
					used[x][y]=c;
					q.push({x,y});
				}
			}
		}
		int co=0;
		rep(i,200)rep(j,200)if(used[i][j]!=-1&&used[i][j]<inf)co++;
		
		cout<<co<<endl;
	}
}


Measured memory_bytes: 3252
# -*- coding: utf-8 -*-

n,m,x = map(int,input().split())
a = list(map(int,input().split()))

cost1 = 0
cost2 = 0

for i in range(x,n+1):
    if i in a:
        cost1 += 1

for i in range(x,0,-1):
    if i in a:
        cost2 += 1

print(min(cost1,cost2))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
    int n,m,p,y;
    int anscnt=1;
    cin >> n >> m;
    pair<pair<int,int>,int> py[100000];
    pair<int,int> num[100000];
    for(int i=0;i<m;i++){
        cin >> p >> y;
        py[i] = make_pair(make_pair(p,y),i);
    }
    sort(py,py+m);
    for(int i=0;i<m;i++){
        if(py[i-1].first.first==py[i].first.first){
            anscnt++;
            
        }else{
            anscnt=1;
        }
        num[py[i].second] = make_pair(py[i].first.first,anscnt);
    }
    for(int i=0;i<m;i++){
        printf("%06d%06d\n",num[i].first,num[i].second);
    }
    return 0;
}

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


vector<vector<int>> A;
int N;
vector<int> b;


void input() {
    A = vector<vector<int>>(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> A[i][j];
    cin >> N;
    b = vector<int>(N);
    rep(i, N) cin >> b[i];
}


int main() {
    input();
    for (int x : b) {
        rep(i, 3) rep(j, 3) {
            if (A[i][j] == x) {
                A[i][j] = 0;
                break;
            }
        }
    }
    rep(i, 3) {
        int x = 0;
        rep(j, 3) x += A[i][j];
        if (x == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(j, 3) {
        int x = 0;
        rep(i, 3) x += A[i][j];
        if (x == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (A[0][0] + A[1][1] + A[2][2] == 0 || A[0][2] + A[1][1] + A[2][0] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int r, d, x;
  cin >> r >> d >> x;

  REP(i, 10){
    x = r*x-d;
    cout << x << "\n";
  }

  return 0;
}


Measured memory_bytes: 3640