akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC164
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            int[] abcd = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = abcd[0], b = abcd[1], c = abcd[2], d = abcd[3];
            while(true)
            {
                c -= b;
                if(c <= 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                a -= d;
                if(a <= 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 19000
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb(x) push_back(x)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;

//OPERATORS


//GLOBALS


//FUNCTIONS


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	ll resto = n%(a+b);
	ll por = n/(a+b);
	ll as = a*por;
	
	 cout << as + min(resto,a) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
kijun = ord("a")
n -= 1 #zero indexed
ans = []
mod = 26
while True:
    ans.append(n%mod)
    if n < mod:
        break
    n //= mod
    n -= 1

res = ""
for i in ans:
    res += chr(kijun+i)

print(res[::-1])

Measured memory_bytes: 61860
#include<bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define ll long long
#define i1 int128_t
#define vi vector<long long>
#define st set<long long>
#define uset unordered_set<long long>
#define si set<long long>:: iterator
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(long long i=a; i<b; i++)
#define fs(i,a,s) for(long long i=a; s[i]!='\0'; i++)
#define endl "\n"

int main(){

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

	ll n;
	cin>>n;

	if(n%1000)
		cout<<1000-n%1000;
	else
		cout<<0;
	 // fclose(stdin);
	 // fclose(stdout);
}

Measured memory_bytes: 3612
def main():
    N, x = map(int, input().split())
    A = [int(a) for a in input().split()]

    count = 0
    for i in range(1, len(A)):
        if A[i-1]+ A[i] > x:
            if A[i-1] <= x:
                count += A[i]+A[i-1]-x
                A[i] -=  A[i]+A[i-1]-x
            else:
                count += A[i]
                A[i] = 0
                count += A[i-1] - x
                A[i-1] = x
    # print(A)
    return count

if __name__ == '__main__':

    print(main())


Measured memory_bytes: 14068
def inpl(): return [int(i) for i in input().split()]

N,W = inpl()
H = {0: 0}
for i in range(N):
    w, v = inpl()
    for iw, iv in H.copy().items():
        if iw+w <=W:
            H[iw + w] = max(H.get(iw + w, 0),iv+v)
ans = 0
for aw,av in H.items():
    ans = max(ans,av)

print(ans)

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int big,regu,nob,ci,su,t;
    while(cin>>big>>regu>>nob>>ci>>su>>t,big,regu,nob,ci,su,t)
        cout<<100+ci*2+nob*7+regu*60+big*90-(t-su)*3+big*5+regu*3<<endl;

}

Measured memory_bytes: 1164
//
// Created by Hideaki Imamura on 2020-03-25.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

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

void print_vec(vector<int> v) {
    for (auto x : v) cout << x << " ";
    cout << endl;
}

string s, t;

int main() {
    cin >> s >> t;
    /* 頭からtを見ていき、各t[i]がs内で登場するかどうか見る
     * 登場しないなら、存在しないことになる
     * 各ch = t[i]とs'の添字jに対して、x = j mod len(s) として、
     * f(ch, x) = sにおいてx文字目以降でchがはじめに登場する位置
     * を計算できればOKっぽい
     * f(ch, x)は、各アルファベットの出現位置のリストを計算しておくと
     * リストからx以上の最小元を取り出すことになるので、lower_boundでいけそう。
     *
     * x が sの長さより長いなら、一周するということ
     * そうでなくでも、ansには次の位置 - 現在の位置を加えれば良さそう。
     * 次の位置はsの長さ未満にしておく
     */

    s += s;
    int n = s.size(), m = t.size();
    vector<ll> l[26];
    for (int i = 0; i < n; ++i) l[s[i] - 'a'].push_back(i);
    for (int i = 0; i < 26; ++i) l[i].push_back(INF);

    auto f = [&](int ch, ll x) {
        return *lower_bound(l[ch].begin(), l[ch].end(), x);
    };

    ll ans = 0;
    ll x = n / 2 - 1;
    for (int i = 0; i < m; ++i) {
        ll j = f(t[i] - 'a', x + 1);
        if (j == INF) {
            cout << -1 << endl;
            return 0;
        }
        ans += j - x;
        x = j % (n / 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3828
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(a int64, b int64) string {
       if a < b {
	return fmt.Sprintf("%v %v", a, b )
}
	return fmt.Sprintf("%v %v", b, a )
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

      for {
	a := nextInt()
	b := nextInt()
       if  a == 0 && b == 0 {
 break
}
	res := solve(a, b)
	fmt.Fprintln(out, res)
}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}



Measured memory_bytes: 1204
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
using namespace std;
const int N=1e5+10;
int f[N],a[N];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	f[1]=0,f[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{

		f[i]=min(abs(a[i]-a[i-2])+f[i-2],abs(a[i]-a[i-1])+f[i-1]);
		//printf("%d...\n",f[i]);
	}
	printf("%d\n",f[n]);
   return 0;
}


Measured memory_bytes: 4456
N = int(input())
words = []
for i in range(N):
  s_in = str(input())
  # 単語内の文字をソートする(標準化)
  s_sort = ''.join(sorted([ch for ch in s_in]))
  words.append(s_sort)
#print(words)

# Counterクラス: key=要素 -> val=出現回数
from collections import Counter
cntr = Counter(words)
#print(cntr)

# 組み合わせ数を足す
# N個から2個を選ぶなら N(N-1)/2 でよい、階乗いらない
# 1の場合は↑が0になるので cnt>1 の条件いらない
ans = 0
for cnt in cntr.values():
  ans += cnt * (cnt - 1) // 2

print(ans)

Measured memory_bytes: 19832
N = int(input())
dp = [-1] * 394
dp[0] = 0

for _ in range(N):
  s,l,p = map(int,input().split())
  for i in range(s, l+1):
    dp[i] = max(dp[i], p)

for i in range(1,394):
  for j in range(i):
    dp[i] = max(dp[i], dp[j]+dp[i-j])

res = []
M = int(input())
for _ in range(M):
  r = dp[int(input())]
  if r == -1:
    print(-1)
    exit()
  else:
    res.append(r)

for r in res: print(r)



Measured memory_bytes: 5656
#include <stdio.h>
#include <stdlib.h>

int main() {

    int n = 0;
    scanf("%d", &n);

    bool yes = false;

    for (int i = 1; i <= 9; i++) {
        if (n % i == 0) {
            if (n / i <= 9) {
                yes = true;
            }
        }
    }

    if (yes) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    // system("pause");
    return 0;
}

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

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define in(x) cin>>(x)
#define out(x) cout<<(x)
#define oute(x) cout<<(x)<<endl

#define INF 1000000
#define NMAX 40
#define ABMAX 10

int main(){
  int N,Ma,Mb; cin>>N>>Ma>>Mb;
  vi A(N),B(N),C(N); rep(n,N) cin>>A[n]>>B[n]>>C[n];

  int Na = NMAX*ABMAX, Nb = NMAX*ABMAX;
  vector<vvi> dp(N+1, vvi(Na+1, vi(Nb+1, INF)));
  dp[0][0][0] = 0;

  rep(n,N)
    rep(a,Na+1)
      rep(b,Nb+1){
        if(dp[n][a][b]==INF) continue;
        dp[n+1][a][b] = min(dp[n+1][a][b], dp[n][a][b]);
        dp[n+1][a+A[n]][b+B[n]]
          = min(dp[n+1][a+A[n]][b+B[n]], dp[n][a][b] + C[n]);
      }

  int ans = INF;
  upto(a,1,Na+1,1)
    upto(b,1,Nb+1,1)
      if(a*Mb==b*Ma) ans = min(ans, dp[N][a][b]);

  if(ans==INF) ans = -1;
  oute(ans);

}

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

def solve():
    N = int(input())
    H = list(map(int, input().split(" ")))

    ans = 1
    pre_h = H[0]
    for i in range(1, len(H)):
        if H[i] >= pre_h:
            ans += 1
            pre_h = H[i]
    print(ans)



if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int MOD = 1e9+7;

signed main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];


    vi hats(3, 0);
    int res = 1;
    rep(i, N) {
        int cnt = 0;
        rep(j, 3) if(A[i]==hats[j]) cnt++;
        //cout << cnt << endl;
        if(cnt==0) {
            cout << 0 << endl;
            return 0;
        }
        res *= cnt;
        res %= MOD;
        rep(j, 3) {
            if(A[i] == hats[j]) {
                hats[j]++;
                break;
            }
        }     
    }

    cout << res << endl;
    
    return 0;
}

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

int main() {
    int x,n;
    cin >> x >> n;
    map<int,int> m;
    for(int i=0 ; i < n ; i++) {
        int x;
        cin >> x;
        m[x]++;
    }
    int l = x , r= x;
    while(1) {
        if(m.find(r) == m.end()){
            cout << r << endl;
            break;
        }
        
        if(m.find(l) == m.end()) {
            cout << l << endl;
            break;
        }
        l++;
        r--;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n;
	cin>>n;
	rep(i,n){
	    string str;
	    cin>>str;
	    set<string> st;
	    for(int j=1;j<str.length();j++){
	        string a,b,c,d;
	        a=str.substr(0,j);
	        c=a;
	        b=str.substr(j);
	        d=b;
	        reverse(all(c));
	        reverse(all(d));
	        st.insert(a+b);
	        st.insert(a+d);
	        st.insert(c+b);
	        st.insert(c+d);
	        st.insert(b+a);
	        st.insert(d+a);
	        st.insert(b+c);
	        st.insert(d+c);
	    }
	    cout<<st.size()<<endl;
	}
}



Measured memory_bytes: 3116
n=int(input())
h = list(map(int, input().split()))
cnt =0
cnt_MAX = 0
for i in range(len(h)-1):
  if h[i] >=  h[i+1]:
    cnt+=1
  else:
    if cnt > cnt_MAX:
      cnt_MAX=cnt
    cnt=0
    
if cnt > cnt_MAX:
  cnt_MAX=cnt
print(cnt_MAX)

Measured memory_bytes: 14252
/*------U Have To DO It------*/
/* BY-> RicoProg */
/*        ___ 
           __|__|
          |  |___       */
#include <bits/stdc++.h>
using namespace std;
 
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define ld long double
#define beg(i ,n) for(ll i=0;i<n;i++)
#define beg1(i ,n) for(ll i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define mp make_pair
#define nl "\n" 
#define sp " "
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second

//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD2 = 998244353 ;
const ll MOD = 1e9 + 7 ;
const ll MAX = 1e5 + 7 ;
const ll inf = 1e18L + 5 ;
const double pi = 3.14159265358979323846 ;
ll fpow(ll n , ll m ){ll res=1 ;while(m>0){if(m&1){res*=n ;}m/=2 ;n*=n ;}return res;}

//---------------------------------------------------FUNCTIONS-------------------------------------------------------

const ll nax = 1e5 + 5 ;

void solve(){
	ll n , m ;
	cin >> n >> m ;
	ll ar[n] ;
	ll ans=0 ;
	beg(i , n) cin >> ar[i] ;
	beg(i , n){
		if(ar[i]>=m) ans++ ;
	}
	cout << ans ;
}

//---------------------------------------------------DRIVER----------------------------------------------------------
int main()
{
    fast ;
    int t=1 ;
    // cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}   

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int r[2];
int main(void){
    // Your code here!
    for (int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        if (a == 5) r[0]++;
        if (a == 7) r[1]++;
    }
    if (r[0] == 2 && r[1] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= putStrLn . solve 

solve :: [Int] -> String
solve [sx, sy, tx, ty] = replicate ly 'U' ++ replicate lx 'R' ++ replicate ly 'D' ++ replicate (lx + 1) 'L' ++ replicate (ly + 1) 'U' ++ replicate (lx + 1) 'R' ++ "DR" ++ replicate (ly + 1) 'D' ++ replicate (lx + 1) 'L' ++ "U"
    where
        lx = tx - sx
        ly = ty - sy


readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 1020
program Takoyaki
 implicit none
 integer   :: n,x,t,ans

 read(*,*) n,x,t

 ans = 0
 
 do
  n = n - x
  ans = ans + t
 if ( n <= 0 ) then
  exit
 end if
 end do
  
 write(*,*) ans 
 
 
 end program Takoyaki


 

 

Measured memory_bytes: 2828
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100001],pro=1,inf=1e18;
int main(){
	int n;
	cin>>n;
	bool zero=false,ok=true;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0) zero=true;
	}
	if(zero==true){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(a[i]>inf) ok=false;
		if(ok){
			inf/=a[i];
			pro*=a[i];
		}
	}
	if(ok) cout<<pro<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N, K;
        double ans = 0;

        void solve(InputReader in, PrintWriter out) {
            // write your code here
            N = in.nextInt();
            K = in.nextInt();

            for (int i = 1; i <= N; i++) {
                double p = 1;
                p /= (double)N;
                int point = i;
                while (point < K) {
                    point *= 2;
                    p /= 2;
                }
                ans += p;
            }

            out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 19412
#include <iostream>
#include <algorithm>
#include <list>
#include <map>

using namespace std;
#define lf double
#define ll long long int
#define map unordered_map
#define f(i, n) for (ll i = 0; i < n; i++)

ll s(string c)
{
    f(i, c.length())
    {
        if ((i + 1) % 2 == 0 && c[i] == 'R')
            return 0;
        if ((i + 1) % 2 != 0 && c[i] == 'L')
            return 0;
    }
    return 1;
}

int main()
{
    // ios::ios_base::sync_with_stdio(0);
    // ll tc;
    // cin >> tc;

    string c;
    cin >> c;
    printf("%s", s(c) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 888
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 #include <functional>
 using namespace std;

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

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

vector<int> DiameterPath(const vector<vector<int>> &g) {//直系のパスを返す（g.front()からg.bavk()まで）
       int n = g.size();
       if (n == 1) return vector<int> { 0 };
       //startから最も離れた頂点を求める
       auto farthest = [&](int start) {
               vector<int> depth(n);
               function<void (int, int, int)> get_depth = [&](int u, int prev, int d) {
                       depth[u] = d;
                       for (auto v : g[u]) if (v != prev) {
                               get_depth(v, u, d + 1);
                       }
               };
               get_depth(start, -1, 0);
               int maxd = 0;
               int res = 0;
               for (int i = 0; i < n; i ++) {
                       if (depth[i] > maxd) {
                               maxd = depth[i];
                               res = i;
                       }
               }
               return res;
       };
       //両端を決める
       int s = farthest(0);
       int t = farthest(s);
       //パスを構築する
       vector<int> diameter_path;
       function<void (int, int, vector<int> &)> construct = [&](int u, int prev, vector<int> &path) {
               if (u == t) {
                       diameter_path = path;
                       return;
               }
               for (auto v : g[u]) if (v != prev) {
                       path.push_back(v);
                       construct(v, u, path);
                       path.pop_back();
               }
       };
       vector<int> tmp;
       tmp.push_back(s);
       construct(s, -1, tmp);
       return diameter_path;
}


int main(){
	int n;
	cin>>n;
	vector<pii> v;
	vector<vector<int>> g=vector<vector<int>>(n,vector<int>());
	FOR(i,0,n-1){
		int a,aa;
		cin>>a>>aa;
		a--;
		aa--;
		v.PB(MP(a,aa));
		g[a].PB(aa);
		g[aa].PB(a);
	}
	if(n==1||n==3){
		cout<<"First"<<endl;
		return 0;
	}else if(n==2){
		cout<<"Second"<<endl;
		return 0;
	}
	vector<int> vd=DiameterPath(g);
	int t=vd.size()-1;
	cerr<<t<<endl;
	if(((t-1)%3)==0){
		cout<<"Second";
	}else{
		cout<<"First";
	}

  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(n);
   for(int i=0;i<m*2;i++){
      int tmp;
      cin >> tmp;
      a[tmp-1]++;
   }
   for(int i=0;i<n;i++){
      cout << a[i] << endl;
   }
   return 0;
}

Measured memory_bytes: 256
//By Zank100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define din(t) long long t;cin>>t;
#define in(t) cin>>t;
#define full(t) t.begin(),t.end()
ll mul(ll a, ll b)
{
    return(((a%mod)*(b%mod))%mod);
}
ll modexp(ll b, ll e){
	ll res = 1;
	for(; e; b = b * b % mod, e >>= 1) if(e & 1) res = res * b % mod;
	return res;
}
ll modinv(ll a){
    ll x=mod-2;
	return modexp(a,x);
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	din(l);din(r);din(d);
	ll ans=0;
	for(ll i=l;i<=r;i++)if(i%d==0)ans++;
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
char s[10][10];
int main()
{
    int h,w,flag=1;
    cin >> h >> w;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin >> s[i][j];
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(s[i][j]=='#' && ((s[i-1][j]=='.' && s[i][j-1]=='.') || (s[i+1][j]=='#' && s[i][j+1]=='#')))
            {
                flag=0;
                break;
            }
        }
        if(!flag)
        {
            break;
        }
    }
    if(flag)
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
    return 0;
}


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

const int N = 2e5 + 5;
int k, n, a[N], fp = 1e6;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> k >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	fp = min(fp, min(k - a[2] + a[1], a[n] - a[1]));
	fp = min(fp, k - a[n] + a[n - 1]);
	for(int i = 2; i < n; ++i) {
		fp = min(fp, min(k - a[i + 1] + a[i], k - a[i] + a[i - 1]));
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]
a.append(-1)
ans = 0

while max(a):
    max_a = max(a)
    i = 0
    while i < n and i >= 0:
        if a[i] == max_a:
            a[i] -= 1
            while a[i+1] == max_a:
                i += 1
                a[i] -= 1
            ans += 1
        i += 1
print(ans)

            

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

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

int main() {
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cassert>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds; 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX
const int N=2e5+5;
const int M=1e9+7;

vector<int> v[N];
int val[N];

void solve(){
	int n,m;
	sfi(n) sfi(m)

	f(i,1,n+1){
		sfi(val[i])
	}

	f(i,0,m){
		int x,y;
		sfi(x) sfi(y)

		v[x].push_back(val[y]);
		v[y].push_back(val[x]);
	}

	int ans=0;

	f(i,1,n+1){
		if(v[i].empty()){
			ans++;
		}
		else{
			int num=*max_element(v[i].begin(),v[i].end());
			if(val[i]>num){
				ans++;
			}
		}
	}

	pfin(ans)
}



int main(){	
	
	solve();
	return 0;	
}

Measured memory_bytes: 11692
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
#define ld long double
 
using namespace std;
 
const int N = 1e5 + 12;
const ll mod = 1e9 + 7;

int n, m, gg[N];
vector<int> g[N], a, b;

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
    	int x;
    	cin >> x;
    	gg[i] = x;
    	g[(x & 1)].push_back(-x);
    }

    if(m == 1){
    	if(gg[1] == 1){
    		cout << "1\n1\n1";
    	}            
    	else{
    		cout << gg[1] << "\n";
    		cout << "2\n";
    		cout << gg[1] - 1 << " " << 1;
    	}
    	return 0;
    }
    if(m == 2){
    	cout << gg[1] << " " << gg[2] << "\n";
    	
    	if(min(gg[1], gg[2]) == 1){
    		cout << "1\n" << gg[1] + gg[2];
    		return 0;
    	}
    	
    	cout << "2\n";
    	cout << gg[1] - 1 << " " << gg[2] + 1;
    	return 0;
    }

    sort(g[0].begin(), g[0].end());
    sort(g[1].begin(), g[1].end());

    if(g[1].size() > 2){
    	cout << "Impossible";
    }
    else{
    	if(g[1].size() >= 1){
    		a.push_back(-g[1][0]);
    	}
    	for(int u: g[0]){
    		a.push_back(-u);
    	}
    	if(g[1].size() == 2){
    		a.push_back(-g[1][1]);
    	}

    	for(int i = 0;i < (int)a.size();i++){
    		if(i == 0){
    			b.push_back(a[i] - 1);
    		}
    		else{
    			if(b.back() == 0){
    				b.pop_back();
    			}
    			b.push_back(a[i]);
    		}
    	}
    	b[(int)b.size() - 1] += 1;

    	for(int u: a){
    		cout << u << " ";
    	}
    	cout << "\n" << b.size() << "\n";
    	for(int u: b){
    		cout << u << " ";
    	}
    }
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int C[110][110];

int main() {
	int N, M;
	vector<pair<pii,int> > v;
	rep(i,110) {
		rep(j,110)
			C[i][j] = 1e9;
		C[i][i] = 0;
	}
	cin >> N >> M;
	v.resize(M);
	rep(i,M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		C[a][b] = C[b][a] = c;
		v[i].fi = pii(a,b);
		v[i].se = c;
	}
	rep(i,N)
		rep(j,N)
			rep(k,N)
				C[j][k] = min(C[j][k], C[j][i] + C[i][k]);
	int res = 0;
	rep(i,M) {
		bool f = true;
		int a, b, c;
		a = v[i].fi.fi; b = v[i].fi.se;
		c = v[i].se;
		rep(j,N) {
			rep(k,N) {
				rep(l,2) {
					if(C[j][a] + C[b][k] + c == C[j][k])
						f = false;
					swap(a,b);
				}
			}
		}
		if(f) res++;
	}
	cout << res << endl;
	return 0;
}


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

typedef long long ll;

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}

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

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

Measured memory_bytes: 1156
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    long long i,j;
    long long n,a,b;

    scanf("%lld %lld %lld",&n,&a,&b);

    if((b - a) % 2 == 0)
    {
        printf("%lld",(b - a) / 2);
    }
    else
    {
        if(a - 1 <= n - b)
        {
            printf("%lld",a + (b - a - 1) / 2);
        }
        else
        {
            printf("%lld",n - b + 1 + (b - a - 1) / 2);
        }
        
    }
    
}


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



int main() {
    ll H;
    ll ans=1;
    ll cnt = 1;
    cin >> H;
    
    while(H > 1){
        H /= 2;
        cnt ++;
        //cout << H << " " << cnt << endl;
    }
    
    for(int i=0;i<cnt;i++){
        ans *=2;
    }
    ans--;
    
    
    
    cout << ans << endl;
    
}


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

using namespace std;

#define INF (1<<29)
typedef vector<int> Vec;
typedef vector<Vec> Graph;

int minimum_steiner_tree(Graph &d, Vec &heart)
{
    int N = d.size(), T = heart.size();
    if (T <= 1) return T;
    
    int dp[1<<T][N];
    for (int i = 0; i < (1<<T); i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = INF;
        }
    }

    for (int i = 0; i < T; i++) {
        for (int j = 0; j < N; j++) {
            dp[1<<i][j] = d[heart[i]][j];
        }
    }

    for (int i = 1; i < (1<<T); i++) {
        if (!(i & (i - 1))) continue;
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < i; k++) {
                if ((i | k) == i) {
                    dp[i][j] = min(dp[i][j], dp[k][j] + dp[i-k][j]);
                }
            }
        }
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + d[j][k]);
            }
        }
    }
    int res = INF;
    for (int i = 0; i < (1<<T); i++) {
        for (int j = 0; j < N; j++) {
            res = min(res, dp[i][j] + dp[((1<<T)-1)-i][j]);
        }
    }
    return res + 1;
}

