akhauriyash/Code-Regression huggingface dataset:
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n := sc.getInt()
	as := sc.getInts(n)
	sort.Ints(as)

	ans := as[n-1]
	for i := (n + 1) / 2; i < n-1; i++ {
		ans += as[i] * 2
	}
	if n%2 == 1 {
		ans += as[n/2]
	}

	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 5936
S=input()
if S[0]=='A':
    f1=True
else:
    f1=False

count=0
for s in S[2:-1]:
    if s=="C":
        count+=1
if count==1:
    f2=True
else:
    f2=False

f3=True
for s in S:
    if s=="A" or s=="C":
        continue
    if s!=s.lower():
        f3=False
        break

if f1 and f2 and f3:
    print("AC")
else:
    print("WA")

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

const int N = 1e6 + 10, mod = 1e9 + 7;
typedef long long ll;
typedef pair <ll, ll> pii;

ll fact[N], rev[N], dp[N];

ll pw (ll a, ll b) {
	if(b == 0)	return 1LL;
	ll ans = pw(a, b / 2);
	ans *= ans;
	ans %= mod;
	if(b & 1)
		ans *= a;
	return ans % mod;
}

void prep() {
	fact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = (fact[i - 1] * i) % mod;
	rev[N - 1] = pw(fact[N - 1], mod - 2);
	for (int i = N - 2; ~i; i--) {
		rev[i] = (rev[i + 1] * (i + 1)) % mod;
	}
}

ll c(int n, int k) {
	ll ans = fact[n] * rev[k];
	ans %= mod;
	ans *= rev[n - k];
	return ans % mod;
}

pii p[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	prep();
	ll h, w, n;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i].first >> p[i].second;
	p[n] = {h, w};
	sort(p, p + n + 1);
	for (int i = 0; i <= n; i++) {
		dp[i] = c(p[i].first + p[i].second - 2, p[i].first - 1);
		for (int j = 0; j < i; j++) {
			if (p[j].first <= p[i].first && p[j].second <= p[i].second) {
				dp[i] = ((dp[i] - (dp[j] * c(p[i].first + p[i].second - p[j].first - p[j].second, p[i].first - p[j].first) % mod) + mod) % mod);
			}
		}
	}
	cout << dp[n] << "\n";
}

Measured memory_bytes: 18944
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
p = a[0]-1
result = False
ans = 1

if a[0] == 2:
    result = True
else:
    for i in range(10**5):
        if a[p] == 2:
            ans += 1
            result = True
            break
        else:
            p = a[p]-1
            ans += 1

if result == True:
    print(ans)
else:
    print("-1")


Measured memory_bytes: 7084
#include<cstdio>
int L,n,cnt,u[110],v[110],w[110],_2[110];
int main(){
	scanf("%d",&L);
	L--;
	_2[0]=1;
	for(int i=1;;i++){
		_2[i]=_2[i-1]*2;
		if(_2[i]>L+1){
			n=i;
			break;
		}
	}
	printf("%d ",n);
	int now=1;
	for(int i=1;i<n;i++,now*=2){
		u[++cnt]=i,v[cnt]=i+1,w[cnt]=now;
		u[++cnt]=i,v[cnt]=i+1,w[cnt]=0;
	}
	for(int i=n;i>=1;i--){
		if(L-now+1<_2[i-1]||L-now+1>=_2[i])continue;
		u[++cnt]=i,v[cnt]=n,w[cnt]=now;
		now=now+_2[i-1];
	}
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)
		printf("%d %d %d\n",u[i],v[i],w[i]);
}

Measured memory_bytes: 1708
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int x3 = (x2 - (y2-y1));
		int y3 = (y2 + (x2-x1));
		int x4 = (x3-(x2-x1));
		int y4 = (y3-(y2-y1));
		System.out.print(x3+" "+y3+" "+x4+" "+y4);
		sc.close();
	}
}

Measured memory_bytes: 22740
#include <cstdio>
#include <iostream>
using namespace std;
int arr[5], k, result;

