akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main()
{
	unsigned int n, k;
	std::cin >> n >> k;

	if ( n == k )
	{
		// NとKが等しければ1回で終わり
		std::cout << "1" << std::endl;
	}
	else
	{
		if ( ( n - 1 ) % ( k - 1 ) )
		{
			// 余りが出るなら切り上げる
			std::cout << ( ( n - 1 ) / ( k - 1 ) ) + 1 << std::endl;
		}
		else
		{
			std::cout << ( n - 1 ) / ( k - 1 ) << std::endl;
		}
	}

	return ( 0 );
}


Measured memory_bytes: 888
def examA():
    S = SI()
    F = "FESTIVAL"
    ans = S[:-(len(F))]
    print(ans)
    return

def examB():
    N = I()
    d = defaultdict(int)
    D = LI()
    for t in D:
        d[t] +=1
    M = I()
    T = LI()
    for t in T:
        if d[t]==0:
            print("NO")
            return
        d[t] -=1
    print("YES")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 48196
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> s;
	ll res = 0;
	rep(i, s.size()) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			ll cnt = 0;
			for (ll j = i; j < s.size(); j++) {
				if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
					++cnt;
				}
				else {
					chmax(res, cnt);
					break;
				}
			}
			chmax(res, cnt);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
using namespace std;

long long inline mul_mod(long long l, long long r, long long mod) {
	return ((l % mod) * (r % mod)) % mod;
}

long long fact_mod(long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		res = mul_mod(res, n, mod);
		--n;
	}
	return res;
}