int get_dist(int y1, int x1, int y2, int x2)
{
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    int H, W, x;
    while (cin >> H >> W, H) {
        Vec heart;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> x;  
                if (x == 1) {
                    heart.push_back(i * W + j);
                }
            }
        }

        Graph G(H*W, Vec(H*W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                for (int k = 0; k < H; k++) {
                    for (int l = 0; l < W; l++) {
                        G[i*W+j][k*W+l] = get_dist(i, j, k, l);
                    }
                }
            }
        }
        cout << H*W - minimum_steiner_tree(G, heart) << endl;
    }
    return 0;
}

Measured memory_bytes: 1340
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] v = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Dictionary<int, int> d1 = new Dictionary<int, int>();
        Dictionary<int, int> d2 = new Dictionary<int, int>();
        List<int> v1 = new List<int>();
        List<int> v2 = new List<int>();
        for (int i = 0; i < v.Length; i++)
        {
            var d = i % 2 == 0 ? d1 : d2;
            if (!d.ContainsKey(v[i])) d.Add(v[i], 0);
            d[v[i]]++;
        }
        var sorted1 = d1.OrderByDescending(x => x.Value).ToList();
        var sorted2 = d2.OrderByDescending(x => x.Value).ToList();
        sorted1.Add(new KeyValuePair<int, int>(-1, 0));
        sorted2.Add(new KeyValuePair<int, int>(-1, 0));
        var count = sorted1[0].Value + sorted2[0].Value;
        if (sorted1[0].Key == sorted2[0].Key)
        {
            count = Max(sorted1[0].Value + sorted2[1].Value, sorted1[1].Value + sorted2[0].Value);
        }
        Console.WriteLine(n - count);
    }
}