int main()
{
    for(int i = 0; i < 5; i++)
    {
        scanf("%d", &arr[i]);
    }
    scanf("%d", &k);
    for(int i = 0; i < 4; i++)
    {
        for(int j = i + 1; j < 5; j++)
        {
            if(arr[j] - arr[i] > k)
            {
                result = 1;
            }
        }
    }
    if(result == 1)
    {
        printf(":(");
        return 0;
    }
    printf("Yay!");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
//#define MOD 1000000007
using namespace std;
typedef long long ll;

ll MOD;

const int MAX = 3010;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  reps(i, 2, MAX){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll c(int n, int k){ // 二項係数計算
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n=MOD-2, ll mod=MOD){ // a^n % MOD の計算
  ll res = 1;
  while (n > 0){
    if(n & 1) res = res * a % mod;
    a = a * a  % mod;
    n >>= 1;
  }
  return res;
}

vector<ll> lagrange_interpolation(vector<ll> xs, vector<ll> ys, const int mod){ // N個のi(0<=i<N)に対して、xs[i]を入れたらys[i]になる多項式P(x)= c_n*x^n +...+c_0 の cを返す
  const int N= xs.size();

  rep(i,N){
    xs[i]%=mod;
    ys[i]%=mod;
  }

  vector<ll> all_c(N+1);
  all_c[0]=1;

  rep(i,N){
    vector<ll> nxt(N+1);
    rep(j,N){
      nxt[j+1]=all_c[j];
    }
    rep(j,N){
      nxt[j]=(nxt[j]+mod-xs[i]*all_c[j]%mod)%mod;
    }
    all_c = move(nxt);
  }

  vector<ll> res(N);
  rep(i,N){
    ll qi=1;
    rep(j,N){
      if(i==j) continue;
      qi=qi*(xs[i]-xs[j]+mod)%mod;
    }
    qi= modpow(qi, mod-2, mod)*ys[i]%mod;

    auto tmp=all_c;
    repr(j,N-1,0){
      res[j] = (res[j] +qi*tmp[j+1])%mod;
      tmp[j]=(tmp[j]+tmp[j+1]*xs[i])%mod;
    }
  }

  return res;
}

void Main(){

  int p;
  cin>>p;

  vector<ll> xs(p),ys(p);

  rep(i,p){
    xs[i]=i;
    cin>>ys[i];
  }

  auto res= lagrange_interpolation(xs, ys, p);

  rep(i,p){
    cout<< res[i]<<" ";
  }
  cout<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<int, int> pr;
ll a[100005],b[100005],c[100005];
bool change[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll sa=0,sb=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sa+=a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        c[i]=b[i]-a[i];
        sb+=b[i];
    }
    if(sa<sb){
        cout<<-1<<endl;
        return 0;
    }
    vector<ll>q;
    ll need=0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(c[i]>0){
            ans++;
            need+=c[i];
    //        change[i]=true;
        }
        else{
            q.push_back(c[i]);
        }
    }
    sort(q.begin(),q.end());
    for(int i=0;i<q.size();i++){
        if(need<=0){
            break;
        }
        need+=q[i];
        ans++;
    }
    cout<<ans;
    return 0;
}

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

int main (){

  while(1){
    int a,b;
    string op;
    cin>>a>>op>>b;
    if(op == "?") break;

    int ans;
    if(op == "+") ans = a + b;
    if(op == "-") ans = a - b;
    if(op == "*") ans = a * b;
    if(op == "/") ans = a / b;

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



Measured memory_bytes: 3136
#include <stdio.h>

int main(void) {
    int a, x[4];
    scanf("%d", &a);
    x[0] = a/1000;
    x[1] = a/100%10;
    x[2] = a/10%10;
    x[3] = a%10;
    if((x[2]*10 + x[3] >= 1 && x[2]*10 + x[3] <= 12) && (x[0]*10 + x[1] >= 1 && x[0]*10 + x[1] <= 12)) printf("AMBIGUOUS\n");
    if((x[2]*10 + x[3] >= 1 && x[2]*10 + x[3] <= 12) && (x[0]*10 + x[1] == 0 || x[0]*10 + x[1] >= 13)) printf("YYMM\n");
    if((x[0]*10 + x[1] == 0 || x[0]*10 + x[1] >= 13) && (x[2]*10 + x[3] == 0 || x[2]*10 + x[3] >= 13)) printf("NA\n");
    if((x[0]*10 + x[1] >= 1 && x[0]*10 + x[1] <= 12) && (x[2]*10 + x[3] == 0 || x[2]*10 + x[3] >= 13)) printf("MMYY\n");
    return 0;
}


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


// 排他的論理和の最上位ビットの桁数 (0-origin)
int diff_max(int a,int b){
  int s=a^b,cnt=0;
  while(s){
    s/=2;
    cnt++;
  }
  return cnt;
}

int main(){
  int n; cin >> n;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      printf("%d ",diff_max(i,j));
    }
    cout << "\n";
  }
}


Measured memory_bytes: 512
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m, k = map(int, input().split())
cmb = combinations_count(n * m - 2, k - 2)
cmb %= 10 ** 9 + 7
ans = 0
for i in range(1, n):
    ans += i * cmb * m * m * (n - i)
    ans %= 10 ** 9 + 7

for i in range(1, m):
    ans += i * cmb * n * n * (m - i)
    ans %= 10 ** 9 + 7

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 75484
N = int(input())
results = ['AC', 'WA', 'TLE', "RE"]
d = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}

