akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var K, T int
	fmt.Scan(&K, &T)
	a := make([]int, T)
	for i := 0; i < T; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	gaps := a[0] - 1
	for i := 1; i < T; i++ {
		gaps -= a[i]
		gaps = max(gaps, 0)
	}
	fmt.Println(gaps) // 残りgapの数が、前日と同じケーキを食べる日数となる
}


Measured memory_bytes: 512
N=input()
N=list(map(int,N))

if N[-1]==2 or N[-1]==4 or N[-1]==5 or N[-1]==7 or N[-1]==9:
    print("hon")
elif N[-1]==0 or N[-1]==1 or N[-1]==6 or N[-1]==8:
    print("pon")
elif N[-1]==3:
    print("bon")

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	int ans = -1;
	for (int i = 0; i <= n; i++){
		if ( floor( i*1.08) == n){
			ans = i;
		}
	}
	if (ans == -1){
		cout << ":(";
	}
	else {
		cout << ans;
	}
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
int h[100010];

bool can = true;

int main(void){
	cin>>n;
	for (int i = 0; i < n; i++) cin>>h[i];

	int maxh = -1;
	for (int i = 0; i < n; i++) {
		if (maxh < h[i]) maxh = h[i];

		if (maxh >= h[i]) {
			if (maxh - 1 > h[i]) can = false;
		}
	}

	if (can) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int a, b, c, d;
	int ans = 0;

	scanf("%d %d %d %d", &a,&b,&c,&d);
	if (a > c){
		int tmp = a;
		a = c;
		c = tmp;
		tmp = b;
		b = d;
		d = tmp;
	}

	if (c < b) {
		if (d <= b) ans = d - c;
		else ans = b - c;
	}

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

	return 0;
}

Measured memory_bytes: 128
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;

