akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

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

	if (n <= 111)
		cout << 111;
	else if (n <= 222)
		cout << 222;
	else if (n <= 333)
		cout << 333;
	else if (n <= 444)
		cout << 444;
	else if (n <= 555)
		cout << 555;
	else if (n <= 666)
		cout << 666;
	else if (n <= 777)
		cout << 777;
	else if (n <= 888)
		cout << 888;
	else if (n <= 999)
		cout << 999;

	return 0;
}

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

template <typename List>
void split(const std::string& s, const std::string& delim, List& result){
    result.clear();

    using string = std::string;
    string::size_type pos = 0;

    while(pos != string::npos){
        string::size_type p = s.find(delim, pos);
        if(p == string::npos){
            result.push_back(s.substr(pos));
            break;
        }else{
            result.push_back(s.substr(pos, p - pos));
        }

        pos = p + delim.size();
    }
}

int main(){
    std::vector<string> result;
    string s;
    cin >> s;
    split(s, "/", result);
    //for(auto s : result){
    //    cout << s << " ";
    //}
    //cout << endl;
    //cout << result[1];
    int year, month, day;
    sscanf(result[0].c_str(), "%d", &year);
    sscanf(result[1].c_str(), "%d", &month);
    sscanf(result[2].c_str(), "%d", &day);

    if(year >= 2019){
        if(month >= 4){
            if((month == 4) && (day <= 30)){
                cout << "Heisei";
            }else{
                cout << "TBD";
            }
        }else{
            cout << "Heisei";
        }
    }
    else{
        cout << "Heisei";
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,c;
    for(a=1;a<=9;a++){
    	for(b=1;b<=9;b++){
    		c=a*b;
    		printf("%dx%d=%d\n",a,b,c);
    	}
    }
    return 0;
}


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

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

int main () {
  int s, w;
  cin >> s >> w;
  if (s > w) cout << "safe";
  else cout << "unsafe";
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;cin>>n;
	unordered_map<string, int> ma;
	vector<string> s(110);cin>>s[0];++ma[s[0]];
	for (int i=1;i<n;++i){
		cin>>s[i]; ++ma[s[i]];
		if(ma[s[i]]==2||s[i][0]!=s[i-1][s[i-1].size()-1]){cout<<"No\n";return 0;}
	}cout<<"Yes";
}

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

int main(){
  int N,A[3][3][2],b,i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      cin>>A[i][j][0];
      A[i][j][1]=0;
    }
  }
  cin>>N;
  for(int k=0;k<N;k++){
    cin>>b;
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
        if(b==A[i][j][0]) A[i][j][1]=1;
      }
    }
  }
  
  //debug
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      cerr<<A[j][i][1];
      cerr<<" ";
    }
    cerr<<endl;
  }
  
  //bingo_check
  /*Horizontal
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(1!=A[i][j][1]) break;
    }
    if(1==A[i][j][1]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }*/
  
  /*Vertical
  for(j=0;j<3;j++){
    for(i=0;i<3;i++){
      if(1!=A[i][j][1]) break;
    }
    if(1==A[i][j][1]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }*/
  
  //Cross+屈辱の手法
  if((A[0][0][1]==1 && A[1][1][1]==1 && A[2][2][1]==1) || (A[0][2][1]==1 && A[1][1][1]==1 && A[2][0][1]==1) || (A[0][0][1]==1 && A[0][1][1]==1 && A[0][2][1]==1) || (A[1][0][1]==1 && A[1][1][1]==1 && A[1][2][1]==1) || (A[2][0][1]==1 && A[2][1][1]==1 && A[2][2][1]==1) || (A[0][0][1]==1 && A[1][0][1]==1 && A[2][0][1]==1) || (A[0][1][1]==1 && A[1][1][1]==1 && A[2][1][1]==1) || (A[0][2][1]==1 && A[1][2][1]==1 && A[2][2][1]==1)){
    cout<<"Yes"<<endl;
    return 0;
  }
  
  cout<<"No"<<endl;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

string s;

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

	cin >> s;
	sort(ALL(s));
	cout << (s == "abc" ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

score = []
while True:
  m, f, r = map(int, input().split())
  if (m == -1 and f == -1 and r == -1):
    break
  else:
    score.append([m, f, r])

for i in range(len(score)):
  if (score[i][0] == -1 or score[i][1] == -1):
      print("F")
  elif (score[i][0]+score[i][1] >= 80):
    print("A")
  elif (score[i][0]+score[i][1] >= 65):
    print("B")
  elif (score[i][0]+score[i][1] >= 50 or (score[i][0]+score[i][1] >= 30 and score[i][2] >= 50)):
    print("C")
  elif (score[i][0]+score[i][1] >= 30):
    print("D")
  else:
    print("F")


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	int64_t k;
	cin>>n>>k;
	map<int,int64_t>m;
	for(int i=0,a,b;i<n;++i){
		cin>>a>>b;
		m[a]+=b;
	}
	int64_t c=0;
	for(auto&i:m){
		c+=i.second;
		if(c>=k){
			cout<<i.first<<"\n"s;
			break;
		}
	}
}