for _ in range(N):
	r = input()
	d[r] += 1

for i in range(4):
	print(results[i] + ' x ' + str(d[results[i]]))

Measured memory_bytes: 9208
from collections import deque
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()


def f(A, N):
    l = [0]*N
    a = (N+1)//2

    for i in range(a):
        l[i*2] = A[a-i-1]
    for i in range(N//2):
        l[i*2+1] = A[N-i-1]

    if N%2==1:
        l[-1], l[2] = l[2], l[-1]

    s = 0
    
    for i in range(N-1):
        s += abs(l[i]-l[i+1])

    return s


print(max(f(A, N), f(list(reversed(A)), N)))

Measured memory_bytes: 14764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define INF 9223372036854775807
const ll mod=998244353;



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    ll num=n,c=0,k=26;
    string ans;
    ll p=26,g=1;
    vector<ll> a;
    a.pb(0);
    ll y=0;
    while(1){
        a.pb(p);
        y++;
        if(n==p){
            for(ll i=0;i<y;i++)
                cout<<'z';
            return 0;
        }
        p+=k*26;
        k*=26;
        //cout<<p<<" ";
        if(p>=1000000000000001){
            a.pb(p);
            break;
        }
    }
    vector<ll> po;
    k=1;
    while(1){
        po.pb(k);
        k*=26;
        if(k>=1000000000000001){
            po.pb(k);
            break;
        }
    }
    while(1){
        ll len;
        for(ll i=0;i<a.size();i++){
            if(num<a[i]){
                len=i-1;
                break;
            }
        }
        ll r=num-a[len];
        //cout<<r<<" ";
        while(len>=0){
            ll q=(r-1)/po[len];
            //if(len>0) 
                ans.pb('a'+q);
            //else ans.pb('a'+q-1);
            r-=q*po[len];
            len--;
        }
        break;
    }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

sum = a[0]
ans1 = 0
if sum <= 0:
	sum = 1
	ans1 += abs(a[0]-1)

for i in range(1, n):
	nextsum = sum + a[i]
	if (sum>0 and nextsum<0) or (sum<0 and nextsum>0):
		sum = nextsum
	elif sum>0:
		ans1 += abs(nextsum+1)
		sum = -1
	elif sum<0:
		ans1 += abs(nextsum-1)
		sum = 1


sum = a[0]
ans2 = 0
if sum >= 0:
	sum = -1
	ans2 += abs(a[0]+1)

for i in range(1, n):
	nextsum = sum + a[i]
	if (sum>0 and nextsum<0) or (sum<0 and nextsum>0):
		sum = nextsum
	elif sum>0:
		ans2 += abs(nextsum+1)
		sum = -1
	elif sum<0:
		ans2 += abs(nextsum-1)
		sum = 1

print(min(ans1, ans2))

Measured memory_bytes: 14500
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        vector<pair<int, int> > walk(n);
        for(int i=0; i<n; i++){
            int p,a,b;
            cin >> p >> a >> b;
            walk[i] = make_pair(a+b, p);
        }
        pair<int, int> ans = *max_element(walk.begin(), walk.end());
        cout << ans.second << " " << ans.first << endl;
    }
    return 0;
}



Measured memory_bytes: 3180
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll n,k;
ll a[110];
ll dp[110][MAXN];
ll sum[MAXN];

int main()
{
    cin >> n >> k;
    for (int i = 1;i <= n;i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 1;i <= n;i++){
        memset(sum,0,sizeof(sum));
        sum[0] = dp[i - 1][0];
        for (int j = 1;j <= k;j++){
            sum[j] = (sum[j - 1] % MOD + dp[i-1][j] % MOD) % MOD;
        }
        //cout <<"LLL ";
        //for(int i = 0;i <= k;i++){
        //    cout << sum[i] << sep;
        //}
        //cout << endl;
        for (int j = 0;j <= k;j++){
            if(j - a[i] - 1 >= 0)
                dp[i][j] =  sum[j] - sum[j - a[i] - 1];
            else
                dp[i][j] = sum[j];
            dp[i][j] += MOD;
            dp[i][j] %= MOD;
            //cout << ":: " << i << tab << j << tab << max(j - a[i] - 1 ,(ll) 0) << tab << dp[i][j] << endl;
        }
    }
    cout << dp[n][k] << endl;
}