namespace hello_world
{class Program
	{
		static void Main(string[] args)
		{
			string a = Console.ReadLine();
			string b = Console.ReadLine();
			int aa = a.Length;
			int bb = b.Length - aa;
			string c = b.Substring(0, aa);
			if(a==c &&bb==1)
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
	}

}

	

Measured memory_bytes: 25892
import sys
input=sys.stdin.readline
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
l1=sorted([i+j for i in a for j in b],reverse=True)[:k]
l2=sorted([i+j for i in l1 for j in c],reverse=True)[:k]
for i in l2:
  print(i)


Measured memory_bytes: 184524
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
typedef long long ll;
int main()
{
  ll n; cin >> n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  ll res = 0;
  rep(i,n) {
    ll lb = -1, ub = n;
    while(ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      (a[mid] < b[i] ? lb : ub) = mid;
    }
    ll tmp = lb + 1;
    lb = -1; ub = n;
    while(ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      (c[mid] > b[i] ? ub : lb) = mid;
    }
    res += tmp * (n - ub);
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 5640
#include <cstdio>
#include <bitset>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <sstream>
#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b)
{
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b)
{
  return a.real() * b.real() + a.imag() * b.imag();
}

int main()
{
  string str;
  while (getline(cin, str)) {
    istringstream is(str);
    string token;
    int n;
    while (is >> token) {
      for (int i = 0; i < 26; i++) {
	string tmp;
	for (int j = 0; j < token.size(); j++) {
	  tmp += (token[j] - 'a' + i) % 26 + 'a';
	}
	//cout << "i = " << i << "tmp = " << tmp << endl;
	if (tmp == "the" || tmp == "this" || tmp == "that") {
	  n = i;
	  goto next;
	}
      }
    }
  next:
    //printf("n = %d\n", n);
    for (int i = 0; i < str.size(); i++) {
      printf("%c", ('a' <= str[i] && str[i] <= 'z') ?(str[i] - 'a' + n) % 26 + 'a' : str[i]);
    }
    printf("\n");
  }
}

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

const int N = (int)1e5+5;

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

    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e6+5,mod=1e9+7;
ll fct[N],inv[N],invfct[N];
void init(){
    fct[0]=fct[1]=1;
	inv[1]=1;
	invfct[0]=invfct[1]=1;
	for(ll i=2;i<N;i++){
		fct[i]=i*fct[i-1]%mod;
		inv[i]=ll(mod-inv[mod%i])*(mod/i)%mod;
		invfct[i]=ll(inv[i])*invfct[i-1]%mod;
	}
}
inline ll ncr(ll n,ll r){
    if(n<0 || n-r<0)return 0;
    ll val = fct[n]*invfct[r];
    val%=mod;
    val = val*invfct[n-r];
    val%=mod;
    return val;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    init();
    ll r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
    ll ans = 0;
    for(ll r=r1;r<=r2;r++){
        ll val = ncr(r+c2+1,r+1) - ncr(r+c1,r+1);
        val = val + mod;
        val%=mod;
        ans = ans + val;
        ans%=mod;
       // cout<<r<<" "<<val<<endl;
    }
    cout<<ans;
}




Measured memory_bytes: 47232
import re
S = input().strip()
if re.match(r'^.*keyence$', S):
  print('YES')
elif re.match(r'^k.*eyence$', S):
  print('YES')
elif re.match(r'^ke.*yence$', S):
  print('YES')
elif re.match(r'^key.*ence$', S):
  print('YES')
elif re.match(r'^keye.*nce$', S):
  print('YES')
elif re.match(r'^keyen.*ce$', S):
  print('YES')
elif re.match(r'^keyenc.*e$', S):
  print('YES')
elif re.match(r'^keyence.*$', S):
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 15556
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int f(int n){
    if (n % 2 == 0){
        return n/2;
    }else{
        return 3*n + 1;
    }
}

int main(int argc, char**argv){
    double s;
    cin >> s;
    vector<int> m(1000001, 0);

    m[s]++;
    int counter = 1;
    while(1){
        counter++;
        s = f(s);
        if (s < 1000001){
            m[s]++;
        }
        if (m[s] == 2){
            cout << counter << endl;
            break;
        }
    }

    return 0;
}















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

int N;
string S;

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

    int r = 0;
    int b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        else b++;
    }

    cout << ((r > b) ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
int n; long long a[55];
int main() {
	cin >> n;
	int r = -1, pos = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (abs(a[i]) > r) {
			r = abs(a[i]);
			pos = i;
		}
	}
	cout << (n - 1) * (a[pos] != 0 ? 2 : 1) << endl;
	for (int i = 0; i < n; i++) {
		if (i != pos) {
			cout << pos + 1 << ' ' << i + 1 << endl;
			a[i] += a[pos];
		}
	}
	if (a[pos] > 0) {
		for (int i = 1; i < n; i++) {
			cout << i << ' ' << i + 1 << endl;
		}
	}
	else if (a[pos] < 0) {
		for (int i = n - 2; i >= 0; i--) {
			cout << i + 2 << ' ' << i + 1 << endl;
		}
	}
	return 0;
}

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

int n,v,e[100001][3],i,p[10001],r=0;

int c(const void *x,const void *y)
{
	return ((int*)x)[2]-((int*)y)[2];
}

int a(int x)
{
	return p[x]==x?x:a(p[x]);
}

int main()
{
	for(;~scanf("%d%d",&n,&v),n;)
	{
		for(i=0;i<=n;i++)
			p[i]=i;
		for(i=0;i<v;e[i][2]=e[i][2]/100-1,i++)
			scanf("%d,%d,%d",&e[i][0],&e[i][1],&e[i][2]);
		qsort(e,v,sizeof(int[3]),c);
		for(i=r=0;i<v;i++)
			if(a(e[i][0])!=a(e[i][1]))
			{
				r+=e[i][2];
				p[a(e[i][0])]=p[a(e[i][1])];
			}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if ( i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a));

	int b = a[0];
	int c = a[1];
	vector<int>blist=enum_div(b);
	vector<int>clist = enum_div(c);
	int gcd = 1;
	rep(i, blist.size()) {
		int count = 0;
		rep(j, n) {
			if (a[j] % blist[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		if (count <= 1) {
			gcd = max(gcd, blist[i]);
		}
	}
	rep(i, clist.size()) {
		int count = 0;
		rep(j, n) {
			if (a[j] % clist[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		if (count <= 1) {
			gcd = max(gcd, clist[i]);
		}
	}
	cout << gcd << endl;

}


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

int main(){
    int N,A,B;
    int P[200];
    cin >> N >> A >> B;
    int P_i, a1, a2, a3;
    a1 = 0; a2 = 0; a3 = 0;
    for(int i=0;i<N;i++){
        cin >> P_i;
        if(P_i <= A) a1++;
        else if(P_i > A && P_i <= B) a2++;
        else if(P_i > B) a3++;
    }
    int amin = a1;
    if (amin > a2) amin = a2;
    if (amin > a3) amin = a3;
    cout << amin << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 200000

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    for(i = 0; i < num; i++) {
        arr[i] -= i;
    }
    qsort(arr, num, sizeof(int), asc);
    int mid = arr[num/2];

    int64_t ans = 0;
    for(i = 0; i < num; i++) {
        ans += abs(arr[i]-mid);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1788
S = input()
K = int(input())
uniqueS = []
for s in S:
    if s not in uniqueS:
        uniqueS.append(s)
lenS = len(S)
ansS = []
uniqueS.sort()
for us in uniqueS:
    for i in range(lenS):
        for j in range(1,min(lenS-i+1,6)):
            if S[i] == us:
                if S[i:i+j] not in ansS:
                    ansS.append(S[i:i+j])
    if len(ansS) >= 5:
        break
ansS.sort()
print(ansS[K-1])

Measured memory_bytes: 3064
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) == N and all([(len(t) > s-1) and (int(t[s-1]) == c) for s, c in SC]):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3060
from io import StringIO
from collections import *
from functools import *
from math import sqrt
import sys


def main(inputs):
    n = int(next(inputs))
    # xs = list(map(int, next(inputs).split()))
    x_max = int(sqrt(n))
    ans=0
    
    for i in range(1, x_max+1):
        if n % i == 0 and (n // i) - 1 > i:
            ans += (n // i) - 1
            pass
        pass

    # n // m = x 
    # n % m = x (0 < x < m < m+1 < x*m < n), (x*x < n)
    # m * x + x = x * (m + 1) = n
    # m = n / x - 1

    return ans


def gen_inputs(str_=None):
    inputs = StringIO(str_) if str_ else sys.stdin
    while True:
        a = inputs.readline().rstrip()
        yield a
        pass
    pass


if __name__ == "__main__":
    print(main(gen_inputs()))
    pass


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<P> v;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    auto comp = [](const P& x, const P& y) {
        return x.second < y.second;
    };

    sort(v.begin(), v.end(), comp);

    int cur = 1, ans = 0;
    for (auto& p : v) {
        if (p.first >= cur) {
            ans++;
            cur = p.second;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

ll f(ll n, ll a, ll b)
{
	if ((b-a) % 2 == 0)
		return (b-a)/2;

	return min(a + f(n, 1, b-a), n-b+1 + f(n, a + n-b+1, n));
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, a, b;
	cin >> n >> a >> b;
	cout << f(n, a, b) << "\n";

	return 0;
}


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


int main(void) {

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  for(int i=n-1; i>=0; i--){
    if( i != 0 ) cout << a[i] << " ";
    else cout << a[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <deque>

#include <algorithm>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;
#include <string>


ll pow_repeat_mod(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow_repeat_mod(N, P/2, M);
        return t*t % M;
    }
    return N * pow_repeat_mod(N, P-1, M)%M;
}


ll pow_repeat(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow_repeat(N, P);
        return t*t;
    }
    return N * pow_repeat(N, P-1);
}


ll my_mod(ll N,ll M){


    ll A =N%M;

    if(A>=0){

        return A;
    }
    else{

        return A +M;
    }
}



int main()
{


    ll n, a, b;


    cin >> n >> a >> b;





    ll kasu = pow_repeat_mod(2,n,1000000007) -1;




    ll X_a =1;
    ll Y_a =1;

    ll X_b =1;
    ll Y_b =1;


    for(int i=0;i<a; i++){
        X_a = (X_a*((n-i)%1000000007))%1000000007;
    }

    for(int i=0;i<a; i++){
        Y_a = (Y_a*((i+1)%1000000007))%1000000007;
    }


    for(int i=0;i<b; i++){
        X_b = (X_b*((n-i)%1000000007))%1000000007;
    }

    for(int i=0;i<b; i++){
        Y_b = (Y_b*((i+1)%1000000007))%1000000007;
    }


    Y_a = pow_repeat_mod(Y_a,1000000007-2,1000000007);
    Y_b = pow_repeat_mod(Y_b,1000000007-2,1000000007);


    kasu = (kasu  - (X_a*Y_a)%1000000007 - (X_b*Y_b)%1000000007);


    cout << my_mod(kasu,1000000007) << endl;


    
    

    return 0;
}



//繰り返し2乗法による




Measured memory_bytes: 888
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int x = vs[0];
			int y = vs[1];
			int a = y - (x * 2);
			if (a >= 0 && a % 2 == 0 && a / 2 <= x) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}

		}
	}
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll ones = 0;
ll twos = 0;
ll threes = 0;

ll N;

vector<vector<vector<double> > > dp;

double calculate(ll a, ll b, ll c){

  if(a<0 || b <0 || c<0) return 0;

  if(dp[a][b][c] != -1){
    return dp[a][b][c];
  }


  double expectedLeave = 1.0;
  if(a+b+c < N){
    expectedLeave = ((double) N/(double) (a+b+c));
  }

  dp[a][b][c] = expectedLeave
                  +calculate(a-1, b, c)*((double)a/(double)(a+b+c))
                  +calculate(a+1, b-1, c)*((double)b/(double)(a+b+c))
                  +calculate(a, b+1, c-1)*((double)c/(double)(a+b+c));

  return dp[a][b][c];
}

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

  cin >> N;

  vl a(N, 0);

  FOR(i, 0, N) cin >> a[i];

  FOR(i, 0, N) {
    if(a[i] == 1){
      ones++;
    }
    else if(a[i] == 2){
      twos++;
    }
    else{
      threes++;
    }

  }

  dp = vector<vector<vector<double> > >(N+1, vector<vector<double> >(N+1, vector<double>(N+1, -1)));





  dp[0][0][0] = 0;


  cout << fixed << setprecision(16) << calculate(ones, twos, threes) << endl;


}


Measured memory_bytes: 216960
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

struct Mod {
	static ll gcd(ll x, ll y, ll* out_cx, ll* out_cy) {
		if (x < 0) {
			ll d = gcd(-x, y, out_cx, out_cy);
			if (out_cx) {
				*out_cx *= -1;
			}
			return d;
		}
		if (y < 0) {
			ll d = gcd(x, -y, out_cx, out_cy);
			if (out_cy) {
				*out_cy *= -1;
			}
			return d;
		}
		if (x > y) {
			return gcd(y, x, out_cy, out_cx);
		}
		if (x == 0) {
			if (out_cx && out_cy) {
				*out_cx = 0;
				*out_cy = 1;
			}
			return y;
		}
		ll q = y / x;
		ll r = y % x;
		ll d = gcd(r, x, out_cy, out_cx);
		if (out_cx) {
			*out_cx -= q * *out_cy;
		}
		return d;
	}
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod()
	: value(0) {}
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
	Mod operator/(const Mod& rhs) const { return *this * rhs.inv(); }
	void operator/=(const Mod& rhs) { *this = *this / rhs; }
	Mod inv() const {
		if (value == 0) {
			assert(false);
			throw "[Mod::inv] div by zero";
		}
		ll ans, sub;
		ll d = Mod::gcd(value, BASE, &ans, &sub);
		if (d != 1) {
			assert(false);
			throw "[Mod::inv] not invertible";
		}
		return ans;
	}
};
ll Mod::BASE = 1000000007;

int main() {
	ll N;
	cin >> N;
	vector<ll> Xs(N);
	rep(i,0,N) {
		cin >> Xs[i];
	}
	vector<Mod> fact(N+1);
	fact[0] = 1;
	rep(n,1,N) {
		fact[n] = fact[n-1] * n;
	}
	auto binom = [&fact](ll n, ll r) -> Mod {
		if (n >= 0 && 0 <= r && r <= n) {
			return fact[n] / fact[r] / fact[n-r];
		} else {
			return 0;
		}
	};
	vector<Mod> ps(N);
	ps[0] = fact[N-1];
	ps[N-1] = 0;
	rep(n,1,N-1) {
		ps[n] = fact[n] * binom(N-1, n+1) * fact[N-n-2];
	}
	vector<Mod> sums(N+1);
	rep(n,1,N+1) {
		sums[n] = sums[n-1] + Xs[n-1];
	}
	Mod ans = 0;
	rep(k,1,N-1) {
		Mod ans_loc = ps[k-1]-ps[k];
		ans_loc *= (sums[N-1] - sums[k]) - sums[N-k-1];
		ans += ans_loc;
	}
	rep(n,0,N) {
		ans += ps[N-n-2] * (Xs[N-1] - Xs[n]);
	}
	cout << ans.value << endl;
}

Measured memory_bytes: 3960
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <cmath>

using namespace std;

int64_t INF = 5'000'000'000'000'000;

string S;
int64_t K;

int main() {
    cin >> S >> K;

    char ans='1';
    for(int i=0;i<S.size();i++){
        if( S[i] != '1' ){
            ans = S[i];
            break;
        } else if( S[i] == '1' && i+1 == K ){
            ans = S[i];
            break;
        }
    }

    cout << ans << endl;
}

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

int main() {
  
  int a ,b,c;
  cin>> a >> b >> c ;
  if (a==b&&b==c){
    cout << "No" << endl;
  }
else if (a==b||b==c||c==a)
{  cout << "Yes" << endl;}
  else {cout << "No" << endl;}
  
 
}





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

int main()
{
	ll int n, W;
	cin >> n >> W;

	ll int w[n], v[n];
	ll V = 0;
	for(int i=0; i<n ;i++)
	{
		cin >> w[i] >> v[i];
		V += v[i];
	}

	ll int dp[n+1][V+1];
	memset(dp, 1, sizeof(dp));
	dp[0][0] = 0;
	
	int mn = 0;
	for(int i=1; i<=n; i++)
	{
		for(int j=0; j<=V; j++)
		{
			if(w[i-1] > W)
				break;
			if(v[i-1] <= j)
				dp[i][j] = min(dp[i-1][j], dp[i-1][j - v[i-1]] + w[i-1]);
			else
				dp[i][j] = dp[i-1][j];

			if(i == n and dp[i][j] <= W)
			mn = max(mn, j);
		}
	}
	cout << mn;

	return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		ch.push_back(x);
	}
	sort(ch.begin(),ch.end());
	reverse(ch.begin(),ch.end());
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			for(ll k=j+1;k<n;k++){
				ll a=ch[i];
				ll b=ch[j];
				ll c=ch[k];
				if(a<b+c&&a!=b&&b!=c&&c!=a){
					ans++;
			//		cout << a<<b<<c<<endl;
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
string a,b;

int main()
{
    // your code goes here
    cin>>a>>b;
    if(a.size()>b.size())
    {
        for(int i=0; i<a.size(); ++i)
        {

            if(i==b.size())
                break;
            cout<<a[i]<<b[i];
        }
        for(int i=b.size(); i<a.size(); ++i)
            cout<<a[i];

        cout<<endl;

    }
    else if(a.size()<b.size())
    {
        for(int i=0; i<b.size(); ++i)
        {
            if(i==a.size())
                break;

            cout<<a[i]<<b[i];
        }
        for(int i=a.size() ;i<b.size(); ++i)
            cout<<b[i];

        cout<<endl;
    }
    else
    {
        for(int i=0; i<a.size(); ++i)

            cout<<a[i]<<b[i];

        cout<<endl;
    }

    return 0;
}


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

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> A)
{
    const long long MOD = 1000000007;
    long long maxA = *max_element(A.begin(), A.end());
    long long k = floor(log2(maxA)) + 1;

    // cout << "k " << k << endl;

    long long res = 0;
    for (size_t j = 0; j < 60; j++)
    {
        long long n_ones = 0;
        for (size_t i = 0; i < N; i++)
        {
            n_ones += (A[i] >> j) & (1);
        }
        long long res_k = n_ones * (N - n_ones);
        for (size_t l = 0; l < j; l++)
        {
            res_k = (2 * res_k) % MOD;
        }

        res += res_k;
    }

    cout << (res % MOD) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
import Control.Monad (replicateM)
main = do
        n <- readLn
        nums <- replicateM n readLn
        print.length.filter isPrime $ nums

primes :: [Int]
primes = 2 : 3 : filter isPrime [5,7..]

isPrime :: Int -> Bool
isPrime n = ip n primes

ip n (p:ps)
    | p > sqrtn     = True
    | n `mod` p == 0 = False
    | otherwise      = ip n ps
    where sqrtn = floor.sqrt.fromIntegral $ n

Measured memory_bytes: 8344
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

ll f(ll h)
{
    if (h == 1) return 1;
    return 2*f(h/2) + 1;
}

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string s;
    cin >> s;

    int cnt = 0;
    char pre = '0';
    for (auto i : s)
    {
        if (pre != i) {
            cnt++;
        }
        pre = i;
    }

    cout << cnt - 1;



    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

  vector<int> w(n + 1), v(n + 1);

  int V = 0;

  for (auto i = 1; i <= n; ++i) {
    cin >> w[i] >> v[i];
    V += v[i];
  }

  int dp[n + 1][V + 1];
  memset(dp, 63, sizeof(dp));

  for (auto i = 0; i <= n; ++i) {
    dp[i][0] = 0;
  }

  for (auto i = 1; i <= n; ++i) {
    for (auto j = 1; j <= V; ++j) {
      dp[i][j] =
          min(dp[i - 1][j], j >= v[i] ? dp[i - 1][j - v[i]] + w[i] : INF);
    }
  }

  for (auto i = V; i >= 0; --i) {
    if (dp[n][i] <= m) {
      cout << i << "\n";
      break;
    }
  }
}

Measured memory_bytes: 39680
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n];
	ll dp[100001]={0};
	for(i=1;i<=100000;i++)
	dp[i]=1e18;
	for(i=0;i<n;i++)
	cin>>w[i]>>v[i];
	for(i=0;i<n;i++)
	for(j=100000;j>=v[i];j--)
	dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
	ll ans=0;
	for(i=0;i<=100000;i++)
	if(dp[i]<=W)
	ans=i;
	cout<<ans;
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 1024
package main

import "fmt"

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

	a := make([]int, n)
	fmt.Scan(&a[0])
	for i := 1; i < n; i++ {
		fmt.Scan(&a[i])
		if a[i] < a[i-1] {
			sum += a[i-1] - a[i]
			a[i] = a[i-1]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 6472
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (ll i=(a); i<(b);++i)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<ll,ll> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a,k) sort(a,a+k,greater<ll>())
#define rsrt(a) sort(a.begin(),a.end(),greater<ll>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define setbits(a) __builtin_popcount(a)
const ll M=1e9+7;
const ll mxx=3001;

int main()
{  
   

   int n;cin>>n;
  int a[n],b[n];
  fr(i,0,n)cin>>a[i];
  fr(i,0,n)cin>>b[i];
  int p=0,q=0,cnt=1;
  int arr[n];
  fr(i,0,n)arr[i]=i+1;
    while(next_permutation(arr,arr+n)){
       
         bool ma=true,mb=true;
         fr(i,0,n){if(arr[i] != a[i])ma=false;if(arr[i] != b[i])mb=false;}
         if(ma){p=cnt;}
         if(mb){q=cnt;}
         cnt++;
    }
    
    cout<<abs(p-q);
}



Measured memory_bytes: 3612
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    if N % 2 != 0 {
        println!("0");
        return;
    }
    let mut ans = 0;
    let mut w = 10;
    while w <= N {
        ans += N / w;
        w *= 5;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll inv =500000004;
const int maxn=1e5;
int n,m;
struct node
{
    int u,v;
}e[maxn+10];
int cmp(node a,node b)
{
    if(a.u == b.u)
        return a.v<b.v;
    return a.u<b.u;
}
int main()
{
    while(cin>>n>>m)
    {
        for(int i=1;i<=m;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            if(u>v)
                swap(u,v);
            e[i].u = u;
            e[i].v = v;

        }
        sort(e+1,e+1+m,cmp);
        int st = e[1].u;
        int en = e[1].v;
        int sum=0;
        for(int i=2;i<=m;i++)
        {
            //printf("%d %d\n",e[i].u,e[i].v);
            if(en<=e[i].u)
            {
                //printf("sss");
                sum++;
                st=e[i].u;
                en=e[i].v;
            }
            else
            {
                if(en<=e[i].v)
                {
                    st=e[i].u;
                    en=en;
                }
                else
                {
                    st=e[i].u;
                    en=e[i].v;
                }

            }
        }
        cout<<sum+1<<endl;

    }
    return 0;
}

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

class Square{
public:
	Square() : mTop( 0.0 ), mBottom( 0.0 ), mRight( 0.0 ), mLeft( 0.0 ){}

	double mTop, mBottom, mRight, mLeft;
};

int main(){
	Square a, b;

	while ( cin >> a.mLeft >> a.mBottom >> a.mRight >> a.mTop
				>> b.mLeft >> b.mBottom >> b.mRight >> b.mTop ){
		if ( !( a.mLeft > b.mRight || a.mRight < b.mLeft )
			&& !( a.mTop < b.mBottom || a.mBottom > b.mTop ) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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

map<string, int> dp;
int x[] = {1, -1, 4, -4};

void bfs()
{
    dp["01234567"] = 0;
    queue<string> q;
    q.push("01234567");
    while(!q.empty()) {
        string now = q.front();
        q.pop();
        int p;
        for(int i = 0; i <= 7; ++i) {
            if(now[i] == '0') {
                p = i;
                break;
            }
        }
        for(int i = 0; i < 4; ++i) {
            int qn = p + x[i];
            if(qn < 0 || qn > 7 || (p == 3 && qn == 4) || (p == 4 && qn == 3)) continue;
            string next = now;
            swap(next[p], next[qn]);
            if(dp.find(next) == dp.end()) {
                dp[next] = dp[now] + 1;
                q.push(next);
            }
        }
    }
}

int main()
{
    bfs();
    string line;
    while(getline(cin, line)) {
        line.erase(remove(line.begin(), line.end(), ' '), line.end());
        cout << dp[line] << endl;
    }
    return 0;
}

Measured memory_bytes: 3436
#include<stdio.h>
#define NIL 500003
 
int A[500001],n;
 
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
   scanf("%d",&A[i]);
  }
  
  for(i=n+1;i<500001;i++){
  A[i] = NIL;
  }
  for(i=n/2;i>=1;i--){
  
   maxHeapify(i);
  }
  for(i=1;i<=n;i++)
    {
  printf(" %d",A[i]);
    }  
printf("\n");

return 0;
  
}

int left(int i){
return i*2;
}

int right(int i){
return i*2+1;
}

void exchange(int *a,int *b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
void maxHeapify(int i){
  
  int l;
  int r;
  int largest;

  l = left(i);
  r = right(i);
 
  if(l<=n&&A[l]>A[i])largest=l;
  else largest=i;
 
  if(r<=n&&A[r]>A[largest])largest=r;
 
  if(largest!=i){
    exchange(&A[i],&A[largest]);
    maxHeapify(largest);
  }
 
}
 

Measured memory_bytes: 2552
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int four = 0, two = 0;
		for(int i = 0; i < N; i++){
			int a = sc.nextInt();
			if(a%4 == 0)
				four++;
			else if(a%2 == 0)
				two++;
		}
		if(four >= N/2)
			System.out.println("Yes");
		else if(two >= N-four*2)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 48592
#include <iostream>

using namespace std;

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

	for (int i = 0; i <= 8; i++) {
		if (X < (i * 200 + 400)) {
			cout << 9 - i << endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;

int reverse(int num)
{
    int rev = 0;
    while (num > 0)
    {
        rev = rev * 10 + num % 10;
        num /= 10;
    }
    return rev;
}

int main()
{
    int A, B, num, a = 0;
    cin >> A >> B;

    for (int i = A; i < B + 1; i++)
    {
        num = i;

        if (num == reverse(num))
        {
            a++;
        }
    }

    cout << a;
}

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

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]);
    return 0;
}

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

int main() {
	cin >> s;
	int l = s.length();
	for(int i = 0; i < l; i++) {
		if(s[i] == '1') s[i] = '9';
		else s[i] = '1';
	}
	cout << s << endl;
}

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

int main(){
	vector<int> v;
	stack<int> s;
	int n;
	cin >> n;
	s.push(n);
	while(cin>>n){
		if(n==0){
			v.push_back(s.top());
			s.pop();
		} else {
			s.push(n);
		}
	}
	for(int i=0 ; i<v.size(); i++){
		cout << v[i] << endl;
	}
	return 0;	
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, a[202020];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	i64 ans = 0, mi = INF;
	for(int i = 0; i < n; i++){
		if(mi >= a[i]){
			ans++;
			mi = a[i];
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n, 0);
    for(int i =0 ; i< n;i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());

    long long tmp =0, ans = 0;
    for(int i = x[0]; i< x[n-1]; i++){
        for(int j = 0; j<n;j++){
            tmp += pow(abs(i-x[j]), 2);
        }
        if(i == x[0]) ans = tmp;
        else ans = min(tmp, ans);

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
        int y1, m1, d1, y2, m2, d2, uruu[1000000], m2d[13];
        for(int i=0; i<1000000; i++) uruu[i] = ((i%4==0)&&(i%100!=0)||(i%400==0));

        while(1){
                scanf("%d %d %d %d %d %d", &y1, &m1, &d1, &y2, &m2, &d2);
                if(y1<0|m1<0|d1<0|y2<0|m2<0|d2<0) break;

                int days1 = 0;
                for(int i=0; i<y1; i++) days1 += 365 + uruu[i];
                for(int i=1; i<m1; i++){
                        switch(i){
                                case 4:
                                case 6:
                                case 9:
                                case 11:
                                        days1 += 30;break;
                                case 2:
                                        days1 += 28 + uruu[y1];break;
                                default:
                                        days1 += 31;break;
                        }
                }
                days1 += d1;

                int days2 = 0;
                for(int i=0; i<y2; i++) days2 += 365 + uruu[i];
                for(int i=1; i<m2; i++){
                        switch(i){
                                case 4:
                                case 6:
                                case 9:
                                case 11:
                                        days2 += 30;break;
                                case 2:
                                        days2 += 28 + uruu[y2];break;
                                default:
                                        days2 += 31;break;
                        }
                }
                days2 += d2;

                printf("%d\n", days2 - days1);
        }
        return 0;
}


Measured memory_bytes: 5640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {

	// ?????°
	static final int n = 10;

	// ?????°
	static final int m = 10;

	// ???????????´????°?
	static final String INK_SIZE_SMALL = "1";

	// ???????????´??????
	static final String INK_SIZE_MEDIUM = "2";

	// ???????????´?????§
	static final String INK_SIZE_LARGE = "3";

	public static void main(String[] args) throws IOException {

		int[][] paper = new int[n][m];

		// 1.?¨?????????????????????????
		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(System.in), 1);

		// 2.??????????????????
		String line;
		while ((line = bufferedReader.readLine()) != null) {
			// 2-1.??????????????????
			String inkSize = line.split(",")[2];
			int x = Integer.parseInt(line.split(",")[0]);
			int y = Integer.parseInt(line.split(",")[1]);

			// 2-2.????????????
			if (INK_SIZE_SMALL.equals(inkSize)) {
				paper = smallInk(x, y, paper);
			} else if (INK_SIZE_MEDIUM.equals(inkSize)) {
				paper = mediumInk(x, y, paper);
			} else if (INK_SIZE_LARGE.equals(inkSize)) {
				paper = largeInk(x, y, paper);
			}
		}

		// 3.????????????????????????????????°?????????
		// 4.????????????

		int colorless = 0;
		int depth = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				// ????????????????????????????????°???????????????
				if (paper[i][j] == 0) {
					colorless++;
				}
				// ???????????????????????¢???
				if (depth < paper[i][j]) {
					depth = paper[i][j];
				}
			}
		}
		System.out.println(colorless);
		System.out.println(depth);
	}

	private static int[][] smallInk(int x, int y, int[][] array) {
		if (x - 1 >= 0) {
			array[y][x - 1]++;
		}

		if (y - 1 >= 0) {
			array[y - 1][x]++;
		}
		array[y][x]++;
		if (y + 1 < n) {
			array[y + 1][x]++;
		}

		if (x + 1 < m) {
			array[y][x + 1]++;
		}
		return array;
	}

	private static int[][] mediumInk(int x, int y, int[][] array) {
		array = smallInk(x, y, array);
		if (y - 1 >= 0) {
			if (x - 1 >= 0)
				array[y - 1][x - 1]++;
			if (x + 1 < m)
				array[y - 1][x + 1]++;
		}
		if (y + 1 < n) {
			if (x - 1 >= 0)
				array[y + 1][x - 1]++;
			if (x + 1 < m)
				array[y + 1][x + 1]++;
		}

		return array;
	}

	private static int[][] largeInk(int x, int y, int[][] array) {
		array = mediumInk(x, y, array);
		if (x - 2 >= 0) {
			array[y][x - 2]++;
		}

		if (y - 2 >= 0) {
			array[y - 2][x]++;
		}
		if (y + 2 < n) {
			array[y + 2][x]++;
		}

		if (x + 2 < m) {
			array[y][x + 2]++;
		}

		return array;
	}

}

Measured memory_bytes: 16972