Measured memory_bytes: 4224
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i % 3600 / 60;
   s = i % 3600 % 60;
   cout << h << ":" << m << ":" << s << endl; 
   
   return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int ans = 0;
    int N, H, W;
    cin >> N >> H >> W;
    while(N--) {
        int A, B;
        cin >> A >> B;
        if(A >= H && B >= W) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args)throws IOException{
        int h, w;

        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        h = Integer.parseInt(st.nextToken());
        w = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (h == 0 && w == 0) break;
        	int i, j;

            for (j = 0;j < w;j++) {
                System.out.printf("#");
            }
            System.out.printf("\n");

            for (i = 1;i < h - 1;i++) {
                System.out.printf("#");
                for (j = 1;j < w - 1;j++) {
                    System.out.printf(".");
                }
                System.out.printf("#\n");
    	    }

            for (j = 0;j < w;j++) {
                System.out.printf("#");
            }
            System.out.printf("\n");

            System.out.printf("\n");
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            h = Integer.parseInt(st.nextToken());
            w = Integer.parseInt(st.nextToken());
        }
    }
}

Measured memory_bytes: 56860
#include<stdio.h>

int main(void)
{
	int N, i, v, j, s;
	scanf( "%d", &N );
	
	int A[N];
	for( i = 0; i < N; i++ ){
		scanf( "%d", &A[i] );
	}
	
	printf( "%d", A[0] );
	
	for( s = 1; s < N; s++ ){
			printf( " %d", A[s] );
		}
	
	printf( "\n" );
	
	for( i = 1; i < N; i++ ){
		v = A[i];
		j = i-1;
		while( j >= 0 && A[j] > v ){
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
		
		printf( "%d", A[0] );
		
		for( s = 1; s < N; s++ ){
			printf( " %d", A[s] );
		}
		
		printf( "\n" );
	}
	
	return 0;
}


Measured memory_bytes: 2096
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

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

	ll num500 = x / 500;
	x -= num500 * 500;
	ll num5 = x / 5;

	ll ans = num500 * 1000 + num5 * 5;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int V[] = new int[N];
		int C[] = new int[N];
		int mouke[] = new int[N];
		int ans = 0;

		for (int i = 0; i < N; i++) {
			V[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
			ans += Math.max(V[i] - C[i], 0);
		}

		System.out.println(ans);

		sc.close();
	}
};

Measured memory_bytes: 35808
{-# LANGUAGE BangPatterns, FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array
import Data.Array.ST
import Data.List
import Debug.Trace (traceShow, traceShowM)
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

solve :: String -> Int
solve xs = minimum $ fmap (\z -> abs $ z - 753) $ do
    ys <- tails xs
    guard (length ys >= 3)
    let z = read $ take 3 ys :: Int
    return z

main :: IO ()
main = do
    xs <- getLine
    print $ solve xs

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char> >c(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c[i][j];
        }
    }
    bool chk = true;
    while(chk){
        chk = false;
        vector<int>tmp;
        for(int i=0;i<h;i++){
            bool chkk = true;
            for(int j=0;j<w;j++){
                if(c[i][j] == '#')chkk = false;
            }
            if(chkk){
                tmp.push_back(i);
                chk=true;
            }
        }
        h -= tmp.size();
        for(int i=tmp.size()-1;i>=0;i--){
            c.erase(c.begin() + tmp[i]);
        }
        vector<int>tmpp;
        for(int i=0;i<w;i++){
            bool chkk = true;
            for(int j=0;j<h;j++){
                if(c[j][i] == '#')chkk=false;
            }
            if(chkk){
                tmpp.push_back(i);
                chk=true;
            }
        }
        w -= tmpp.size();
        for(int i=tmpp.size()-1;i>=0;i--){
            for(int j=0;j<h;j++){
                c[j].erase(c[j].begin() + tmpp[i]);
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
cout << c[i][j];
        }
        cout << endl;
        
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void Yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };

void solve() {
    int N,K,C;
    string S;
    cin >> N >> K >> C >> S;
    vi L(K+1),R(K+1);
    int counter=1;
    int rest = 0;
    rep(i,N){
        if(rest-->0) continue;
        if(counter>K) break;
        if(S[i]=='o'){
            L[counter++]=i+1;
            rest=C;
        }
    }
    counter=K;
    rest = 0;
    per(i,N){
        if(rest-->0) continue;
        if(counter<1) break;
        if(S[i]=='o'){
            R[counter--]=i+1;
            rest=C;
        }
    }
    rng(i,1,K+1){
        if(L[i]==R[i]) print(L[i]);
    }
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

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

const long long num = 1e18;
int n;
long long a, ans = 1;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (a == 0) ans = 0;
        else if (ans <= 0) continue;
        else if (a <= (num / ans)) ans *= a;
        else ans = -1;
    }
    cout << ans << "\n";
}


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