Measured memory_bytes: 79360
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = 0; i < N; i++) {
			boolean swap = false;
			int min = i;
			for (int j = i + 1; j < N; j++) {
				if (A[j] < A[min]) {
					min = j;
					swap = true;
				}
			}
			if (swap) {
				cnt++;
			}
			int tmp = A[i];
			A[i] = A[min];
			A[min] = tmp;
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vector<int> res = p;
	sort(all(res));

	int k = 1;
	int a, b;
	do {
		if (res == p) a = k;
		if (res == q) b = k;
		k++;
	} while (next_permutation(all(res)));

	dunk(abs(a - b));

	return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

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

x_sorted=sorted(x)
c = (x_sorted[n//2-1]+x_sorted[n//2])/2

for i in range(n):
    if x[i]>=c:
        print(x_sorted[n//2-1])
    else:
        print(x_sorted[n//2])


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

int main(void){
    int N;
    int ans =0;
    scanf("%d", &N);

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if (i*j<N){
                ans++;
            }
            else{
                break;
            }
        }
    }

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


Measured memory_bytes: 1732
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1) {
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=1;i<=100;i++)
	{
		if(a*i%b==c)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
a,b=input().split()
List=[]
x=0
for i in range(2*N):
  if i%2 == 0:
    x=a[i//2]
    List.append(x)
  else:
    x=b[(i-1)//2]
    List.append(x)

p=List[0]
for i in range(1,len(List)):
    p=p+List[i]
    
print(p)

Measured memory_bytes: 3060
s = input()
k = "keyence"
j = 0
"""
for i in range(len(s)):
    if s[i]==k[j]:
        j+=1
    if j==7:
        print("YES")
        exit()
"""
#部分列を取り除けるのは一度だけ
for i in range(7):
    if s[:i]+s[-7+i:]==k:
        print("YES")
        exit()

print("NO")
    



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

int c2(int n)
{
    if(n <= 1)
    {
        return 0;
    }
    else
    {
        return (n*(n-1))/2;
    }
}

int main() 
{
    int n, m;
    cin>>n>>m;
    int a = c2(n);
    int b = c2(m);
    cout<<a+b;
    return 0;
}

Measured memory_bytes: 256
local someTable = {}
for i=1,10 do
    someTable[10^i] = true
end

function suibian(a)
    local total = 0
    if someTable[a] then
        print(10)
        return
    end
    a = tostring(a)
    for i=1,string.len(a) do
        total = tonumber(string.sub(a,i,i))+total
    end
    print(total)
end
local n = io.read("*n")
suibian(n)

Measured memory_bytes: 760
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end


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

    string s;
    in >> s;
    vector<ll> alphabet(26, 1);
    REP(i, s.size()){
        int num = s[i] - 'a';
        alphabet[num] = 0;
    }
    REP(i, 26){
        if (alphabet[i] != 0){
            out << (char)('a' + i) << endl;
            break;
        }else if(i == 25){
            out << "None" << endl;
        }
    }
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R, K, X, A, B, C, Z;
ll ans;
string S;
ll a[100000000];
bool channel[31][200001];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin >> N >> Z >> W;
	rep(i, 0, N) {
		cin >> a[i];
	}
	if (N == 1)cout << abs(a[0] - W) << endl;
	else {
		cout << max(abs(a[N - 1] - W), abs(a[N - 1] - a[N - 2])) << endl;
	}
	cin >> ans;
	return 0;
}

Measured memory_bytes: 2304
N,K = map(int,input().split())

#list =[0 for i in range(N)]
p = 0
for i in range(N):
    i = i+1
    l = i
    b = 0
    if K<=i:
        p += 1/N
    else:
        while 1:
            if K <= i:
                p += (1/N)*(1/(2**b))
                #p += 1/2**b
                break
            else:
                b += 1
                i = i*2
print('{:.9f}'.format(p))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
const int mod=20010905;
int main(){
    int n,a[200004];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int min=a[0];
    int num=0;
    for(int i=0;i<n;i++){
        if(a[i]<=min){
            num++;
            min=a[i];}
    }
    cout<<num<<endl;
}


Measured memory_bytes: 1024
/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
#include <unordered_map>
#include <random>
 
#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (ll i = 0; i < (ll)n; i++)
#define mp make_pair
#define ui unsigned int
 
using namespace std;

const int maxn = (int)1e5 + 10;
vector <int> ed[maxn];
int f[maxn];
int k;
int cnt = 0;

int dfs(int v) {
	int h = 0;
	for (int i = 0; i < (int)ed[v].size(); i++) {
		h = max(h, dfs(ed[v][i]));
	}

	if (h == k - 1 && f[v] != 1) {
		cnt++;
		return 0;
	}

	return h + 1;
}

int main() {
	int n;

	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		scanf("%d", &f[i]);
	}

	if (k == 1) {
		for (int i = 1; i <= n; i++) {
			if (f[i] != 1) {
				cnt++;
			}
		}

		cout << cnt << endl;

		return 0;
	}

	if (f[1] != 1) {
		f[1] = 1;
		cnt++;
	}

	for (int i = 2; i <= n; i++) {
		ed[f[i]].push_back(i);
	}

	dfs(1);

	cout << cnt << endl;

	return 0;
}


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

using namespace std;

int main() {
  int t;
  cin >> t;
  for (int ti = 0; ti < t; ti++) {
    int gx, gy;
    cin >> gx >> gy;

    int m[16][16][16][16];
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        for (int k = 0; k < 16; k++) {
          for (int l = 0; l < 16; l++) {
            m[i][j][k][l] = 1;
          }
        }
      }
    }

    int p;
    cin >> p;
    for (int i = 0; i < p; i++) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      m[x1][y1][x2][y2] = 0;
      m[x2][y2][x1][y1] = 0;
    }

    int dp[16][16];
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        dp[i][j] = 0;
      }
    }

    dp[0][0] = 1;

    for (int i = 1; i <= gx; i++) {
      if (m[i - 1][0][i][0]) {
        dp[i][0] = min(dp[i - 1][0], 1);
      }
    }

    for (int i = 1; i <= gy; i++) {
      if (m[0][i - 1][0][i]) {
        dp[0][i] = min(dp[0][i - 1], 1);
      }
    }

    for (int i = 1; i <= gx; i++) {
      for (int j = 1; j <= gy; j++) {
        if (m[i - 1][j][i][j]) {
          dp[i][j] += dp[i - 1][j];
        }
        if (m[i][j - 1][i][j]) {
          dp[i][j] += dp[i][j - 1];
        }
      }
    }

    if (dp[gx][gy] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << dp[gx][gy] << endl;
    }
  }
}



Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
int n,m,t[10005],p[10005],x[10005],i,j,ans[10005];
int main()
{scanf("%d",&n);
for(i=1;i<=n;i++)
  scanf("%d",&t[i]);
scanf("%d",&m);
for(i=1;i<=m;i++)
  {scanf("%d%d",&p[i],&x[i]);
  for(j=1;j<=n;j++)
    {if(p[i]==j)
      {ans[i]+=x[i];
      continue;
      }
    ans[i]+=t[j];
    }
  }
for(i=1;i<=m;i++)
  cout<<ans[i]<<endl;
return 0;
}

Measured memory_bytes: 256
//12
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int w;cin>>w,w!=-1;){
    cout<<4280-1150-max(0,w-10)*125-max(0,w-20)*15-max(0,w-30)*20<<endl;
  }
  return 0;
}

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

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

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