Measured memory_bytes: 26848
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {

	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);

	rep(i, N) {
		cin >> A[i]; 
		B[i] = A[i];
	}
	sort(A.begin(),A.end());

	int c = 0;

	rep(i, N) {

		if (B[i] != A[N - 1]) {
			cout << A[N - 1] << endl;
		}
		else cout << A[N - 2] << endl;

	}
	return 0;
}

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

ll gcd(ll x, ll y)
{
    if (x > y) swap(x, y);
    if (y % x == 0) return x;
    return gcd(x, y % x);
}

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

    ll times[n];
    rep(i, 0, n) cin >> times[i];


    ll ans = times[n - 1];
    rep(i, 0, n - 1)
        ans = ans * (times[i] / gcd(ans, times[i]));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int s1,s2,m,x;
int main()
{
	cin>>s;
	s1=(int)(s[0]-'0')*10+(int)(s[1]-'0');
	s2=(int)(s[2]-'0')*10+(int)(s[3]-'0');
	//cout<<s1<<" "<<s2;
	if(s1>0 && s1<=12)
	{
		m++;
		x=1;
	}
	if(s2>0 && s2<=12)
	{
		m++;
		x=2;
	}
	if(m==2)
	{
		cout<<"AMBIGUOUS";
	}
	else
	  if(m==1)
	  {
	  	if(x==1)
	  	  cout<<"MMYY";
	  	else
	  	  cout<<"YYMM";
	  }
	  else
	    cout<<"NA";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int a, b, c, k;

int main()
{
    cin >> a >> b >> c >> k;

    set<int> st;
    for(int k1 = 0; k1 <= k; k1++){
        for(int k2 = 0; k2 <= k - k1; k2++){
            int k3 = k - (k1 + k2);
            ll val = a * pow(2, k1) + b * pow(2, k2) + c * pow(2, k3);
            st.insert(val);
        }
    }
    vi vec(all(st));
    sort(all(vec), greater<int>());
    cout << vec[0] << endl;

    return 0;

}

Measured memory_bytes: 256
<?php
list($K) = ints();
$sum6 = 0;
for($i = 1; $i <= $K; ++$i)
for($j = 1; $j <= $K; ++$j)
$memo[$i][$j] = $memo[$j][$i] = (int)gcd($i, $j);

for($i = 1; $i <= $K; ++$i)
for($j = $i+1; $j <= $K; ++$j){
    $mij = $memo[$memo[$i][$j]];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$mij[$k];
}

for($i = 1; $i <= $K; ++$i){
  $mi = $memo[$i];
  for($j = $i+1; $j <= $K; ++$j)
    $sum6+=$mi[$j];
}

echo $sum6*6+$K*($K+1)/2;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 18968
import sys
K = int(sys.stdin.readline())

def cands():
    d = 1
    res = []
    res.extend(range(1, 1000))
    for d in range(3, 16):
        y = 10 ** (d-2)
        z = y - 1
        r = map(lambda x: x * y + z, range(100, 1000))
        res.extend(r)
    return res


def S(m):
    res = 0
    while m > 0:
        res += m % 10
        m //= 10
    return res

def is_snuke(i_s_i, m):
    return i_s_i <= m

ss = []
cs = cands()
for i in cs:
    s_i = S(i)
    ss.append((i, s_i, i / s_i))

m = float('inf')
ms = []
for _, _, i_s_i in reversed(ss):
    m = min(m, i_s_i)
    ms.append(m)
ms = list(reversed(ms))

res = 0
for (i, s_i, i_s_i), m in zip(ss, ms):
    b = is_snuke(i_s_i, m)
    if b:
        print(i)
        res += 1
    if K <= res:
        break


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

const int N = 100005;

int n;
char s[N];

int main() {
    scanf("%s", s);
    n = strlen(s);
    int b = 0, result = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'g') {
            if (b > 0) ++result, --b;
            else ++b;
        } else {
            if (b > 0) --b; else --result, ++b;
        }
    }
    cout << result << endl;
    return 0;
}


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