int main() {
  int N;
  ll K;
  cin >> N >> K;
  int A[2005];
  ll low_sum = 0;
  rep(i, N) { cin >> A[i]; }

  ll tmp = 0;
  for (int p = 0; p < N; p++) {
    for (int q = 0; q < N; q++) {
      if (A[p] > A[q] && p < q) {
        tmp++;
      }
      if (A[p] > A[q]) {
        low_sum++;
      }
    }
  }

  long long ans = 0;
  long long cal = K * (K - 1) / 2 % MOD;
  ans += tmp * K % MOD;
  ans %= MOD;
  ans += low_sum * cal % MOD;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}

import Control.Applicative
main = do
  [a, b, c] :: [Int] <-  (map read . words) <$> getLine
  putStrLn $ solve a b c

solve :: Int -> Int -> Int -> [Char]
solve a b c
  |a < b = if b < c then "Yes" else "No"
  |otherwise = "No"

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, L: int):
    s = N*L+N*(N+1)//2-N
    s -= min([L-1+i for i in range(1, N+1)], key=lambda x: abs(x))
    print(s)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}

int main() {
	cin >> N;
	cout << (N+1) / 2;
}



Measured memory_bytes: 256
cnt = 0

def merge(a, b):
    global cnt
    c = []
    i = 0
    j = 0
    for k in range(len(a)+len(b)):
        if i < len(a) and j < len(b) and a[i] > b[j]:
            c.append(b[j])
            cnt = cnt + len(a) - i
            j = j + 1
        elif i >= len(a):
            c.append(b[j])
            j = j + 1
        else:
            c.append(a[i])
            i = i + 1
    return c

