akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
using namespace std;
//#define int long long int

int bottom(int a[], int n, int k)
{
	int dp[n + 1] = {0};
	for (int i = 1; i < n; i++)
	{
		dp[i] = abs(a[i] - a[i - 1]) + dp[i - 1];
		for (int j = 2; j <= k && (i - j) >= 0; j++)
			dp[i] = min(dp[i], (abs(a[i] - a[i - j]) + dp[i - j]));
		//cout << dp[i] << " ";
	}
	return dp[n - 1];
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << bottom(a, n, k);
}
// 5 3
// 10 30 40 50 20

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

int H, W, N;
int Sr, Sc;
string S[2];


bool hoge() {    
    int x = 1, y = W;
    for (int i = N - 1; i >= 0; --i) {
        if (i < N - 1 && S[1][i] == 'R') {
            x = max(1, x-1);
        } else if (i < N - 1 && S[1][i] == 'L') {
            y = min(W, y+1);
        }
        if (S[0][i] == 'L') {
            x += 1;
        } else if (S[0][i] == 'R') {
            y -= 1;
        }
        if (x > y) return false;
    }

    if (Sc < x || Sc > y) return false;

    x = 1, y = H;
    for (int i = N - 1; i >= 0; --i) {
        if (i < N - 1 && S[1][i] == 'D') {
            x = max(1, x-1);
        } else if (i < N - 1 && S[1][i] == 'U') {
            y = min(H, y+1);
        }
        if (S[0][i] == 'U') {
            x += 1;
        } else if (S[0][i] == 'D') {
            y -= 1;
        }
        if (x > y) return false;
    }
    
    if (Sr < x || Sr > y) return false;
    return true;
}

void solve() {
    cin >> H >> W >> N;
    cin >> Sr >> Sc;
    cin >> S[0] >> S[1];

    cout << (hoge() ? "YES" : "NO") << endl;
}

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


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

int main(){
  int N,K;
  cin >> N >> K;
  if(K==1){
    cout << "YES" << endl;
  }else if(N<=K){
    cout << "NO" << endl;
  }else if(N%2 && N/2+1 >=K){
    cout << "YES" << endl;
  }else if(!(N%2) && N/2 >= K){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string S1,S2;
    cin>>S1>>S2;
    int rui1A[100001]={0};
    int rui2A[100001]={0};
    int rui1B[100001]={0};
    int rui2B[100001]={0};
    for(int i=1;i<=S1.size();i++){
        rui1A[i]=rui1A[i-1];
        if(S1[i-1]=='A')rui1A[i]=rui1A[i-1]+1;
    }
    for(int i=1;i<=S1.size();i++){
        rui1B[i]=rui1B[i-1];
        if(S1[i-1]=='B')rui1B[i]=rui1B[i-1]+1;
    }
    for(int i=1;i<=S2.size();i++){
        rui2A[i]=rui2A[i-1];
        if(S2[i-1]=='A')rui2A[i]=rui2A[i-1]+1;
    }
    for(int i=1;i<=S2.size();i++){
        rui2B[i]=rui2B[i-1];
        if(S2[i-1]=='B')rui2B[i]=rui2B[i-1]+1;
    }
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int kari1A=rui1A[b]-rui1A[a-1];
        int kari1B=rui1B[b]-rui1B[a-1];
        int kari2A=rui2A[d]-rui2A[c-1];
        int kari2B=rui2B[d]-rui2B[c-1];
        kari1A%=3;
        kari2A%=3;
        kari2B%=3;
        kari1B%=3;
        if(kari1A==kari1B&&kari2A==kari2B)puts("YES");
        else if(((kari1A==0&&kari1B==1)||(kari1A==1&&kari1B==2)||(kari1A==2&&kari1B==0))&&((kari2A==0&&kari2B==1)||(kari2A==1&&kari2B==2)||(kari2A==2&&kari2B==0)))puts("YES");
        else if(((kari1A==0&&kari1B==2)||(kari1A==2&&kari1B==1)||(kari1A==1&&kari1B==0))&&((kari2A==2&&kari2B==1)||(kari2A==1&&kari2B==0)||(kari2A==0&&kari2B==2)))puts("YES");
        else puts("NO");
    }
    return 0;
}


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