long long power_mod(long long x, long long y, long long mod) {
	if (y == 0)return 1;
	if (y == 1)return x % mod;
	auto res = power_mod(x, y / 2, mod);
	if (y % 2 == 0)return (res * res) % mod;
	return ((res * res) * x) % mod;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long div_mod(long long l, long long r, long long mod) {
	return mul_mod(l, modinv(r, mod), mod);
}

long long ncr_mod(long long n, long long r, long long mod) {
	return div_mod(fact_mod(n, mod), mul_mod(fact_mod(n - r, mod), fact_mod(r, mod), mod), mod);
}

int main()
{
	cout << fixed << setprecision(6);
	int n, k;
	cin >> n >> k;

	int rNum = n - k;
	long long mod = 1000000007LL;
	for (int i = 1; i <= k; ++i) {
		//赤玉の間rNum + 2箇所中i箇所に青玉を置く -> i回操作する
		// (rNum + 1)Ci * (k - 1)C(i - 1)
		// ただしl < r -> 0(不可)
		if (rNum + 1 < i || k < i)cout << 0 << endl;
		else {
			cout << mul_mod(ncr_mod(rNum + 1, i, mod), ncr_mod(k - 1, i - 1, mod), mod) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        r,n = LI()
        if r == 0 and n == 0:
            break
        a = [LI() for _ in range(n)]
        d = collections.defaultdict(int)
        for xl,xr,h in a:
            for x in range(xl,xr):
                if d[x] < h:
                    d[x] = h
        tr = inf
        r2 = r**2
        for x in range(-r,r):
            h = d[x]
            k = min(abs(x), abs(x+1))
            t = (r2 - k**2) ** 0.5
            xr = r - t + h
            if tr > xr:
                tr = xr

        rr.append('{:0.9f}'.format(tr))

    return '\n'.join(map(str,rr))


print(main())




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

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

const ll MOD = 1'000'000'007;

ll inv(ll x) {
	ll pow = MOD - 2;
	ll res = 1;

	while (pow > 0) {
		if (pow & 1) {
			res = res * x % MOD;
		}

		pow /= 2;
		x = x * x % MOD;
	}

	return res;
}

ll suff[400'000];
ll pref[400'000];

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

	int n, k;
	cin >> n >> k;

	for (int i = n; i >= 0; i--) {
		suff[i] = i + (i == n ? 0 : suff[i + 1]);
		suff[i] %= MOD;
	}

	pref[0] = 0;

	for (int i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + i;
		pref[i] %= MOD;
	}

	ll res = 0;

	for (int i = k; i <= n + 1; i++) {
		res = (res + suff[n - i + 1] - pref[i - 1] + 1 + MOD) % MOD;
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

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

    int count = 1;
    int flag = 0;
    if (N >= 3) {
        for (int i = 1; i < N; i++) {
            if (A[i] > A[i-1]) {
                if (flag == 0) {
                    flag = 1;
                } else if (flag == -1) {
                    flag = 0;
                    count++;
                }
            } else if (A[i] < A[i-1]) {
                if (flag == 0) {
                    flag = -1;
                } else if (flag == 1) {
                    flag = 0;
                    count++;
                }
            }
        }
    }

    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
const int MAXN=2e5+5;
int a[MAXN];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;++i)   
        {
            cin>>a[i];
        }
        if(n&1)
        {
            cout<<a[n];
            for(int i=n-2;i>=1;i-=2)
                cout<<" "<<a[i];
            for(int i=2;i<=n-1;i+=2)
                cout<<" "<<a[i];
            cout<<endl;
        }else
        {
            cout<<a[n];
            for(int i=n-2;i>=2;i-=2)
                cout<<" "<<a[i];
            for(int i=1;i<=n-1;i+=2)
                cout<<" "<<a[i];
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2944
until(n,m=gets.split.map(&:to_i))==[0,0]do
r,p,a=[],[],[]
n.times{r<<gets.gsub("?",".").split}
m.times{p<<gets.split}
p.each{|p|r.reverse.each{|r|if p[0]=~/#{r[1]}/&&p[1]=~/#{r[2]}/
a<<p*" "if r[0]=~/p/
break
end}}
puts a.size,a
end

Measured memory_bytes: 9276
function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n = Number(stdin.shift());
    const A = stdin.shift().split(' ').map(Number);

    const b = countingSort(A, n);
    console.log(b.join(' '));
}

function countingSort(A, n) {
    const b = [];
    let mx = 0;
    for (let i = 0, l = A.length; i < l; i++) {
        mx = mx < A[i] ? A[i] : mx;
    }
    const c = new Array(mx + 1).fill(0);

    for (const item of A) {
        c[item]++;
    }
    for (let i = 1, l = c.length; i < l; i++) {
        c[i] = c[i - 1] + c[i];
    }
    let temp = n - 1;
    while(temp > -1) {
        b[c[A[temp]]] = A[temp];
        c[A[temp]]--;
        temp--;
    }
    b.shift();
    return b;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 263164
<?php
// 整数の入力
fscanf(STDIN, "%d", $n);

$num = floor($n / 111);

//ちょうど111の倍数の時はすぐに参加する
if ($n % 111 === 0) {
  $num -= 1;
}

echo 111 * ($num + 1);

?>


Measured memory_bytes: 3828
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    
    const temp = N / 1.08;
    
    // console.log(temp)
    
    const floor = Math.floor(temp * 1.08);
    const ceil  = Math.ceil(temp) * 1.08;
    
    // console.log(999 * 1.08)
    if(floor === N) {
        // console.log(Math.floor(temp))
        if(Math.floor(temp) * 1.08 === N) {
            console.log(Math.floor(temp))
        } else if(Math.floor(Math.ceil(temp) * 1.08) === N) {
            console.log(Math.ceil(temp))
        } else {
            console.log(":(")
        }
    } else {
        console.log(":(")
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = Integer.parseInt(sc.next());
		int R = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int count = 0;

		for(int i=L;i<=R;i++) {
			if(i%d==0)count++;
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 27008
# B - Trick or Treat
def main():
    N, K = map(int, input().split())
    has_snacks = set()
    for _ in range(K):
        _ = input()
        has_snacks |= set(map(int, input().split()))
    print(N - len(has_snacks))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9112
use proconio::*;
use proconio::marker::*;

type Link = Option<Box<Node>>;

#[derive(Default)]
struct Node {
    cnt: u32,
    next: [Link; 26],
}

fn insert(node: &mut Link, s: &[u8]) {
    if node.is_none() {
        *node = Some(Box::new(Node::default()));
    }
    let node = node.as_mut().unwrap();
    node.cnt += 1;
    if s.len() > 0 {
        let k = (s[0] - b'a') as usize;
        insert(&mut node.next[k], &s[1..]);
    }
}

fn dfs(node: &Link, s: &[u8], add: &mut u32, cnt: &mut [[u32; 26]]) {
    let node = node.as_ref().unwrap();
    let sum = node.next.iter().fold(0, |s, p| s + p.as_ref().map_or(0, |p| p.cnt));
    *add += node.cnt - sum;
    if s.len() > 0 {
        let k = (s[0] - b'a') as usize;
        for (cnt, next) in cnt[k].iter_mut().zip(node.next.iter()) {
            *cnt += next.as_ref().map_or(0, |p| p.cnt);
        }
        dfs(&node.next[k], &s[1..], add, cnt);
    }
}

#[fastout]
fn run() {
    input! {
        n: usize,
        s: [Bytes; n],
        q: usize,
        ask: [(Usize1, Bytes); q],
    }
    let mut root = None;
    for s in s.iter() {
        insert(&mut root, s);
    }
    let mut memo = vec![];
    for s in s.iter() {
        let mut cnt = [[0; 26]; 26];
        let mut add = 0;
        dfs(&root, s, &mut add, &mut cnt);
        memo.push((add, cnt));
    }
    for (k, ask) in ask {
        let memo = &memo[k];
        let mut ans = memo.0;
        for i in 1..26 {
            let a = (ask[i] - b'a') as usize;
            for j in 0..i {
                let b = (ask[j] - b'a') as usize;
                ans += memo.1[a][b];
            }
        }
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 309428
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,current = 0;
    cin>>n;
    vector<P> c(n);
    for(int i=0;i<n;i++)
        cin>>c[i].first>>c[i].second;
    sort(c.begin(),c.end(),[](P a,P b){return a.second<b.second;});
    for(int i=0;i<n;i++){
        if(current + c[i].first > c[i].second)
        {
            cout<<"No"<<endl;
            return 0;
        }
        current += c[i].first;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
ans = 0
for i in range(n-1):
    if A[i+1] < A[i]:
        A[i+1] += (A[i] - A[i+1])
        ans += (A[i+1] - B[i+1])
print(ans)

Measured memory_bytes: 32192
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>

using namespace std;

int main(int argc, char const* argv[])
{
    int table_count=0;
    char key,value;

    while ( 1 ) 
    {
        /* ---  読み込み --- */
        cin >> table_count;
        if ( table_count == 0 ) { return 0; };
        //
        //cout << "table_count" << table_count << endl;

        map<char, char> map;
        for (int i = 0; i < table_count; i++) 
        {
            //cout << i << ": ";
            cin >> key; 
            cin >> value; 
            map[key] = value; 
            //
            //cout << key << " " << value << endl;
        }
        
        /* ---  出力 --- */
        int char_count;
        cin >> char_count;
        //scanf("%d\n", &char_count);
        //
        //cout << "char_count :" << char_count << endl;
        for (int i = 0; i < char_count; i++) 
        {
            //
            //cout << i << " :";
            char tmp_char;
            cin >> tmp_char;
            
            if ( map.find(tmp_char) == map.end() ) 
            {
                cout << tmp_char;
            } 
            else 
            {
                cout << map[tmp_char];
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	x := make([]int, M)
	y := make([]int, M)
	for i := 0; i < M; i++ {
		x[i], y[i] = getInt()-1, getInt()-1
	}

	a := make([]bool, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		b[i] = 1
	}
	a[0] = true
	for i := 0; i < M; i++ {
		f := x[i]
		t := y[i]
		if b[f] == 1 {
			a[t] = a[t] || a[f]
			a[f] = false
		} else {
			a[t] = a[t] || a[f]
		}
		b[f]--
		b[t]++
		// out(a)
	}
	// out(a)
	ans := 0
	for i := 0; i < N; i++ {
		if a[i] {
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  string n;
  cin >> n;
  rep(i, n.size()) {
    if (n[i] == '1') cout << "9";
    else if (n[i] == '9') cout << "1";
    else cout << n[i];
  }
  cout << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

void solve() {
    int s;
    cin >> s;

    int i = 1;
    vector<int> a;
    a.push_back(s);
    //cout << "0: " << s << endl;
    while(true){
        int tmp;
        if(a[i-1] % 2 == 0){
            tmp = a[i-1]/2;
        } else {
            tmp = 3*a[i-1]+1;
        }
        //cout << i << ": " << tmp << endl;
        auto it = find(a.begin(), a.end(), tmp);
        if(it != a.end()){
            cout << i+1 << endl;
            break;
        } else {
            a.push_back(tmp);
            i++;
        }
    }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vector<ll> v;

void dfs(ll a, int d){
	if(d == 0){
	 	v.EB(a);
		// DEBUG("%lld\n", a);
	} else {
		int k = a%10;
		if(0 <= k-1) dfs(a * 10 + (k-1), d-1);
		dfs(a * 10 + k, d-1);
		if(k+1 <= 9) dfs(a * 10 + (k+1), d-1);
	}
}

int main(){
	int k; scanf("%d", &k); k--;
	for(int i = 0; (int)v.size() <= k; i++) FOR(j, 1, 10) dfs(j, i);
	sort(ALL(v));
	printf("%lld\n", v[k]);
}


Measured memory_bytes: 2420
X, Y = map(int, input().split())
result = 0
if X <= 3:
    result += 10**5 * (4 - X)
if Y <= 3:
    result += 10**5 * (4 - Y)
if X == 1 and Y == 1:
    result += 10**5 * 4
print(result)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int[] KV=new int[100001];
	    int[] GV=new int[100001];
	    int[] V= new int[N];

        for(int i=0; i<N;i++) {
        	int a=gi();
        	V[i]=a;
        	if((i+1)%2==1) {
        		KV[a]++;
        	} else {
        		GV[a]++;
        	}
        }

        int mki=0;
        int mgi=0;
        int mk=0;
        int mg=0;
        for(int i=0; i<100001;i++) {
        	int kv = KV[i];
        	int gv = GV[i];
        	if(mk<kv) {
        		mk=kv;
        		mki=i;
        	}
        	if(mg<gv) {
        		mg=gv;
        		mgi=i;
        	}
        }

        long ans=0;
        if(mki==mgi) {
        	int mki2=0;
            int mgi2=0;
            int mk2=0;
            int mg2=0;
            for(int i=0; i<100001;i++) {
            	int kv = KV[i];
            	int gv = GV[i];
            	if(mk2<kv && mki!=i) {
            		mk2=kv;
            		mki2=i;
            	}
            	if(mg2<gv && mgi!=i) {
            		mg2=gv;
            		mgi2=i;
            	}
            }
            if(mk2>mg2) {
            	ans=N-mk2-mg;
            } else {
            	ans=N-mk-mg2;
            }
		} else {
			ans = N-KV[mki] -GV[mgi];
		}


	    System.out.print(ans);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main() {
    string S;
    cin>>S;
    if(S.size()==2){
        cout<<S<<endl;
    }else{
        cout<<S.at(2)<<S.at(1)<<S.at(0)<<endl;
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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; }

vector<bool> eratosthenes(const int N)
{
    vector<bool> isPrime(N + 1, true);

    isPrime[0] = isPrime[1] = false;

    for (int i = 2; i <= N; i++)
    {
        if (isPrime[i])
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                isPrime[j] = false;
            }
        }
    }

    return isPrime;
}

int main()
{	
	const int N = 100000;

	vector<ll> A(N + 1);

    auto primes = eratosthenes(N);

	reple(i, 1, N)
	{
        A[i] = A[i - 1];

        if (primes[i] && primes[(i + 1) / 2]) A[i]++;
	}


    int Q;
    cin >> Q;

    rep(i, Q)
    {
        int l, r;
        cin >> l >> r;

        cout << A[r] - A[l - 1] << endl;
    }

	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long  n, a, b, c, x;
	
	while (1) {
		cin >> n >> a >> b >> c >> x;
		if (!n) break;
		vector<int> y(n);
		REP(i, n) {
			cin >> y[i];
		}
		int j = 0;
		REP(i, 10001) {
			if (y[j] ==x) {
				if (j == n - 1) {
					cout << i << endl;
					break;
				}
				else {
					++j;
				}
			}
			if (i == 10000) cout << -1 << endl;
			x = (a*x + b) % c;
		}
	}
	return 0;

}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


int main(){
    LL t1,t2,a1,a2,b1,b2;cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    LL v1 = a1 * t1 + a2 * t2, v2 = b1 * t1 + b2 * t2;
    if(v1==v2){
        puts("infinity");
        return 0;
    }
    if(v1 < v2){
        swap(v1,v2);
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a1 > b1){
        puts("0");
        return 0;
    }
    LL l = t1 * (b1 - a1) / (v1 - v2);
    LL ans = 2 * l + 1;
    if(l > 0){
        LL k1 = (v1-v2)*l+a1*t1, k2 = b1*t1;
        if(k1==k2) ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e) != (s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)

#define F first
#define S second

int bit_count(int n) {
	int ans = 0;
	while(n) {
		ans += n & 1;
		n >>= 1;
	}
	return ans;
}

int main()
{
	int N, M; cin >> N >> M;
	vector< vector<double> > dist(N, vector<double>(N, -1));
	vector< pair<double, pair<double, double> > > colors;
	REP(i, N) {
		double l, a, b; cin >> l >> a >> b;
		colors.push_back(make_pair(l, make_pair(a, b)));
	}
	REP(i, N) {
		REP(j, N) {
			pair<double, pair<double, double> > c1, c2;
			c1 = colors[i], c2 = colors[j];
			dist[i][j] = dist[j][i] = (pow(c1.F - c2.F, 2) + pow(c1.S.F - c2.S.F, 2) + pow(c1.S.S - c2.S.S, 2));
		}
	}
	double ans = 0;
	for(ull i = 0; i < 1 << 20; ++i) {
		if(bit_count(i) != M) continue;
		vi picked;
		REP(j, N) {
			if(i & (1 << j)) picked.push_back(j);
		}
		double t_dist = 0;
		for(vi::iterator it_i = picked.begin(); it_i != picked.end(); ++it_i) {
			for(vi::iterator it_j = picked.begin(); it_j != picked.end(); ++it_j) {
				t_dist += dist[*it_i][*it_j];
			}
		}
		ans = max(ans, t_dist / 2.0);
	}
	cout.precision(16);
	cout << ans << endl;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n;
    cin>>n;
    vll a(n);
    vll res(1e5+10,0);
    ll sum=0;
    rep(i,0,n)cin>>a[i],res[a[i]]++,sum+=a[i];
    ll q;
    cin>>q;
    rep(i,0,q){
        ll b,c;
        cin>>b>>c;
        sum-=b*res[b];
        res[c]+=res[b];
        sum+=res[b]*c;
        res[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}




Measured memory_bytes: 4760
require 'set'
dp=Set.new [0]
gets.to_i.times do
  s=gets.to_i
  nex=dp.dup
  dp.each do |i|
    nex.add(i+s)
  end
  dp=nex
end
p dp.map{|i|i%10==0 ? 0 : i}.max


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

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

  while (1) {
    if ((N / 100) == (N / 10) % 10 && (N / 10) % 10 == N % 10) {
      break;
    }
    N++;
  }

  printf("%d", N);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    cin >> n;
    vector<LL> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    LL ans=1;
    vector<LL> rgb(3, 0);
    for(int i=0; i<n; i++){
        LL tmp=0;
        for(int j=0; j<3; j++){
            if(a[i]==rgb[j]){
                tmp++;
            }
        }
        ans=ans*tmp;
        ans=ans%MOD;
        for(int j=0; j<3; j++){
            if(a[i]==rgb[j]){
                rgb[j]++;
                break;
            }
        }
    }

    //for(int i=0; i<3; i++){
    //    cout << rgb[i] << endl;
    //}

    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<vector<ll>> one(60,vector<ll>(n,0)),zero(60,vector<ll>(n,0));
for(int i=0;i<60;i++){
  for(int j=0;j<n-1;j++){
           if(a[j]&(1ll<<i)){
             one[i][j+1]+=one[i][j]+1;
             zero[i][j+1]+=zero[i][j];
           }
           else {
             one[i][j+1]+=one[i][j];
             zero[i][j+1]+=zero[i][j]+1;
           }
  }
}
ll ans=0;
for(int i=0;i<60;i++){
  ll now=(1LL<<i);
  now%=mod;
  for(int j=1;j<n;j++){
           if(a[j]&(1ll<<i))(ans+=now*zero[i][j]%mod)%=mod;
           else (ans+= now*one[i][j]%mod)%=mod;
  }
}
cout<<ans<<endl;
}



Measured memory_bytes: 286168
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 h;
    cin >> h;

    int cnt = 0;
    while(h != 0) h/=2, cnt++;

    int64 ans = exp2(cnt) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 888
def cookie(a, b, n):
    
    if a >= n:
        return [a-n, b]
    elif n < a+b:
        
        return[0, b-(n-a)]
    else:
        return [0, 0]

if __name__ == "__main__":
    a, b, n = map(int, input().split())
    j = cookie(a, b, n)
    print(j[0], j[1])



Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	if(s[0]>s[1]||(s[0]==s[1]&&s[1]>=s[2]))
		cout<<s[0]<<s[0]<<s[0];
	else
	{
		int a=s[0]-'0';
		cout<<a+1<<a+1<<a+1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#define MAX_N (200000)

using namespace std;

typedef pair<int,int> P;
P points[MAX_N];
P sortedX[MAX_N];
P sortedY[MAX_N];
int cX[MAX_N];
int cY[MAX_N];

int cmp(const P& p1, const P& p2) {
  return p1.second > p2.second;
}
struct SegmentTree {
  int Storage[MAX_N*8];
  int N;
  void init(int n) {
    N=1;
    while(N<n) N*=2;

    for(int i=0;i<N*2;++i) {
      Storage[i]=0;
    }
  }

  void updateLeaf(int i, int value) {
    i += N-1;
    Storage[i]=value;
    while(i>0) {
      i = (i-1) / 2;
      Storage[i] = max(Storage[i*2+1], Storage[i*2+2]);
    }
  }

  int calcRangeGCD(int a,int b,int k,int l, int r) {
    if(b<=l || a>=r) return 0;
    if(a<=l && b>=r) {
      return Storage[k];
    } else {
      int tl = calcRangeGCD(a,b,k*2+1,l,(l+r)/2);
      int tr = calcRangeGCD(a,b,k*2+2,(l+r)/2,r);
      return max(tl,tr);
    }
  }
};
SegmentTree segmentTree;
int main() {
  int x1,y1,x2,y2;
  int N;
  bool flip=false;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  if (y1>y2) {
    swap(y1,y2);
    swap(x1,x2);
  }
  if (x1>x2) {
    flip=true;
    x1= (1000 * 1000 * 100 - 1) - x1;
    x2= (1000 * 1000 * 100 - 1) - x2;
  }
  scanf("%d", &N);
  int subN=0;
  for(int i=0;i<N;++i) {
    int X,Y;
    scanf("%d%d", &X, &Y);
    if (flip) {
      X= (1000 * 1000 * 100 - 1) - X;
    }
    if (X>=x1&&X<=x2 && Y>=y1&&Y<=y2) {
      sortedX[subN]=P(X,subN);
      sortedY[subN]=P(Y,subN);
      subN++;
    }
  }
  N=subN;
  sort(sortedX, sortedX+N);
  sort(sortedY, sortedY+N);
  for(int i=0;i<N;++i) {
    P sX=sortedX[i];
    cX[i]=sX.first;
    P sY=sortedY[i];
    cY[i]=sY.first;
    points[sX.second].first=i;
    points[sY.second].second=i;
  }
  sort(points,points+N,cmp);
  segmentTree.init(N);
  for(int i=0;i<N;++i) {
    P p=points[i];
    int m=segmentTree.calcRangeGCD(p.first,N,0,0,segmentTree.N);
    segmentTree.updateLeaf(p.first, m+1);
  }
  int num=segmentTree.calcRangeGCD(0,N,0,0,segmentTree.N);
  bool flag=false;
  if (num==min(x2-x1+1,y2-y1+1)) {
    flag=true;
  }

  long double answer = 0;
  answer += ((x2-x1) + (y2-y1))*100.0;
  answer += (5.0 * M_PI-20.0) * num;
  if (flag) {
    answer -= (5.0*M_PI-20.0);
    answer += (10.0*M_PI-20.0);
  }

  printf("%.20Lf\n", answer);
  return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
   int n;
   int x;
   while(1){
       int max=-1,min=1001;
       int S=0;
       cin>>n;
       if(n==0){
           break;
       }
       for(int i=0;i<n;i++){
            cin>>x;
            if(min>x){
                min=x;
            }
            if(max<x){
                max=x;
            }
           S=S+x;            
       }
       cout<<(S-(max+min))/(n-2)<<endl;
   }
   return 0;
}


Measured memory_bytes: 3092
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    val ans = if (s.last() != 's') s + 's' else s + "es"
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 35760
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double EPS=1e-9;
const long long INF = 100001000010000100ll;

template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


int N;

int d[100000+10];
int dp[100000+10][2];

int main(){

	while(cin >> N, N){
		memset(d, 0 ,sizeof(d));
		memset(dp, 0 ,sizeof(dp));
		rep(i, N){
			int t;
			cin >> t;
			if(i > 0){
				if(i % 2){
					if(dp[i-1][t]==0){
						if(i - dp[i - 1][!t] - 1 >= 0){
							dp[i][t] = dp[i - 1][!t] + dp[i - dp[i - 1][!t] - 1][t] + 1;
							dp[i][!t]=0;
						}else{
							dp[i][t] = dp[i - 1][!t] + 1;
							dp[i][!t]=0;
						}
					}else{
						dp[i][t] = dp[i - 1][t] + 1;
						dp[i][!t] = 0;
					}
				}else{
					dp[i][t] = dp[i - 1][t] + 1;
					dp[i][!t] = 0;
				}
			}else{
				dp[i][t]=1;
			}
			//printf("0:%d 1:%d\n", dp[i][0], dp[i][1]);
		}
		int ans=0;
		int i = N - 1;
		while(i >= 0){
			//cout << i << endl;
			ans+=dp[i][0];
			i -= max(dp[i][0], dp[i][1]);
		}
		cout << ans << endl;
	}

	return 0;

}

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


int main(void){
    // Your code here!
    long long int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k%2 == 0) cout << a-b << endl;
    else cout << b-a << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s,t;cin>>s>>t;
		int a=0,b=0,now=1;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]>='0'&&s[i]<='9')now=s[i]-48;
			else
			{
				a+=now*(s[i]=='m'?1000:s[i]=='c'?100:s[i]=='x'?10:1);
				now=1;
			}
		}
		for(int i=0;i<t.size();i++)
		{
			if(t[i]>='0'&&t[i]<='9')now=t[i]-48;
			else
			{
				b+=now*(t[i]=='m'?1000:t[i]=='c'?100:t[i]=='x'?10:1);
				now=1;
			}
		}
		a+=b;
		string ans="";
		for(int i=1000;i;i/=10)
		{
			if(a/i%10>1)ans+=a/i%10+48;
			if(a/i%10>0)ans+=i==1?"i":i==10?"x":i==100?"c":"m";
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3148
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextLine() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextLine())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func sumSlice(nums []int) int {
	sum := 0
	for _, n := range nums {
		sum += n
	}
	return sum
}

func binarySearch(target int, list []int) int {
	left := 0
	right := len(list) - 1
	mid := (left + right) / 2

	for {
		if list[mid] < target {
			left = mid + 1
		} else {
			right = mid
		}
		mid = (left + right) / 2
		if left >= right {
			break
		}
	}
	return mid
}

func main() {
	scanner.Split(bufio.ScanWords) // switch to separating by space
	// scanner.Buffer([]byte{}, 1000000009) // switch to read large size input
	A := nextInt()
	B := nextInt()
	C := nextInt()

	diff := A - B
	remain := C - diff

	answer := max(remain, 0)

	fmt.Println(answer)
}


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

const long long N=400000;
typedef pair<long long,long long> pi;
long long a[N],b[N];

int main(){
    
    ios_base::sync_with_stdio(false);
    
	long long n,m,i,k,z,k1,k2,q1,q2,s=0,ans=0;
	
	pair<long long,long long>p;
	priority_queue<pi,vector<pi>,greater<pi>>pq;
	
	cin>>n>>m;
	
	for(i=0;i<n;i++)
		cin>>a[i];
	
	for(i=0;i<n;i++){
	
	k=a[i];
	z=0;
	
	while(k>0){
	k=k/2;
	z++;}
	
	b[i]=z;
	s+=b[i];}
	
	for(i=0;i<n;i++){
	
	if(b[i]!=0){
	k1=a[i]/((long long)1<<b[i]);
	k2=a[i]/((long long)1<<(b[i]-1));
	
	pq.push(make_pair(k2-k1,i));}}
	
	for(i=0;i<s-m;i++){
	
	p=pq.top();
	pq.pop();
	
	k1=p.first;
	k2=p.second;
	
	b[k2]--;
	
	if(b[k2]!=0){
	q1=a[k2]/((long long)1<<b[k2]);
	q2=a[k2]/((long long)1<<(b[k2]-1));
	
	pq.push(make_pair(q2-q1,k2));}}
	
	for(i=0;i<n;i++)
	ans+=a[i]/((long long)1<<b[i]);

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

Measured memory_bytes: 5236
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int n = sc.nextInt();
			if(n==0)break;
			int k = 0;
			for (int d = 5; d <= n; d *= 5) {
				k+=Math.ceil(n/d);
			}
			System.out.println(k);
		}
	}
}

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

int main() {
    string s;
    cin >> s;
    deque<char> dq;
    for (char c : s) {
        if (c == 'B' && !dq.empty()) dq.pop_back();
        if (c != 'B') dq.push_back(c);
    }
    while (!dq.empty()) {
        cout << dq.front();
        dq.pop_front();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3528
#include<iostream>
#include<array>
#include<algorithm>
const int poetry = 3;

int main() {
	std::array<int, poetry> arry;
	int five, seven;
	
	for (int i = 0; i < poetry; i++) {
		std::cin >> arry[i];
	}

	five=std::count(arry.begin(), arry.end(), 5);
	seven = std::count(arry.begin(), arry.end(), 7);

	if (2 == five && 1 == seven) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}

	return 0;

}

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

using namespace std;

#define DPRINTF(...) printf(__VA_ARGS__)
#define FOR0(i, n) for(int i=0;i<n;i++)
#define ALL(c) (begin(c)), (end(c))
#define fst(t) get<0>(t)
#define snd(t) get<1>(t)
#define thd(t) get<2>(t)

typedef long long ll;

string S;
ll rec(int p, ll sum){
    if(p == S.size()){return sum;}

    ll res = 0ll;
    for(int i=p+1;i<=S.size();i++){
        // cout << "+" << S.substr(p, i-p) << endl;
        ll added = stoll(S.substr(p, i-p));
        res += rec(i, sum + added);
    }

    return res;
}

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

  cin >> S;

  cout << rec(0, 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {
  int x, y;
  std::cin >> x >> y;
  for (int i = 0; i <= x; ++i)
    if (i * 2 + (x - i) * 4 == y) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  std::cout << "No" << std::endl;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <cmath> //これはlogを使うときに必要
#include <vector> //これは配列(vector)を使うときに必要
#include <math.h> //べき乗を使うときに必要
using namespace std;

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int small = min(x,y);
  int big = max(x,y);
  int money;

  //3通りの算出法
  int p = a * x + b * y;
  int q = c * 2 * small + a * (x - small) + b * (y - small);
  int r = c * 2 * big;
  money = min(min(p,q),r);
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 888
N = int(input())

T = [0] * N
A = [0] * N
for i in range(N):
    A[i], T[i] = map(int, input().split())

tmp_T = T[0]
tmp_A = A[0]

for i in range(1,N):
    ma = tmp_A // A[i] + (1 if tmp_A % A[i] > 0 else 0)
    mt = tmp_T // T[i] + (1 if tmp_T % T[i] > 0 else 0)
    n = max(mt,ma)
    tmp_A = n * A[i]
    tmp_T = n * T[i]

print(tmp_T + tmp_A)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <limits.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    int W[100][100];
    for (int i=0; i<100; i++) {
        for (int j=0; j<100; j++) {
            W[i][j] = INT_MAX;
        }
    }
    
    for (int i=0; i<m; i++) {
        int s,t,w;
        cin >> s >> t >> w;
        W[s-1][t-1] = w;
        W[t-1][s-1] = w;
    }
    
    int o=0;
    int mark[100][100] = {};
    
    for (int i=0; i<n; i++) {
        
        int pie[100];
        for (int p=0; p<100; p++) {
            pie[p] = -1;
        }
        
        int visited[100] = {};
        
        vector<pair<int,int>> pq;
        for (int k=0; k<n ;k++) {
            int d = (k==i) ? 0 : INT_MAX;
            pq.push_back(make_pair(d,k));
        }
        
        vector<pair<int,int>> pq_copy(pq);
        
        make_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
        
        while(pq.size()>0) {
            pair<int,int> s = pq.front();
            pop_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
            pq.pop_back();
            
            visited[s.second] = 1;
            for (int t=0; t<100; t++) {
                if (W[s.second][t] != INT_MAX && !visited[t]) {
                    if (s.first + W[s.second][t] < pq_copy[t].first) {
                        pq_copy[t].first = s.first + W[s.second][t];
                        pie[t] = s.second;
                    }
                }
            }
            
            for (auto &a:pq) {
                a.first = pq_copy[a.second].first;
            }
            
            make_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
        }
        
        for (int p=0; p<100; p++) {
            int t=p;
            while(pie[t] != -1) {
                mark[t][pie[t]] = 1;
                mark[pie[t]][t] = 1;
                t=pie[t];
            }
        }

    }
    
    for(int r=0; r<100; r++) {
        for(int c=0; c<100; c++){
            if (W[r][c] != INT_MAX && !mark[r][c]) o++;
        }
    }
    
    cout << o/2 << endl;
    
	return 0;
}

Measured memory_bytes: 384