def mergesort(a):
    if len(a) == 1:
        return a
    else:
        return merge(mergesort(a[:len(a)//2]), mergesort(a[len(a)//2:]))

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

mergesort(a)

print(cnt)


Measured memory_bytes: 27472
#include<stdio.h>

int main(void){
    int c0[3],c1[3],c2[3],i,temp[3];
    scanf("%d %d %d",&c0[0],&c0[1],&c0[2]);
    scanf("%d %d %d",&c1[0],&c1[1],&c1[2]);
    scanf("%d %d %d",&c2[0],&c2[1],&c2[2]);
    
    for(i=0;i<3;i++){
        temp[i] = c1[i]-c0[i];
    }
    if(temp[0] != temp[1] || temp[1] != temp[2]){
        printf("No\n");
        return 0;
    }
    
    for(i=0;i<3;i++){
        temp[i] = c2[i]-c1[i];
    }
    if(temp[0] != temp[1] || temp[1] != temp[2]){
        printf("No\n");
        return 0;
    }
    temp[0] = c0[1]-c0[0];
    temp[1] = c1[1]-c1[0];
    temp[2] = c2[1]-c2[0];
    if(temp[0] != temp[1] || temp[1] != temp[2]){
        printf("No\n");
        return 0;
    }
    temp[0] = c0[2]-c0[1];
    temp[1] = c1[2]-c1[1];
    temp[2] = c2[2]-c2[1];
    if(temp[0] != temp[1] || temp[1] != temp[2]){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
/*Lucky_Glass*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=20000;

int n,m;
char Is[N+5],ReS[N+5],It[N+3],Ns[N+3],Nans[N+3];

int main(){
	scanf("%d%d%s",&n,&m,Is+1);
	strcpy(ReS+1,Is+1);
	reverse(ReS+1,ReS+1+n);
	strcat(Is+1,ReS+1);
	m--;
	for(int i=1;i<=n+1;i++){
		for(int j=0;j<n;j++) It[j+1]=Is[j+i];
		It[n+1]=It[n];
		int Vlen=0;
		for(int j=n;j>=1;j--)
			if(It[j]==It[j+1]) Vlen++;
			else break;
		int logf=ceil(log2(ceil((double)n/Vlen)));
		if(m>=logf){
			for(int j=1;j<=n;j++)
				Ns[j]=It[n];
		}
		else{
			int k=n-Vlen;
			for(int j=1;j<=Vlen*(1<<m);j++)
				Ns[j]=It[n];
			for(int j=1;j+Vlen*(1<<m)<=n;j++)
				Ns[j+Vlen*(1<<m)]=It[k--];
		}
		Ns[n+1]='\0';
//		printf("%s\n",Ns+1);
		if(Nans[1]=='\0') strcpy(Nans+1,Ns+1);
		else
			if(strcmp(Nans+1,Ns+1)>0)
				strcpy(Nans+1,Ns+1);
	}
	printf("%s\n",Nans+1);
	return 0;
}
/*
10 1
bbaabbbaab
*/

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

void dfs(int n, char c = 'a', string acc = "a") {
  if (acc.size() == n) {
    cout << acc << endl;
    return;
  }
  int nc = c > acc.back() ? c : c + 1;
  for (char c = 'a'; c <= nc; ++c)
    dfs(n, nc, acc + c);
}

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

  dfs(n);
}

Measured memory_bytes: 1536
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

int table[1 << 10];
int ans;

// n 残りの残数
// s 合計
// bit mask
void solve(int mask, int n, int s, int min) {
  if (table[mask] != 0) return;
  if (s == 0 && n == 0) {
    table[mask] = 1;
    ans++;
    return;
  }
  if (s < 0 || n <= 0) return;
  int sum = 0;
  for (int i = 0; i <= 9; i++) {
    if (((mask >> i) & 1) == 0 && i >= min) {
      solve(mask | 1 << i, n - 1, s - i, i);
    }
  }
  return;
}

void main() {
  while(true) {
    (cast(ubyte*)&table)[0..table.sizeof] = 0;
    auto line = readln.chomp.split(" ").map!(to!(int));
    int n = line[0];
    int s = line[1];
    if (n == 0 && s == 0) break;
    ans = 0;
    solve(0, n, s, 0);
    writeln(ans);
  }
}

Measured memory_bytes: 1072
#include <iostream>
using namespace std;
int main(){
	int n,m,l;
	cin >>n>>m>>l;
	long long int a[101][101],b[101][101];
	long long int x;
	for( int i=0 ; i<n ; i++ )
		for( int j=0 ; j<m ; j++ )
			cin >> a[i][j];
	for( int i=0 ; i<m ; i++ )
		for( int j=0 ; j<l ; j++ )
			cin >> b[i][j];
	for( int i=0 ; i<n ; i++ ){
		for( int j=0 ; j<l ; j++ ){
			x=0;
			for( int k=0 ; k<m ; k++ ){
				x += a[i][k]*b[k][j];
			}
			cout << x;
			if( j!=l-1 )
				cout <<" ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
// https://atcoder.jp/contests/abc154/tasks/abc154_f

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define FORR(i,b,e) for(int i=(b); i>=(int)(e); i--)

#if 1
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(a) if (DEBUG) REP(_i, a.size()) DUMP(a[_i]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(a)
#endif

//------------------------------------------------------------------------------
int extgcd(int a, int b, int &x, int &y) {
  int ret = a;
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    ret = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  return ret;
}

int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

//------------------------------------------------------------------------------
const int F_MAX = 2*1e6+1;

ll fact[F_MAX + 1];
ll fact_inv[F_MAX + 1];

void init_fact(int m) {
  fact[0] = 1;
  FOR(i, 1, F_MAX) fact[i] = fact[i - 1] * i % m;
  fact_inv[F_MAX] = mod_inverse(fact[F_MAX], m);
  FORR(i, F_MAX - 1, 0) fact_inv[i] = fact_inv[i + 1] * (i + 1) % m;
}

ll mod_comb_fast(ll n, ll k, ll mod) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll a = fact[n];
  ll b = fact_inv[k] * fact_inv[n - k] % mod;
  ll ret = a * b % mod;
  // printf("%lld_C_%lld = %lld\n", n, k, ret);
  return ret;
}

//------------------------------------------------------------------------------

const int R_C_MAX = 1e6;
const int MOD = 1e9+7;

int r_1, c_1, r_2, c_2;

ll F(ll r, ll c) {
  if (r > c) swap(r, c);
  ll ret = 0;
  FOR(i, 0, r) ret = (ret + mod_comb_fast(c + i + 1, i + 1, MOD)) % MOD;
  // cout << "F(" << r << ", " << c << ") = " << ret << endl;
  return ret;
}

int main() {
  cin >> r_1 >> c_1 >> r_2 >> c_2;
  r_1--; c_1--;

  init_fact(MOD);

  ll ans = F(r_2, c_2);
  ans = (ans + MOD - F(r_1, c_2)) % MOD;
  ans = (ans + MOD - F(r_2, c_1)) % MOD;
  ans = (ans + F(r_1, c_1)) % MOD;
  cout << ans << endl;
}


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

ll calc(ll x, ll y, ll v) {
	ll c1 = v / x;
	ll c2 = v / y;
	ll c3 = v / (x * y / __gcd(x, y));
	return v - c1 - c2 + c3;
}

int main()
{
	ll A, B;
	int C, D;
	cin >> A >> B >> C >> D;
	cout << calc(C, D, B) - calc(C, D, A - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
int n,k;
int ai[56][56];
int bi[5];
void init(){
   
}


int ans;
void play(){
    memset(ai,0,sizeof(ai));
    int sum=bi[1]+bi[2]+bi[3]+bi[4];
    for(int i=1;i<=50;i++){
        for(int j=1;j<=50;j++){
            for(int k=1;k<=4;k++){
                if(bi[k]>0){
                    if(k!=ai[i][j-1]&&k!=ai[i-1][j]){
                        ai[i][j]=k;
                        sum--;
                        bi[k]--;
                        break;
                    }
                    else{
                        continue;
                    }
                }
                if(ai[i][j]>0)break;
               
            }
         
        }
    }
}
void pri(){
   
}
struct he1 {
    int x;
    int id;
}need[100];
int vvv[100];
bool cmp1(he1 a,he1 b){
    return a.x>b.x;
}
int main() {
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF){
        if(a==0){
            if(b==100)
                printf("%d\n",101);
            else
                printf("%d\n",b);
        }
        else if(a==1){
            if(b==100)
                printf("%d\n",10100);
            else
                printf("%d\n",b*100);
        }
        else{
            if(b==100)
                printf("%d\n",1010000);
            else
                printf("%d\n",b*10000);
            }
    }

    
    return 0;
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d){
    cout << "Left" <<endl;
  }
  else if(a + b == c + d){
    cout << "Balanced" <<endl;
  }
  else{
    cout << "Right" <<endl;
  }
}
    



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;

    cin >> x >> y;
    vi p(x);
    rep(i, y)
    {
        cin >> a >> b;
        p[a - 1]++;
        p[b - 1]++;
    }
    rep(i, x)
        pr(p[i]);
    return 0;
}


Measured memory_bytes: 3592
#include<algorithm>
#include<deque>
#include<iostream>
using namespace std;
int N, a;
deque<int> q;
int main() 
{
    cin >> N;
    for(int i = 1; i <= N; ++i) 
    {
        cin >> a;
        if(i & 1) q.push_back(a);
        else q.push_front(a);
    }
    if(N & 1) reverse(q.begin(), q.end());
    for(auto it = q.begin(); it != q.end(); ++it)
        cout << *it << ' ';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

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

    ll N;
    cin >> N;
    ll sum = 0, mn = INF;
    rep(i, N){
        ll s;
        cin >> s;
        sum += s;
        if(s % 10 != 0) chmin(mn, s);
    }
    if(sum % 10 != 0) drop(sum);
    else if(mn == INF) drop(0);
    else drop(sum - mn);


    return 0;
}

Measured memory_bytes: 256
def main():
    A, V = list(map(int, input().split()))
    B, W = list(map(int, input().split()))
    T = int(input())

    distance = abs(A-B)
    speed = V - W
    if speed <= 0:
        print("NO")
        return
    
    if T * speed >= distance:
        print("YES")
        return
    else:
        print("NO")
        return
    


if __name__  == '__main__':
    main()

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

int main(){
  string s;
  cin >> s;
  if(s.substr(0,2) =="00" || s.substr(2,2) =="00"){
    if(s=="0000"){
      cout << "NA" << endl;
      return 0;
    }
    else if(s.substr(0,2) =="00" && s.substr(2,2) <="12"){
      cout << "YYMM" << endl;
      return 0;
    }
    else if(s.substr(0,2) <="12" && s.substr(2,2) =="00"){
      cout << "MMYY" << endl;
      return 0;
    }
    else cout << "NA" << endl;
    return 0;
  }


  if(s.substr(0,2) <="12" && s.substr(2,2) <="12"){
    cout << "AMBIGUOUS" << endl;
    return 0;
  }
  else if(s.substr(0,2) <="12"){
    cout << "MMYY" << endl;
    return 0;
  }
  else if(s.substr(2,2) <="12"){
    cout << "YYMM" << endl;
    return 0;
  }
  else{
    cout << "NA" << endl;
    return 0;
  } 
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int D[3][N], a[3][N];
    for (int i = 0; i < N; i++)
    {
        for (int y = 0; y < 3; y++)
        {
            cin >> a[y][i];
        }
    }
    for (int y = 0; y < 3; y++)
    {
        D[y][0] = a[y][0];
    }
    for (int i = 1; i < N; i++)
    {
        for (int y = 0; y < 3; y++)
        {
            D[y][i] = 0;
            for (int u = 0; u < 3; u++)
            {
                if (y != u)
                {
                    D[y][i] = max(D[y][i],D[u][i-1]+a[y][i]);
                }
            }
        }
    }
    cout << max(D[0][N-1],max(D[1][N-1],D[2][N-1]));
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool flag = false;
  for(int i =0; i<N;i++){
    int a;
    cin >> a;
    if(a % 2 == 0){
      if(a%3 != 0 && a%5 !=0)flag = true;
    }
    if(flag)break;
  }
  if(flag)cout<<"DENIED"<<endl;
  else cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Data{
	Data(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

int M,N,K,D;
int POW[7] = {1,2,4,8,16,32,64};

int getNUM(char buf[5]){

	int ret = 0;
	for(int i = 1; buf[i] != '\0'; i++){
		ret = 10*ret + (buf[i]-'0');
	}
	ret--;

	switch(buf[0]){
	case 'L':
		return ret+M+2;
	case 'C':
		return ret+2;
	case 'H':
		return 0;
	case 'D':
		return 1;
	}

	return -1; //must not reach here
}

void func(){

	int cake_value[M],min_Cost[M+N+2][POW[M]];

	for(int i = 0; i < M+N+2; i++){
		for(int k = 0; k < POW[M]; k++)min_Cost[i][k] = BIG_NUM;
	}

	vector<Data> V[M+N+2];

	for(int i = 0; i < M; i++)scanf("%d",&cake_value[i]);

	char left[5],right[5];
	int cost,left_num,right_num;

	for(int loop = 0; loop < D; loop++){
		scanf("%s %s %d",left,right,&cost);

		left_num = getNUM(left);
		right_num = getNUM(right);

		if(left[0] != 'C' && right[0] != 'C'){
			V[left_num].push_back(Data(right_num,K*cost));
			V[right_num].push_back(Data(left_num,K*cost));
		}else if(left[0] == 'C' && right[0] != 'C'){
			V[left_num].push_back(Data(right_num,K*cost));
			V[right_num].push_back(Data(left_num,K*cost-cake_value[left_num-2]));
		}else if(left[0] != 'C' && right[0] == 'C'){
			V[left_num].push_back(Data(right_num,K*cost-cake_value[right_num-2]));
			V[right_num].push_back(Data(left_num,K*cost));
		}else{
			V[left_num].push_back(Data(right_num,K*cost-cake_value[right_num-2]));
			V[right_num].push_back(Data(left_num,K*cost-cake_value[left_num-2]));
		}
	}

	min_Cost[0][0] = 0;

	bool updated;
	int next_state;

	for(int loop = 0; loop < N+M+2; loop++){
		updated = false;

		for(int from = 0; from < N+M+2; from++){
			for(int i = 0; i < V[from].size();i++){
				for(int state = 0; state < POW[M];state++){
					if(min_Cost[from][state] != BIG_NUM){
						if(V[from][i].to >= 2 && V[from][i].to <= 2+M-1){
							if(state & (1 << (V[from][i].to-2))){
								//Do nothing
							}else{
								next_state = state + POW[V[from][i].to-2];
								if(min_Cost[V[from][i].to][next_state] > min_Cost[from][state] + V[from][i].cost){
									min_Cost[V[from][i].to][next_state] = min_Cost[from][state] + V[from][i].cost;
									updated = true;
								}
							}

						}else{
							if(min_Cost[V[from][i].to][state] > min_Cost[from][state] + V[from][i].cost){
								min_Cost[V[from][i].to][state] = min_Cost[from][state] + V[from][i].cost;
								updated = true;
							}
						}
					}

				}
			}
		}

		if(!updated)break;
	}

	int ans = BIG_NUM;
	for(int i = 0; i < POW[M];i++)ans = min(ans,min_Cost[1][i]);

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

int main(){

	while(true){
		scanf("%d %d %d %d",&M,&N,&K,&D);
		if(M == 0 && N == 0 && K == 0 && D == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2632
#include <stdio.h>

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

    int ans=0;
    for(int i=1;i<=n;i+=2)
    {
        int divisor=0;
        for(int j=1;j<=i;j++)
        {
            if(i%j==0) divisor++;
        }
        if(divisor==8) ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009

ll gcm(ll a,ll b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcm(a%b,b);
}

int main(){
  ll n,k;
  cin >> n >> k;
  ll b;
  cin >> b;
  ll ag = b;
  rep(i,n){
    ll a;
    cin >> a;
    ag = gcm(ag,a);
    b = max(b,a);
  }
  if(k <= b && k % ag == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}


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

int main() {
  string str, tmp;
  while( cin >> tmp ) {
    str += tmp;
  }

  int ary[26] = {0};
  rep(i, str.length()) {
    if(!isalpha(str[i])) {
    } else if (islower(str[i])) {
      ary[str[i] - 'a']++;
    } else {
      ary[str[i] - 'A']++;
    }
  }

  rep(i, 26)
    cout << (char)(i + 'a') << " : " << ary[i] << endl;
  
  return 0;
}



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

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<int> v(N);
    rep(i, N) cin >> w[i] >> v[i];
    vector<vector<int>> dp(N + 1, vector<int>(100001, 1e9+1));
    rep(i, N + 1) dp[i][0] = 0;

    for (int i = 1; i <= N; i++) {
        int vv = v[i - 1];
        int ww = w[i - 1];
        rep(vi, 100001) {
            if (vi <= vv) {
                dp[i][vi] = min(dp[i - 1][vi], ww);
            } else {
                int before = vi - vv;
                dp[i][vi]  = min(dp[i - 1][vi], dp[i - 1][before] + ww);
            }
        }
    }

    for (int i = 100000; i >= 0; i--) {
        if (dp[N][i] <= W) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 40192
#include<bits/stdc++.h>
 
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace std;
const int N=2e3+1, mod= 1e9+7;

const long double PI= acos(-1);

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	
	int n;  ll l,r,ans, k;
	cin>>n>>k;
	
	vector<int> a(n),b(n);
	for(auto &x:a)cin>>x;
	for(auto &x:b)cin>>x;
	
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),greater<int>() );
	
	r=0;
	for(int i=0;i<n;i++){
		r=max(r,1LL*a[i]*b[i]);
	}
	
	l=0;
	ans=r;
	while(l<=r){
		ll mid=(l+r)/2;
		
		ll t=0;
		for(int i=0;i<n;i++){
			if( 1LL*a[i]*b[i] > mid ){
				int temp = mid/b[i];
				t+=a[i]-temp;
			}
		}
		
		if(t<=k){
			r=mid-1;
			ans=mid;
		}else l=mid+1;
		
	}
	
	cout<<ans;
	
	
    yogeshk972();
}


Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

result = 0

hasuu = [item % 10 for item in [A, B, C, D, E] if item % 10 != 0]

for item in [A, B, C, D, E]:
  if item % 10 == 0:
    result += item 
  else:
    result += (item // 10 + 1) * 10
    
if hasuu != []:
  result = int(result - 10 + min(hasuu))

print(result)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = s;
        if(s.length() == 3) {
            byte[] a = s.getBytes();
            byte[] r = new byte[]{a[2],a[1],a[0]};
            res = new String(r);

        }

        System.out.println(res);
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int alp = 26;
int D;
vector<long long> c(alp);
vector< vector< long long > > s;

long long sub(vector<int>& last, int x, int d){
    long long res = s[d][x];
    for(int j=0;j<alp;j++){
        if(j != x) res -= c[j] * (d-last[j]);
    }
    return res;
}

long long score(vector<int>& t){
    if(t.size() != D) return 0;
    vector< int > last(alp, -1);
    long long res = 0;
    for(int i=0;i<D;i++){
        res += s[i][t[i]];
        last[t[i]] = i;
        for(int j=0;j<alp;j++){
            res -= c[j] * (i-last[j]);
        }
    }
    return res;
}

void f(vector<int>& t){
    t.assign(D, 0);
    vector< int > last(alp, -1);
    for(int i=0;i<D;i++){
        int mxj = 0;
        long long mx = -1e9;
        for(int j=0;j<alp;j++){
            long long tmp = sub(last, j, i);
            if(tmp > mx){
                mxj = j;
                mx = tmp;
            }
        }
        t[i] = mxj;
        last[mxj] = i;
    }
}

bool print_t(vector<int>& t){
    if(t.size() != D) return false;
    for(int i=0;i<D;i++){
        cout << t[i]+1 << endl;
    }
    return true;
}

int main(void){
    cin >> D;
    for(int i=0;i<alp;i++) cin >> c[i];
    s.assign(D, vector<long long>(alp, 0));
    for(int i=0;i<D;i++){
        for(int j=0;j<alp;j++) cin >> s[i][j];
    }

    vector<int> t;
    f(t);
    print_t(t);
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

int n;
   cin>>n;
   std::vector<int> v(n);
 
   for(int i=0; i<n; i++)cin>> v[i];
 
   sort(v.begin(), v.end(), greater<int>()); 
 
   long int ans =0;
 
   ans += v[0];
 
   n -= 2;
   int i=1;
   while(n>=2)
   {
      ans +=2*v[i];
      n-=2;
      i++;
   }
 
   if(n)
   {
      ans += v[i];
   }
   cout<<ans<<endl;

	return 0;
 }

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ini(n) scanf("%d",&n)
#define inl(n) scanf("%lld",&n)
#define ini2(n,m) scanf("%d%d",&n,&m)
#define inl2(n,m) scanf("%lld%lld",&n,&m)
#define prnti(n) printf("%d",n)
#define prnti2(n, m) printf("%d %d",n,m)
#define prntl(n) printf("%lld",n)
#define prntl2(n, m) printf("%lld %lld",n,m)
#define SP() printf(" ")
#define NL() printf("\n")
int main()
{
    int n;
    cin >> n;
    double circumfrence = 0;
    circumfrence = 2 * acos(-1) * n ;
    printf("%.9f\n",circumfrence);
    return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
	int h,w,n,a[10005];
	int p[105][105];
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	memset(a,0,sizeof(a));
	memset(p,0,sizeof(p));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int k=1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(a[k])
			{
				p[i][j]=k;
				a[k]--;
			}else 
			{
				k++;
				a[k]--;
				p[i][j]=k;
			}
			
		}
		i++;
		for(int j=w-1;j>=0;j--)
		{
			if(a[k])
			{
				p[i][j]=k;
				a[k]--;
			}else 
			{
				k++;
				a[k]--;
				p[i][j]=k;
			}
			
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			printf("%d ",p[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int co[10][10] = { 0 };
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		int l = int(s[0] - '0');
		int r = int(s[s.size() - 1] - '0');
		co[l][r]++;
	}
	int ans = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			ans += co[i][j] * co[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    if(arr[0]+arr[1]==arr[2])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

const int INF = 1e+9;
int M, N, P[10001], C[501], E[501];
int DP[10010], sum[10010];

int main() {
	cin >> M >> N;
	for(int i = 0; i < M; ++i)
		scanf("%d", &P[i]);
	for(int i = 0; i < N; ++i)	
		scanf("%d%d", &C[i], &E[i]);
	stable_sort(P, P + M, greater<int>());
	sum[0] = 0;
	for(int i = 1; i <= M; ++i)
		sum[i] = P[i - 1] + sum[i - 1];
		
	fill(DP, DP + M + 5, INF);
	DP[0] = 0;
	for(int i = 0; i < N; ++i)
		for(int j = M; j >= 0; --j)
			DP[j] = min(DP[j], DP[max(0, j - C[i])] + E[i]);
			
	int ans = 0;
	for(int i = 0; i <= M; ++i)
		ans = max(ans, sum[i] - DP[i]);

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0); 
    ll n, m;
    cin >>  n >> m;
    ll ans = n * (n - 1) / 2 + (m) * (m - 1) / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++) {
        if(i % 2 == 0) {
            if(s[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            if(s[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}



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

int main(){
    long long X,deposit=100,year=0;
    cin >> X;
    while(1){
        if(X<=deposit){
            cout << year << endl;
            break;
        }else{
            deposit = deposit + (deposit/100);
            year++;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
#define pb push_back


int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n ;
    int arr[n],brr[n+1]={0};
    arr[0]=-1;
    for(int i=1;i<n;i++)
    {
        cin>>arr[i];
        brr[arr[i]]++;
    }
    for(int i=1;i<=n;i++)
        cout << brr[i] <<"\n";
    
    return 0;
}

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

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;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  ll n,x;
  cin >> n >> x;
  ll a[1000000];
  FOR(i,n){
    cin >> a[i]; 
  }

  ll ans=0;

  FOR(i,n-1){
    if(a[i]+a[i+1]>x){
      ans+=min(a[i+1],a[i]+a[i+1]-x);
      a[i+1]-=min(a[i+1],a[i]+a[i+1]-x);
      
      if(a[i]+a[i+1]>x){
        ans+=a[i]-x;
      }
    }
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 2816
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
typedef long long ll;
using namespace std;
 
int gcd(int a, int b)
{
  if(b == 0)
    {
      return a;
    }
  else
    {
      return gcd(b, a % b);
    }
}
 
int main()
{
  int a,b;
  while(~scanf("%d %d",&a,&b)){
    printf("%d %d\n",gcd(a,b),a/gcd(a,b)*b);
  }
}

Measured memory_bytes: 1188