int main(){
	int k; cin>>k;
	ll ans=0;
	for(int i=1; i<=k; i++){
		for(int j=1; j<=k; j++){
			for(int l=1; l<=k; l++){
				ans+=__gcd(i,__gcd(j,l));
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include<stdio.h>

int main(){
int n[8]={};
int N,x;

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=0;i<N;i++)
{
scanf("%d",&x);
if(x<10)n[0]++;
else if(x<20)n[1]++;
else if(x<30)n[2]++;
else if(x<40)n[3]++;
else if(x<50)n[4]++;
else if(x<60)n[5]++;
else if(x>=60)n[6]++;
}
for(int i=0;i<7;i++)
printf("%d\n",n[i]);
for(int i=0;i<7;i++)
	n[i]=0;

}
return 0;
}

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

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

	int	n, k;
	cin >> n >> k;
	vector<ll> V(n);
	rep(i, n)
		cin >> V.at(i);
	sort(V.begin(), V.end(), greater<ll>());
	if (k >= V.size())
		cout << '0' << endl;
	else
	{
		vector<ll>::iterator it;
		it = V.begin();
		advance(it, k);
		cout << accumulate(it, V.end(), 0LL) << endl;
	}
}


Measured memory_bytes: 1792
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iter = input.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let expected_values: Vec<f64> = iter
        .map(|p| expect_value_for_dice(p.parse().unwrap()))
        .collect();

    let mut sums: Vec<f64> = Vec::with_capacity(n - k + 1);
    sums.push(expected_values[0]);
    for i in 1..n {
        let sum = sums[i - 1] + expected_values[i];
        sums.push(sum);
    }

    let mut max: f64 = sums[k - 1];
    for i in k..n {
        let sum = sums[i] - sums[i - k];
        if sum > max {
            max = sum;
        }
    }

    return format!("{:.12}", max);
}

fn expect_value_for_dice(p: u32) -> f64 {
    let sum = (1..p+1).fold(0, |a, b| a + b);
    return (sum as f64) / (p as f64);
}

Measured memory_bytes: 12540
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<int> h(n);
	for(int i = 0; i < n; ++i) std::cin >> h[i];

	std::vector<int> dh(n);
	for(int i = 0; i < n; ++i) {
		if(i == 0) dh[i] = h[i];
		else dh[i] = h[i] - h[i-1];
	}

	int n_water_min = 0;
	for(int i = 0; i < n; ++i) {
		n_water_min += std::max(dh[i], 0);
	}

	std::cout << n_water_min << std::endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from itertools import combinations
from collections import deque


def solve():
  uv = set()
  N,K = map(int, input().split())
  if N==2:
    if K==0:
     uv.add((1,2))
  elif N==3:
    if K==0:
      uv = set((1,2),(2,3),(1,3))
    elif K==1:
      uv = set((1,2),(2,3))
  elif N >= 4:
    if K <= (N-1)*(N-2)//2:
      for i in range(2,N+1):
        uv.add((1,i))
      combi = deque(combinations(range(2,N+1),2))
      K = (N-1)*(N-2)//2 - K
      while K > 0:
        p,q = combi.popleft()
        uv.add((p,q))
        K -= 1
  return uv


if __name__ == "__main__":
  uv = solve()
  if len(uv)==0:
    print(-1)
  else:
    print(len(uv))
    for u,v in uv:
      print(u,v)