ll a=100;
int count=0;
while(a<x){
a+=a/100;
count++;
}
cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int H;
int a[100000];
int b[100000];

void solve()
{
	sort(a, a + N);
	sort(b, b + N);
	int res = 0;
	int m = a[N - 1];
	for (int i = N - 1; i >= 0; i--) {
		if (m > b[i]) break;
		H -= b[i];
		res++;
		if (H <= 0) {
			cout << res << endl;
			return;
		}
	}
	int t = H / a[N - 1];
	H -= t * a[N - 1];
	if (H) cout << res + t + 1 << endl;
	else cout << res + t << endl;
}


int main()
{
	cin >> N >> H;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
	int n, m, l;
  	cin >> n >> m >> l;
	ll s, a[n][m], b[m][l];
  	for (int i = 0; i < n; i++){
    	for (int j = 0; j < m; j++){
        	cin >> a[i][j]; 
        }
    }
  	for (int i = 0; i < m; i++){
    	for (int j = 0; j < l; j++){
        	cin >> b[i][j]; 
        }
    }
  	for (int i = 0; i < n; i++){
    	for (int j = 0; j < l; j++){
         	s = 0;
        	for (int k = 0; k < m; k++){
        		s += a[i][k]*b[k][j];
        	}
          	cout << s;
          	if (j != l-1) cout << " ";
          	else cout << endl;
        }
    }
  
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=1,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> n;
       rrep(i,1,n+1){
           ans*=i;
           ans%=1000000007;
       }
       Cout(ans);
return 0;
}


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