int main() {
  int n;
  while(cin >> n && n) {
    int a[n][n];
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) cin >> a[i][j];
    }
    int b[n];
    fill(b,b+n,0);
    for(int i=0; i<n; i++) {
      int sum=0;
      for(int j=0; j<n; j++) {
	printf("%5d",a[i][j]);
	sum+=a[i][j];
	b[j]+=a[i][j];
      }
      printf("%5d\n",sum);
    }
    int sum=0;
    for(int i=0; i<n; i++) {
      printf("%5d",b[i]);
      sum+=b[i];
    }
    printf("%5d\n",sum);
  }
  return 0;
}


Measured memory_bytes: 1160
import java.util.*;

fun main(args: Array<String>){
  val sc = Scanner(System.`in`)
  var day = sc.nextInt()
  if(day == 25){
    println("Christmas")
  }
  else if(day == 24){
    println("Christmas Eve")
  }
  else if(day == 23){
    println("Christmas Eve Eve")
  }
  else{
    println("Christmas Eve Eve Eve")
  }
}

Measured memory_bytes: 29348
#include <iostream>


main() {
        int x[10000], i, num;

        num = 0;
        while( 1==1 ){
                std::cin >> x[num];
                if( x[num] == 0 ) break;
                num++;
        }
        for( i=0; i<num; i++ ){
             std::cout << "Case " << i+1 << ": " << x[i] << std::endl;
        }
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
    
    
  int main(){
      COMinit();
      lint n,k;
      cin>>n>>k;
      repp(i,1,k+1){
         lint ans= COM(n-k+1,i)*COM(k-1,i-1);
         ans%=MOD;
         cout<<ans<<endl;
      }
  }
     
  


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n; cin >> n;
  string s, t;
  cin >> s >> t;
  int ans = 2*n;
  for(int i = 1; i <= n; ++i) {
    if(s.substr(n-i, i) == t.substr(0, i)) chmin(ans, 2*n-i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3572