Measured memory_bytes: 43760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  long long a[3];
  cin >> a[0] >> a[1] >> a[2];

  sort(a, a+3);
  if (a[0]%2 == 0 || a[1]%2 == 0 || a[2]%2 == 0) {
    cout << "0" << endl;
  } else {
    cout << a[0]*a[1] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > v[100005];
bool use[100005];
int d[100005];
void dfs(int n,int w)
{
	use[n]=true;
	d[n]=(w&1);
	for(int i=0;i<v[n].size();i++)
	{
	  if(!use[v[n][i].first])
	    dfs(v[n][i].first,v[n][i].second+w);
    }
}
int n,mb;
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		v[a].push_back(make_pair(b,c));
		v[b].push_back(make_pair(a,c));
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		cout<<d[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > v(101);
int dp[101][2] = { 0 };
int n, t = 0;
 
void dfs(int a) {
    if (dp[a][0] == 0) { t++; dp[a][0] = t; }
    else { return; }
    for (int i = 0;i < v[a].size();i++) {
        if (dp[v[a][i]][0] == 0) {
            dfs(v[a][i]);
        }
    }
    if (dp[a][1] == 0) { t++; dp[a][1] = t; }
}
 
int main() {
    cin >> n;
    for (int i = 0; i < n;i++) {
        int u,k; cin >> u >> k;
        for (int j = 0; j < k;j++) {
            int x; cin >> x;
            v[u].push_back(x);
        }
    }
    for (int i = 1; i <= n;i++) {
        dfs(i);
    }
    for (int i = 1; i <= n;i++) {
        cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
    }
}


Measured memory_bytes: 3164
using System;

class P
{
    static void Main(string[] _)
    {
        _ = Console.ReadLine().Split(' ');
        int w = int.Parse(_[0]);
        int a = int.Parse(_[1]);
        int b = int.Parse(_[2]);
        int result = (Math.Max(a, b) - Math.Min(a, b)) - w;
        Console.WriteLine(result > 0 ? result : 0);
    }
}


Measured memory_bytes: 11092
def binary_search(border, b):
    ok = b
    ng = n
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if L[mid] < border:
            ok = mid
        else:
            ng = mid

    return ok


n = int(input())
L = sorted(list(map(int, input().split())))
ans = 0

for a in range(0,n-1):
    for b in range(a+1, n):
        a_b = L[a] + L[b]
        ans += binary_search(a_b, b) - b

print(ans)

Measured memory_bytes: 74544
#include<stdio.h>
#include<math.h>
int main(){
  int n,y,b,r,t;
  int i,mi;
  double m,max;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    scanf("%d",&y);
    max=0.0;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&b,&r,&t);
      if(t==1)m=1.0+(double)y*r/100.0;
      else    m=pow((1.0+r/100.0),(double)y);
      if(max<m){
	max=m;
	mi=b;
      }
    }
    printf("%d\n",mi);
  }
  return 0;
}
	

Measured memory_bytes: 692
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

const int mod = 1000000007;
int binpow(int a, int b, int mod)
{
    int ans = 1;
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 1;
    while (b)
    {
        if (b & 1)
            ans = ((ans % mod) * (a % mod)) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        b >>= 1;
    }
    return ans % mod;
}

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        if (n == 1)
        {
            cout << 0 << "\n";
            return 0;
        }
        int ans = binpow(10, n, mod) - (2 * (binpow(9, n, mod)) % mod) + binpow(8, n, mod) + mod;
        cout << ans % mod << "\n";
    }
}


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

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int y = y1- y2;
  int x = x2 - x1;
  cout << y + x2 << ' ' << x + y2 << ' ' << y + x1 << ' ' << x + y1 << endl;
  return 0;
}

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    
    while(true){
         c -= b;
         if(c<=0){
             cout << "Yes" << endl;
             break;
         }

         a -= d;

         if(a<=0){
             cout << "No" << endl;
             break;
         }
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define lriii(a,b,c) lrii(a,b),lri(c)
#define pb push_back
#define _1 first
#define _2 second
#define ALL(s) s.begin(),s.end()
#define SZ(x) int((x).size())

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int alphabet = 26;
const double PI = 3.1415926535;
const int MAXINT = 1e5+1;

int main(){
	int n, h[MAXINT];

	ri(n);
	FOR(i,0,n) ri(h[i]);

	int dp[n]; dp[n-1] = 0, dp[n-2]=abs(h[n-1]-h[n-2]);
	ROF(i,n-3,-1){
		dp[i] = INF;
		dp[i] = min( dp[i], abs(h[i]-h[i+1]) + dp[i+1] );
		dp[i] = min( dp[i], abs(h[i]-h[i+2]) + dp[i+2] );
	}
	printf("%d\n", dp[0]);
	return 0;
}
/*

*/  


Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int A, B;
    cin >> A >> B;
    if (A+B >= 10)cout << "error" << endl;
    else cout << A+B << endl;
    
}

Measured memory_bytes: 3600
from collections import deque
n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort(reverse = True)
queue = deque()
queue.append(a_ls[0])
for i in range(1,n):
    queue.append(a_ls[i])
    queue.append(a_ls[i])
ans = 0
for _ in range(n-1):
    ans += queue.popleft()
print(ans)




Measured memory_bytes: 32344
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);
using namespace std;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(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;
}