int main(){
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i,n) cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  ll N;
  cin >> N;
  ll ans = 1;
  vector<ll> a(N);
  rep(i,N){
    cin >> a.at(i);
    if(a.at(i) == 0 ){
      cout << "0" << endl;
      return 0;
    }
  }
  rep(i,N){
    if(ans > 1000000000000000000 / a.at(i)){
      cout << -1 << endl;
      return 0;
    }
    ans *= a.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = new string('x', sS[0].Length);

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
from collections import defaultdict
dic = defaultdict(int)
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
h = []

r, s, p = 0, 0, 0
for i in range(N):
    if i>=K:
        if T[i]==h[i-K]:
            h.append("x")
            continue
    
    if T[i]=="r":
        h.append("r")
        p+=1
    elif T[i]=="p":
        h.append("p")
        s+=1
    elif T[i]=="s":
        h.append("s")
        r+=1

print(p*P + r*R + s*S)

Measured memory_bytes: 80280
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    std::string pre = S.substr(0, 2);
    std::string post = S.substr(2);
    if("01" <= pre && pre <= "12"){
        if("01" <= post && post <= "12"){
            std::cout << "AMBIGUOUS" << std::endl;
        }else{
            std::cout << "MMYY" << std::endl;
        }
    }else{
        if("01" <= post && post <= "12"){
            std::cout << "YYMM" << std::endl;
        }else{
            std::cout << "NA" << std::endl;
        }
    }
    return 0;
}


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

int main(){
	int n[4];
	int c[4] = {0};
	for (int i = 0; i<4; i++) {
		cin >> n[i];
		switch(n[i]){
			case 1:
				c[0] = 1;
				break;
			case 9:
				c[1] = 1;
				break;
			case 7:
				c[2] = 1;
				break;
			case 4:
				c[3] = 1;
				break;
		}
	}
	if(c[0]&&c[1]&&c[2]&&c[3]) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int A = 20;

int bit(int mask, int i) {
  return (mask >> i) & 1;
}

int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<string> a[A];

  for (int mask = 0; mask < (1 << n); ++mask) {
    string t(n, 'z');
    int l = 0, r = n - 1;
    int sz = __builtin_popcount(mask);
    for (int i = 0; i < n; ++i) {
      if (bit(mask, i)) 
        t[l++] = s[i];
      else
        t[r--] = s[i];
    }
    //cerr << sz << ": " << t << "\n";
    a[sz].push_back(t);
  }

  for (int i = 0; i <= n; ++i)
    sort(all(a[i]));

  auto cnt = [&](int k, const string &t) {
    return upper_bound(all(a[k]), t) - lower_bound(all(a[k]), t);
  };

  ll ans = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    string t(n, 'z');
    int l = 0, r = n - 1;
    int sz = __builtin_popcount(mask);
    for (int i = 0; i < n; ++i)
      if (bit(mask, i))
        t[l++] = s[2 * n - 1 - i];
      else
        t[r--] = s[2 * n - 1 - i];


    //if (cnt(n - sz, t)) {
      //cerr << n - sz << ", " << t << "\n";
    //}
    ans += cnt(sz, t);
  }

  cout << ans << "\n";
}