int main(){
  ll n;
  cin >> n;
  ll ans=1;
  rep(i,n){
    ans*=(i+1);
    ans%=MOD;
  }  
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math
import random
from decimal import Decimal
import itertools
import re
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(2147483647)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

def main():
	n = I()
	A = sorted(np.array(LI()))
	product = Decimal('1')
	for a in A:
		ad = Decimal(str(a))
		product *= ad
		if product > Decimal(str(10**18)):
			product = -1
			break
	print(int(product))




if __name__ == '__main__':
    main()

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

int main()
{
    int n, m;
    LL x;
    priority_queue<LL> pq;
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
    {
        cin >> x;
        pq.push(x);
    }
    for(int i = 0; i < m; ++i)
    {
        x = pq.top(); pq.pop();
        pq.push(x / 2);
    }
    LL ans = 0;
    for(int i = 0; i < n; ++i)
    {
        ans += pq.top(); pq.pop();
    }
    cout << ans << '\n';
}

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

int main(){
    int n; cin >> n;
    
    map<string, int> mp;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        mp[s] += 1;
    }
    int max_v = 0;
    for(const auto& x : mp){
        int v = x.second;
        if(v > max_v) max_v = v;
    }           
    for(auto it=mp.begin(); it!=mp.end(); it++){
        if(it->second == max_v){
            cout << it->first << endl;
        }
    }
}

Measured memory_bytes: 19260
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#define MAXN 100010
#define LL long long
using namespace std;

int n;
map<LL,int> S;
LL a[MAXN],b[MAXN];
int prime[MAXN],nump;
bool flag[MAXN];

pair<LL,LL> trans(LL x){
	LL tx=x;
	LL y1=1,y2=1;
	for(int _i=1;_i<=nump;_i++){
		LL i=prime[_i];
		if(tx%i==0){
			int cnt=0;
			while(tx%i==0) tx/=i,cnt++;
			cnt%=3;
			for(int j=0;j<cnt;j++) y1*=i;
			cnt=(3-cnt)%3;
			for(int j=0;j<cnt;j++) y2*=i;
		}
	}
	if(tx>1){
		LL temp=max((LL)(sqrt(tx)-2),1LL);
		for(LL i=0;i<4;i++)
			if((temp+i)*(temp+i)==tx){
				y1*=tx;
				y2*=temp+i;
				return make_pair(y1,y2);
			}
		y1*=tx;
		y2*=tx*tx;
	}
	return make_pair(y1,y2);
}

int main(){
#ifdef DEBUG
	freopen("D.in","r",stdin);
#endif
	for(int i=2;i<=2154;i++){
		if(!flag[i]) prime[++nump]=i;
		for(int j=1;j<=nump && i*prime[j]<=2154;j++){
			flag[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
		pair<LL,LL> temp=trans(a[i]);
		a[i]=temp.first;
		b[i]=temp.second;
		S[a[i]]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(S[a[i]]){
			if(a[i]==1){
				S[a[i]]=0;
				ans++;
				continue;
			}
			int t1=S[a[i]],t2=S[b[i]];
			S[b[i]]=S[a[i]]=0;
			ans+=max(t1,t2);
		}
	printf("%d\n",ans);
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
using namespace std;
long long n, x, a[2000], B[2000];
int main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++)cin >> a[i];
	long long minx = 1LL << 62;
	for (int i = 0; i < n; i++)B[i] = 1LL << 62;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < n; j++)B[j] = min(B[j], a[(j + n - i) % n]);
		long long score = 0; for (int j = 0; j < n; j++)score += B[j];
		minx = min(minx, score + i*x);
	}
	cout << minx << endl;
	return 0;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  string s[h];
  for (int i = 0; cin >> s[i]; ++i) {
  }
  int result = h * w;
  for (int i = 0; i < 1 << (h - 1); ++i) {
    bitset<10> bits(i);
    int current = 0, block[h], sum[h] = {};
    for (int j = 0; j < h; ++j) {
      block[j] = current;
      if (bits[j]) {
        ++current;
      }
    }
    for (int c = 0; c < w; ++c) {
      int count[h] = {};
      for (int r = 0; r < h; ++r) {
        count[block[r]] += s[r][c] - '0';
      }
      for (int r = 0; r < h; ++r) {
        if (count[r] + sum[r] > k) {
          ++current;
          fill(sum, sum + h, 0);
          break;
        }
      }
      for (int r = 0; r < h; ++r) {
        sum[r] += count[r];
        if (sum[r] > k) {
          current = h * w;
        }
      }
    }
    result = min(result, current);
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;
const double EPS = 10e-8;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };


int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10)cout << "error" << endl;
	else cout << a + b << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s     = input.ReadLine();

        var buil = new StringBuilder();
        for(int i=0; i<s.Length; i++) {
            buil.Append("x");
        }
        return buil.ToString();
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define rep(i,x) for(int i=0;i<x;i++)

using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   
   int n, m, k;
   
   string f[10];
	
	cin >> n >> m >> k;
	
	rep(i, n) 
	cin >> f[i];
	
	int ans = 0;
	
	rep(mask, (1<<n))
	rep(mask2, (1<<m))
	{
		string e[10];
		
		rep(j, 10)
		e[j] = f[j];
		
		rep(i, n)
		if(((mask>>i)&1))rep(j, m) e[i][j] = 'X';
		rep(j, m) if(((mask2>>j)&1)) rep(i, n) e[i][j] = 'X';
		int cnt = 0;
		rep(i, n) rep(j, m) cnt += e[i][j] == '#';
		if(cnt == k) ans++;
	}
	
	cout<<ans<<endl;
   
   return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

string s = "NSWE";
int a[4];
signed main(){
	string str;
	cin >> str;
	int n = str.size();
	rep(i,n){
		rep(j,4)if(str[i] == s[j])a[j]++;
	}
	int ans = 1;
	if(a[0] > 0 and a[1] == 0)ans = 0;
	if(a[0] == 0 and a[1] > 0)ans = 0;
	if(a[2] > 0 and a[3] == 0)ans = 0;
	if(a[2] == 0 and a[3] > 0)ans = 0;
	printf("%s\n", ans ? "Yes" : "No");
	return 0;
}







Measured memory_bytes: 256
N, X = map(int, input().split())

def calc(n, x):
  if x == 0: return 0
  if n == 0: return 1
  if x < 2**(n+1) - 1:
    return calc(n-1, x-1)
  else:
    return 2**n + calc(n-1, x-2**(n+1)+1)

print(calc(N, X))

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


int N;
int L[10];
int A,B,C;


int dfs(int k, int a, int b, int c) {
    if (k == N) {
        if (a == 0 || b == 0 || c == 0) return 1e9;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }
    int ans = 1e9;
    ans = min(ans, dfs(k + 1, a + L[k], b, c) + (a > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b + L[k], c) + (b > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c + L[k]) + (c > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c));
    return ans;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k[]  = new int[3];
		int count=0;
		int just=0;
		int low=0;
		int high=0;

		while(true){
			String[] line =sc.nextLine().split(" ");
			k[0]=Integer.parseInt(line[0]);
			k[1]=Integer.parseInt(line[1]);
			k[2]=Integer.parseInt(line[2]);
			while(!((k[0]<=k[1])&&(k[1]<=k[2]))){
				if(k[0]>k[1]){
					int store=k[0];
					k[0]=k[1];
					k[1]=store;
				}
				if(k[1]>k[2]){
					int store=k[1];
					k[1]=k[2];
					k[2]=store;
				}
			}
			if(k[2]>=k[0]+k[1]){
				break;
			}
			count=count+1;
			if(k[2]*k[2]==k[0]*k[0]+k[1]*k[1]){
				just=just+1;
			}
			if(k[2]*k[2]<k[0]*k[0]+k[1]*k[1]){
				low=low+1;
			}
			if(k[2]*k[2]>k[0]*k[0]+k[1]*k[1]){
				high=high+1;
			}
		}

		System.out.println(count+" "+just+" "+low+" "+high);
	}
}



Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == '1') cout << '9';
        else cout << '1';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3544
fun main() {
    var answer = "No"

    val XY = readLine()!!.split(" ").map { it.toInt() }
    val X = XY[0]
    val Y = XY[1]

    for (c in 0..X) {
        if (4*X - 2*c == Y) {
            answer = "Yes"
            break
        }
    }

    println(answer)
}

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

using namespace std;

typedef long long LL;

const int N = 110;

int n;
double a[N];
double res;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%lf", a + i);
    for(int i = 1; i <= n; i++) res += 1.0 / a[i];

    printf("%f\n", 1.0 / res);
    return 0;
}


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