Measured memory_bytes: 18784
#include<bits/stdc++.h>
#define itn int
#define lli unsigned long long int
#define REP(a,n) for(int i=a;i < n;i++)
#define REP2(a,n) for(int j = a;j<n;j++)
#define scanf scanf_s
using namespace std;
int main(void) {
	lli n, k;
	vector<lli> H;
	cin >> n >> k;
	lli temp = 0;
	for (lli i = 0; i<n; i++) {
		cin >> temp;
		H.push_back(temp);
	}
	sort(H.begin(), H.end());
	for (lli i = 0; i < k && !H.empty(); i++) {
		H.pop_back();
	}
	lli ans = 0;
	for (lli i = 0; i < H.size(); i++) {
		ans += H[i];
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int d[10000010];

int sum(int n){
	return n*(n+1)/2;
}

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

	int ans = 0;
	for(int i = 1;i <= n;i++){
		ans += i*sum(n/i);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main() {
    long long N, Y;
    cin >> N >> Y;
    FOR(i, 0, N+1) {
        FOR(j, 0, N+1-i) {
            if(10000*i + 5000*j + 1000*(N-i-j) == Y){
                cout << i << " " << j << " " << N-i-j <<"\n";
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << "\n";
}

Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;
	public static void main(String[] args)throws Exception{
		InputStream in = System.in;
		sc = new Scanner(in);

		while(true){
			int a, b, x;
			x = sc.nextInt();
			a = sc.nextInt();
			b = sc.nextInt();

			if(a-b >= 0) {
				System.out.println("delicious");
				break;
			} else if(Math.abs(a-b) <= x) {
				System.out.println("safe");
				break;
			} else if(Math.abs(a-b) > x){
				System.out.println("dangerous");
				break;
			}
		}
	}
}


Measured memory_bytes: 23764
n=int(input())
a=list(map(int,input().split()))
zerocounter=0
for i in range(n):
  if a[i]==0:
    zerocounter=1
    break
if zerocounter==1:
  print(0)
else:
  ans=1
  for i in range(n):
    ans=ans*a[i]
    if ans>10**18:
      ans=-1
      break
  print(ans)

Measured memory_bytes: 21592
a = input()
b = input()
c = input()
 
# 文字のマッチング(?はワイルドカード)
def match(a, b):
    return a=="?" or b=="?" or a==b
 
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
 
def check(a, b, ab):
    for i in range(len(a)):
        for j in range(len(b)):
            if not match(a[i], b[j]):
                ab[i-j+50000] = False
 
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
 
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
 
ans = len_a + len_b + len_c
 
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
    # j = CをAに対していくつスライドして置くか
    for j in range(-2 * len_max, 2 * len_max + 1):
        if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
            ans = min(ans, max(len_a, len_b+i, len_c+j) - min(0, i, j))
 
print(ans)

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	string s; cin>>s;
	int n = s.size();
	int ans = n;
	for(int i = 1; i < n; i++){
		if(s[i] != s[i - 1])ans = min(ans, max(i, n - i));
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   if(n & 1)
   {
       cout<<0<<endl;
       return 0;
   }
   else
   {
       int cnt=0;
       n/=2;
       for(int i=5;i<=n;i*=5)
       {
           cnt+=(n/i);
       }
       cout<<cnt<<endl;
   }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

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

def dfs(s, ans):
    if len(s) == 0:
        print('\n'.join(map(str, reversed(ans))))
        exit()
        return
    for i in range(len(s)):
        #if s[i] == i+1:
        #if s[i] == i+1 and max(s[:i] + [0]) >= i:
        if s[i] == i+1:
            s1 = s[:i] + s[i+1:]
            allok = True
            for j in range(len(s1)):
                if s1[j] > j+1:
                    allok = False
                    break
            #print(s[:i], s[i+1:],i)
            if allok:
                ans.append(s[i])
                dfs(s1, ans)
    if len(ans) > 0:
        ans.pop()

dfs(b, [])

print('-1')


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

int main(){
  int N, f_x;
  int N_tmp;
  int reminder;
  cin >> N;
  int N_fix = N;
  
  while(true){
    N_tmp = N;
    reminder = N % 10;  // 余り
    N = (int)N / 10;  // 商
    // cout << "N_tmp" << N_tmp << endl << "reminder" << reminder << endl << "N" << N << endl;
    
    f_x += reminder;
    
    if (reminder==N_tmp){
      break;
    } else {
      ;
    }
    
  }
  // cout << f_x << endl;
  
  if (N_fix % f_x==0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
n,k = map(int,input().split())
S = input()
S += '+'
L = []
cur = S[0]
cnt = 1
for i in range(1,n+1):
    if cur == S[i]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
        cur = S[i]
if len(L)%2 == 0:
    if len(L)//2 <= k:
        print(n-1)
    else:
        ans = 0
        for i in range(2*k+1):
            ans += L[i]
        for i in range(2*k+1,len(L)):
            ans += L[i]-1
        print(ans-1)
else:
    if (len(L)-1)//2 <= k:
        print(n-1)
    else:
        ans = 0
        for i in range(2*k+1):
            ans += L[i]
        for i in range(2*k+1,len(L)):
            ans += L[i]-1
        print(ans-1)

Measured memory_bytes: 4092
#include <iostream>
#include <string>
using namespace std;
string s;
int n;

int main(){
	cin>>s;
	n=s.size();
	int b=0,r=0;
	for (int i=0;i<n;i++){
		if (s[i]=='0') b++;
		else r++;
	}
	cout<<min(r,b)*2<<endl;
	return 0;
} 

Measured memory_bytes: 512
use proconio::{input, marker::Usize1};
use std::cell::RefCell;

fn main() {
    input! {
        n: usize, m: u64, q: usize,
        qs: [(Usize1, Usize1, u64, u64); q]
    }
    let mut sq = Vec::new();
    let mut dfs = unsafe { std::mem::uninitialized() };
    let rec = &mut dfs as *mut dyn FnMut() -> u64;
    dfs = || unsafe {
        if sq.len() == n {
            qs.iter()
                .map(|&(a, b, c, d)| if sq[b] - sq[a] == c { d } else { 0 })
                .sum()
        } else {
            let last = *sq.last().unwrap_or(&1);
            (last..=m)
                .map(|x| {
                    sq.push(x);
                    let ret = (*rec)();
                    sq.pop();
                    ret
                })
                .max()
                .unwrap()
        }
    };
    println!("{}", dfs());
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    string in;
    cin >> in;
    int n = in.size();
    bool use[26];
    memset(use, false, sizeof(use));
    for (auto i : in) {
        int t = i - 97;
        use[t] = true;
    }
    for (int i = 0; i < 26; ++i) {
        if (!use[i]) {
            cout << (char)(i+97);
            return 0;
        }
    }
    cout << "None";
    return 0;
}

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

int main()
{
   static long i,j,k,l;
   long n;
   long cnt = 0;
   long left,right,mid;
   long ans = 0;
   int a,b;
   static int H[10000];
   static int W[10000];


   for(i = 0;; i++) {
      scanf("%d %d",&H[i],&W[i]);
      if(H[i] == 0)
         break;
   }
   for(j = 0; j < i; j++) {
      for(l = 0; l < W[j]; l++)
         putchar('#');
         putchar('\n');
      for(k = 1; k < H[j]-1; k++) {
         putchar('#');
         for(l = 1; l < W[j]-1; l++) {
            putchar('.');
         }
         putchar('#');
         putchar('\n');
      }
      for(l = 0; l < W[j]; l++)
         putchar('#');
      putchar('\n');
      putchar('\n');
   }

   return 0;
}

Measured memory_bytes: 1008
#include<iostream>
#include<vector>

using namespace std;

vector< vector<int> > MakeCombination(int, int);
void MakeCombinationInner(vector<int>&, int);
void CountSum(vector< vector<int> >, vector< vector<int> >, vector<int>, int, int, int&);
int CountSumInner(vector<int>, int);

int main(){
  int i, j, n, m, x, sum, _sum;
  vector<int> _data, count_data;
  vector< vector<int> > data, comb_data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<m; ++i)
      count_data.push_back(0);

    for(i=0; i<n; ++i){
      for(j=0; j<m; ++j){
	cin >> x;
	if(x == 0) ++count_data[j];
	_data.push_back(x);
      }
      data.push_back(_data);
      _data.clear();
    }

    sum = CountSumInner(count_data, n);

    for(i=0; i<data.size(); ++i){
      comb_data = MakeCombination(n, i+1);
      _sum = sum;
      CountSum(data, comb_data, count_data, n, m, _sum);
      if(sum < _sum) sum = _sum;
      if(sum == n*m) break;
    }

    cout << sum << endl;
    count_data.clear();
    comb_data.clear();
    data.clear();
  }
  return 0;
}

vector< vector<int> > MakeCombination(int n, int m){
  int i;
  vector<int> _data;
  vector< vector<int> > data;

  for(i=0; i<m; ++i)
    _data.push_back(i);
  data.push_back(_data);

  while(1){
    MakeCombinationInner(_data, n);
    data.push_back(_data);

    if(_data[0] == n-m && _data[_data.size()-1] == n-1)
      break;
  }
  return data;
}

void MakeCombinationInner(vector<int>& data, int n){
  int i, j;
  for(i=data.size()-1, j=1; i>=0; --i, ++j){
    if(data[i] != n-j){
      ++data[i];
      for(j=i+1; j<data.size(); ++j)
        data[j] = data[j-1]+1;
      return;
    }
  }
}

void CountSum(vector< vector<int> > data, vector< vector<int> > comb_data,
	      vector<int> count_data, int n, int m, int& sum){
  int i, j, k, _sum;
  vector<int> _count_data;

  for(i=0; i<comb_data.size(); ++i){
    _count_data = count_data;
    for(j=0; j<comb_data[i].size(); ++j){
      for(k=0; k<data[comb_data[i][j]].size(); ++k){
	if(data[comb_data[i][j]][k] == 0) --_count_data[k];
	else ++_count_data[k];
      }
    }
    _sum = CountSumInner(_count_data, n);
    if(sum < _sum) sum = _sum;
    if(sum == n*m) return;
  }
}

int CountSumInner(vector<int> data, int n){
  int i, sum;
  for(i=0, sum=0; i<data.size(); ++i){
    if(data[i] > n/2) sum += data[i];
    else sum += (n - data[i]);
  }
  return sum;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int a; cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;

int div_count(int);

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

    // 割れる最大回数の計算
    int count = 0, tmp;
    for (int i=0; i < N; i++) {
        int A_i;
        std::cin >> A_i;

        tmp = div_count(A_i);
        // 2の倍数の判定 2の倍数でなければ 0 を出力
        if (tmp >= 1) {
            if (i == 0) {
                count = tmp;  // i==0 の時、ひとまず格納
            }

            if (tmp < count) {
                // div_count(割れる数) が小さければcount を更新
                // 因数に一番少なく2が入っているものの割れる回数を抽出
                count = tmp;
            }
        } else {
                count = 0;
                break;
        }
    }
    std::cout << count << std::endl;

    return 0;
}

int div_count(int num) {
    int count = 0;
    while(num % 2 == 0) {
        num /= 2;
        count++;
    }
    return count;
}


Measured memory_bytes: 256