int main(){
    int ans=0,sum=0;
    int n,rest=0;
    
    cin >>n;
    vector< pair <int,int> > arr(n);
    vector< pair <int,int> > ori(n);

    for (int i = 0; i < n; i++){
        int a;
        cin >>a;

        arr[i]=make_pair(a,i);
        ori[i]=make_pair(a,-1);
    }
    

    sort(arr.begin(),arr.end());

    for (int i = 0; i < n; i++){
        if(arr[i].second  != i){
            rest++;
        }
    }
    if(rest==0){
        cout << rest << endl;
        return 0;
    }

    for (int i = 0; i < n; i++){
        ori[arr[i].second].second=i;
    }
    


    int q;
    cin >>q;

    for (int i = 0; i < q; i++){
        int x,y;
        cin >>x>>y;
        x--;y--;

        if(ori[x].second==y)rest--;
        else if(ori[x].second == x)rest++;

        if(ori[y].second==x)rest--;
        else if(ori[y].second == y)rest++;

        swap(ori[x],ori[y]);

        if(rest==0){
            cout << i+1 << endl;
            return 0;
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << "-1" << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 7516
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

int main() {
    ll A,B,C;
    cin >> A >> B >> C;

    ll count = 0;
    while(A%2==0 && B%2==0 && C%2 == 0){
        ll tmpA = (B/2) + (C/2);
        ll tmpB = (A/2) + (C/2);
        ll tmpC = (A/2) + (B/2);
        
        A = tmpA;
        B = tmpB;
        C = tmpC;
        count++;

        if(A == B && B == C){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int m = cin.Int();
			int k = cin.Int();

			int max = (int)Math.Pow(2, m);

			if (k >= max) {
				Console.WriteLine(-1);
				return;
			}

			StringBuilder sb = new StringBuilder();
			if (k == 0) {
				for (int i = 0; i < max; i++) {
					sb.Append($"{i} ");
					sb.Append($"{i} ");
				}
			} else if (m == 1) {
				Console.WriteLine(-1);
				return;
			} else {
				for (int i = 0; i < max; i++) {
					if (i != k) {
						sb.Append($"{i} ");
					}
				}

				sb.Append($"{k} ");

				for (int i = max - 1; i >= 0; i--) {
					if (i != k) {
						sb.Append($"{i} ");
					}
				}

				sb.Append($"{k} ");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main(int argc, char *argv[])
{
    int A, B;
    cin >> A >> B;

    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll k, x;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> k >> x;
    FOR(i, x - k + 1, x + k)
    {
        if(i >= -1e6 && i <= 1e6) cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Cmondai {
    static void Main()
    {
        var nk = Console.ReadLine().Split(' ').Select(value => Int32.Parse(value)).ToArray();
        var N = nk[0];
        var K = nk[1];
        var count = N - K + 1;
        var x=Console.ReadLine().Split(' ').Select(value => Int64.Parse(value)).ToArray();
        var cost = new List<long>();
        for (int i=0;i<count;++i)
        {
            var l = Math.Abs(x[i]-x[i+K-1]);
            cost.Add(Math.Abs(x[i])+l);
            cost.Add(Math.Abs(x[i+K-1])+l);
        }
        var ans=cost.Min();
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 24160
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	for 2 <= len(s) {
		n := len(s) - 2
		s = s[:n]

		mid := n / 2
		// fmt.Println(n, s, mid, s[:mid], s[mid:])
		if s[:mid] == s[mid:] {
			fmt.Println(n)
			break
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>


int IsPrime(int n);
int main(void)
{
	int n;
	while(1)
	{
		scanf("%d", &n);
		if(n == 0)
			break;
		while(1)
		{
			if(IsPrime(n) && IsPrime(n-2))
			{
				printf("%d %d\n", n-2, n);
				break;
			}
			n--;
		}
	}
	return 0;
}


int IsPrime(int n)
{
	int i;
	if( (n!=2)&&(n<2 || n%2==0) )
		return 0;
	for(i=3; i*i<=n; i++)
		if(n%i == 0)return 0;
	return 1;
}

Measured memory_bytes: 600
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while(true){
			String[] a=br.readLine().split(" ");
			if(a[0].equals("0")&&a[1].equals("0")) break;
	        int x=Integer.parseInt(a[0]);
	        int y=Integer.parseInt(a[1]);
	        if(x>y){
	        	sb.append(y+" "+x+"\n");
	        }else{
	        	sb.append(x+" "+y+"\n");
	        }
		}
		System.out.print(sb);
	}
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<double>> dp(2, vector<double>(n + 1, 0));
  int crr = 0;
  int nxt = 1;
  dp[crr][0] = 1;
  for (int i = 1; i <= n; i++) {
    double p;
    cin >> p;
    dp[nxt][0] = 0;
    for (int j = 0; j < i; j++) {
      double crv = dp[crr][j];
      dp[nxt][j] += (1.0 - p) * crv;
      dp[nxt][j + 1] = p * crv;
    }
    swap(crr, nxt);
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n ; i++) {
    ans += dp[crr][i];
  }
  cout << setprecision(12) << ans << '\n';
  return 0;
}

Measured memory_bytes: 384
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int BN = 7;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;
  while (tn--) {
    int n, d;
    cin >> n >> d;

    int sum = 0;
    for (int i = 0, bi = 1; i < BN; i++, bi <<= 1) {
      int m = ((n & 1) == ((d >> i) & 1) ? n : n - 1);
      sum += m * bi;
    }
    printf("%d\n", sum);
  }
  return 0;
}


Measured memory_bytes: 256
s = int(input())
MOD = 1000000007

kotae = [0 for _ in range(2001)]

kotae[0] = 0
kotae[1] = 0
kotae[2] = 0
kotae[3] = 1
kotae[4] = 1
kotae[5] = 1
kotae[6] = 2

for i in range(7,2001):
    kotae[i] = kotae[i-1] + kotae[i-3]
    kotae[i] = kotae[i] % MOD

print(kotae[s])

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<bool> start(N+1);
  vector<bool> goal(N+1);

  for (int i = 0; i < M; i++) {
    int a;
    int b;
    cin >> a >> b;
    if (a == 1) {
      start[b] = true;
    }
    if (b == N) {
      goal[a] = true;
    }
  }

  string result = "IMPOSSIBLE";

  for (int i = 0; i < N+1; i++) {
    if (start[i] && goal[i]) {
      result = "POSSIBLE";
      break;
    }
  }

  cout << result << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define MOD 1000000007
#define PI 3.14159265358979

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

using namespace std;

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;

template < typename T >
bool chmin(T &x, const T &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T >
bool chmax(T &x, const T &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
int main() {
	ll K, N = 50;
	cin >> K;
	cout << 50 << endl;
	ll A = K % 50;
	ll B = A == 0 ? 50 : A;
	ll C = K == 0 ? -1 : (K - 1) / N;
	rep(i, B) {
		cout << N + (N - B) + C << " ";
	}
	rep(i, N - B) {
		cout << C - A + N - 1 << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import AtCoder._

object Main extends App
  {
    val a, b, c, d, e, k = Int.scan
    (e - a > k).cond(":(", "Yay!").println
  }

object AtCoder
  {
    val scanner = new java.util.Scanner(System.in)

    trait Read[A]
      {
        def read(string :String) :A
        def scan :A = this.read(scanner.next)
      }

    trait Write
      extends Any
      {
        def write :String
        def print :Unit = write.print
        def println :Unit = write.println
      }

    implicit class Bool(val value :scala.Boolean)
      extends AnyVal
      {
        def cond[A](t :A, f :A) :A = if(this.value) t else f
        def yes_no :String = this.cond("yes", "no")
        def Yes_No :String = this.cond("Yes", "No")
        def YES_NO :String = this.cond("YES", "NO")
      }

    object Int
      extends Object
      with Read[Int]
      {
        def read(string :String) :Int = string.value.toInt
      }

    implicit class Int(val value :scala.Long)
      extends AnyVal
      with Write
      {
        def write = this.value.toString
        def +(a :Int) :Int = this.value + a.value
        def -(a :Int) :Int = this.value - a.value
        def *(a :Int) :Int = this.value * a.value
        def /(a :Int) :Int = this.value / a.value
        def %(a :Int) :Int = this.value % a.value
        def <(a :Int) :Bool = this.value < a.value
        def >(a :Int) :Bool = this.value > a.value
        def <=(a :Int) :Bool = this.value <= a.value
        def >=(a :Int) :Bool = this.value >= a.value
        def ==(a :Int) :Bool = this.value == a.value
        def !=(a :Int) :Bool = this.value != a.value
      }

    implicit class Float(val value :scala.Double)
      extends AnyVal
      with Write
      {
        def write = this.value.toString
      }

    implicit class String(val value :java.lang.String)
      extends AnyVal
      with Write
      {
        def write = this
        override def print = System.out.print(value)
        override def println = System.out.println(value)
      }
  }


Measured memory_bytes: 25492
n = int(input())
a = []
b = []
d = []
c = 0
for i in range(n):
 ak = int(input())
 a.append(ak)
a.sort()
for i in range((len(a)-1)//2):
 d.append(a[-i-1]-a[i])
for i in range(n-1):
 bk = a[i+1] -  a[i]
 b.append(bk)
e = len(b)
c = sum(d) * 2
if e % 2 == 1:
 c += b[e//2]
else:
 c -= min(b[e//2-1],b[e//2])
print(c)


Measured memory_bytes: 13116
#include<iostream>
using namespace std;
int a,b;
int main(){
  cin >> a >> b;
  int res=0;
  for(int i=a;i<=b;i++){
    int n=i;
    int x[5];
    for(int j=0;j<5;j++){
      x[j]=n%10;
      n/=10;
    }
    if(x[0]==x[4]&&x[1]==x[3]) res++;
  }
  cout << res << "\n";
  return 0;
}


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

int main() {
    double r;
    cin >> r;
    r = 2*r*3.1415926535;
    cout << fixed << setprecision(20) << r << endl;
    return 0;
}

Measured memory_bytes: 3788
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        int i = 0;
        while (i < k && i < s.length()) {
            if (s.charAt(i) != '1') {
                System.out.println(s.charAt(i));
                System.exit(0);
            } else
                i++;
        }
        System.out.println(1);
    }
}


Measured memory_bytes: 23764
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]

ANS = []
for i in range(H+2):
  t = []
  for j in range(W+2):
    if i == 0 or j == 0 or i == H+1 or j == W+1:
      t.append("#")
    else:
      t.append(A[i-1][j-1])
  ANS.append("".join(t))
  
print("\n".join(ANS))


Measured memory_bytes: 8960
N,Y = map(int,input().split())
A,B,C = -1,-1,-1
flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N+1-i):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y and (N-i-j) >= 0:
            A,B,C = i,j,(N-i-j)
            flag = True
            break
print(A,B,C)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();
	
	int N, K; cin >> N >> K;
	if (K == 1) {
		cout << 0 << "\n";
	}
	else cout << N - K << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
queue<char>a,b,c;
int main(){
 string al , bo ,chr ;
 cin >> al ;
 cin >> bo ;
 cin >> chr ;
 for(int i=0;i<al.size();i++){
    a.push(al[i]);
 }
 for(int i=0;i<bo.size();i++){
    b.push(bo[i]);
 }
 for(int i=0;i<chr.size();i++){
    c.push(chr[i]);
 }
 char curr = a.front();
 a.pop();
 while(true){
     if(curr=='a'){
        if(a.empty()){
          cout << "A" <<endl;
          return 0;
        }
        curr = a.front();
        a.pop();
     }
     else if(curr=='b'){
        if(b.empty()){
          cout << "B" <<endl;
          return 0;
        }
        curr=b.front();
        b.pop();
     }
     else if(curr=='c'){
        if(c.empty()){
          cout << "C" <<endl;
          return 0;
        }
        curr=c.front();
        c.pop();
     }
 }

 return  0;
}


Measured memory_bytes: 3592
//#include <ext/pb_ds/assoc_container.hpp> 
     //#include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e18;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
   //  using namespace __gnu_pbds;
     //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
  

    int32_t main()
    {
        IOS
  
        
        int n,r;
        cin>>n>>r;
        if(n>=10)
        {
            cout<<r<<endl;
        }
        else
        {
            cout<<r+100*(10-n);
        }


    }       

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    int n;
    cin>>n;
    VI a(n+1);
    VL dp(n+1),sum(n+1);
    rep(i,1,n+1){
        cin>>a[i];
    }
    sum[1]=a[1];
    rep(i,2,n+1)sum[i]=a[i]+sum[i-2];
    rep(i,2,n+1){
        if(i&1)dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else dp[i]=max(a[i]+dp[i-2],sum[i-1]);
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 7172
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

flag = 0

if((b-a)>k or (c-a)>k or (d-a)>k or (e-a)>k or (c-b)>k or (d-b)>k or (e-b)>k or (d-c)>k or (e-c)>k or (e-d)>k):
  print(":(")
else:
  print("Yay!")
  

Measured memory_bytes: 3064
import math
N = int(input())
max = 0
max2 = 0
for i in range(2, int(math.sqrt(N)+ 2)):
    if N % i == 0:
        max = i
        max2 = N // i
if max != 0:
    print(max + max2 - 2)
else:
    print(N -1)
#print(max, max2)


Measured memory_bytes: 2940
import numpy as np

MOD = 998244353

N, S = map(int, input().split())
A = np.array(list(map(int, input().split())))

dp = np.zeros((N, S + 1))
dp[0, 0] = 2
if A[0] < S + 1:
	dp[0, A[0]] = 1

for i in range(1, N):
	dp[i, :] = (2 * dp[i - 1, :]) % MOD
	if A[i] > S:
		continue
	dp[i, A[i] : S + 1] += dp[i - 1, 0 : S - A[i] + 1]
	dp[i, :] %= MOD
print(int(dp[N - 1, S]))

Measured memory_bytes: 97240