akhauriyash/Code-Regression huggingface dataset:
def ncr(n, r):
  if n < r:
    return 0
  res = 1
  for i in range(1, n + 1):
    res *= i
  for i in range(1, r + 1):
    res //= i
  for i in range(1, n - r + 1):
    res //= i
  return res
n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
print(sum(v[0:a]) / a)
if v[0] == v[a - 1]:
  c = v.count(v[0])
  ans = 0
  for i in range(a, b + 1):
    ans += ncr(c, i)
  print(ans)
else:
  k = v.count(v[a - 1])
  r = v[0:a].count(v[a - 1])
  print(ncr(k, r))


Measured memory_bytes: 3064
import numpy as np
MOD = 10**9 + 7
N,M = map(int,input().split())
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)

# (n,m) 以前で作れている列
dp = np.zeros((N+1, M+1), dtype = np.int64)
dp[0] = 1

for n in range(1, N+1):
  same = (T == S[n-1])
  dp[n,1:][same] = dp[n-1,:-1][same] # ちょうど(n,m)で終わる
  dp[n] = (dp[n].cumsum() + dp[n-1]) % MOD # cumsumに直す

answer = dp[N,M]
print(answer)


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

int main() {
    int t, n, s, f;
    while (cin >> t, t) {
        cin >> n;
        int sum = 0;
        for (int i=0; i<n; ++i) {
            cin >> s >> f;
            sum += f - s;
        }
        if (sum < t) {
            cout << t - sum << endl;
        } else {
            cout << "OK" << endl;
        }
    }
    return 0;
}


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

int dfs(int i, vector<int>& dp, vector<vector<int>>& toid, vector<bool>& visited, vector<bool>& calculated)
{
	visited[i] = true;

	if (toid[i].empty()) {
		calculated[i] = true;
		dp[i] = 1;
		return dp[i];
	}

	for (auto& j : toid[i]) {
		if (calculated[j]) {
			dp[i] = max(dp[i], dp[j] + 1);
			continue;
		}
		if (visited[j]) {
			return -1;
		}

		int ans = dfs(j, dp, toid, visited, calculated);
		if (ans == -1) {
			return -1;
		}
		dp[i] = max(dp[i], ans + 1);
	}

	calculated[i] = true;
	return dp[i];
}

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> av(n, vector<int>(n-1));
	for (auto& i : av) {
		for (auto& j : i) {
			cin >> j;
			--j;
		}
	}

	vector<vector<int>> idTable(n, vector<int>(n));

	int v = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			idTable[i][j] = v++;
		}
	}

	vector<vector<int>> toid(v);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j) {
			av[i][j] = idTable[min(i, av[i][j])][max(i, av[i][j])];
		}
		for (int j = 0; j < n - 2; ++j) {
			toid[av[i][j+1]].push_back(av[i][j]);
		}
	}

	int ret = 0;
	vector<int> dp(v, -1);
	vector<bool> visited(v, false);
	vector<bool> calculated(v, false);
	for (int i = 0; i < v; ++i)
	{
		if (calculated[i]) {
			continue;
		}

		int ans = dfs(i,dp,toid, visited, calculated);
		if (ans == -1) {
			cout << -1;
			return 0;
		}
		ret = max(ret, ans);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 37632
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int GRAPH_SIZE= 50*50+100+20;
int pin[GRAPH_SIZE],dep[GRAPH_SIZE],s=0,t=GRAPH_SIZE-1;
struct EDGE{
	int u,v,c,cos;
};
vector<EDGE> e;
vector<int> each[GRAPH_SIZE];
int maxflow,mincost;
int flow[GRAPH_SIZE];
int dis[GRAPH_SIZE],inq[GRAPH_SIZE],las[GRAPH_SIZE];
bool spfa(){
	memset(inq,0,sizeof(inq));
	memset(dis,63,sizeof(dis));
	flow[s]=INF;
	dis[s]=0;
	queue<int> q;
	q.push(s);
	inq[s]=1;
	while(!q.empty()){
		int now=q.front();
		q.pop();
		inq[now]=0;
		for(auto it:each[now]){
			int to,f,c;
			to=e[it].v;
			f=e[it].c;
			c=e[it].cos;
			if(f<=0) continue;
			if(dis[to]>dis[now]+c){
				dis[to]=dis[now]+c;
				las[to]=it;
				flow[to]=min(flow[now],f);
				if(!inq[to]) q.push(to);
				inq[to]=1;		
			}
		}
	}
	return dis[t]!=INF;
}
void KM(){
	while(spfa()){
		maxflow+=flow[t];
		mincost+=dis[t]*flow[t];
		int now=t;
		while(now!=s){
			e[las[now]].c-=flow[t];
			e[las[now]^1].c+=flow[t];
			now=e[las[now]].u;
		}
	}
}
void make_edge(int U,int V,int C,int COS){
	EDGE tmp;
	tmp.u=U;
	tmp.v=V;
	tmp.c=C;
	tmp.cos=COS;
	e.PB(tmp);
	each[U].PB(e.size()-1);
	swap(tmp.u,tmp.v);
	tmp.c=0;
	tmp.cos=-COS;
	e.PB(tmp);
	each[V].PB(e.size()-1);
}
int n,m;
string maze[51];
int walk[2][2]={{1,0},{0,1}};
bool check(int x,int y){
	if(x<=0||y<=0||x>n||y>m) return 0;
	if(maze[x][y]=='#') return 0;
	return 1;
}
int main(){
	fastio;
	R2(n,m);
	rb(i,1,n) R(maze[i]);
	rb(i,1,n) maze[i]='^'+maze[i];
	rb(i,1,n)
		rb(j,1,m){
			int id=(i-1)*m+j;
			if(maze[i][j]=='o')
			make_edge(s,id,1,0);
			make_edge(id,t,1,0);
			rep(k,2)
			{
				int nx,ny;
				nx=i+walk[k][0];
				ny=j+walk[k][1];
				if(check(nx,ny)){
					make_edge(id,(nx-1)*m+ny,INF,-1);
				}
			}
		}
	KM();
	cout<<-mincost<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i) {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}


void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll s = accumulate(A.begin(), A.end(), 0LL);
    vector<ll> D = divisor(s);
    ll ans = 1;
    for (ll d : D) {
        vector<ll> m1, m2;
        rep(i, N) {
            ll a = A[i];
            m1.push_back(a % d);
        }
        sort(m1.begin(), m1.end());
        rep(i, N) {
            m2.push_back(d - m1[i]);
        }
        vector<ll> S1(N + 1, 0), S2(N + 1, 0);
        reverse(m2.begin(), m2.end());
        rep(i, N) {
            S1[i + 1] += S1[i] + m1[i];
            S2[i + 1] += S2[i] + m2[i];
        }
        rep2(i, 1, N + 1) {
            ll j = N - i;
            if (S1[i] - S2[j] == 0 && S1[i] <= K) {
                ans = max(ans, d);
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sa=[0]
sum=0
for i in range(n):
    sum+=a[i]
    sa.append(sum)
sb=[0]
sum=0
for i in range(m):
    sum+=b[i]
    sb.append(sum)

ans=0
j=m
for i in range(n+1):
    if k<sa[i]:
        break
    while sb[j]>k-sa[i]:
        j-=1
    ans=max(ans,i+j)

print(ans)


Measured memory_bytes: 47496
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
long long a, b, n, z;
int main(){
	cin >> a >> b >> n;
	if(n >= b){
		z = b - 1;
		cout << floor((z * a) / b) - (a * floor(z / b));
	}else{
		z = n;
		cout << floor((z * a) / b) - (a * floor(z / b));
	}
return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
// lld A[lim];

int main(){
    lld n = sc();
    int ans = 0;
    rep(i,1,n) {
        int k = scd();
        ans += (i % 2 == 1 and k % 2 == 1);
    }
    prdL(ans);
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    reverse(all(s));
    map<int, int> mp;
    mp[0]++;
    int p = 1;
    int now = 0;
    rep(i, 0, s.size()) {
        now = (now + (s[i] - '0') * p) % 2019;
        mp[now]++;
        p *= 10;
        p %= 2019;
    }
    ll ans = 0;
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<ll, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
const int MN = 1e3+5, MOD=1e9+7;
int lcm (int a, int b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
int N;
string S;
string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
unordered_map<char, int> dict;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N;
    cin >> S;
    string ans = "";
    for (int i = 0; i<26;i++) {
        dict[alpha[i]] = i;
    }
    for (int i = 0; i<S.length();i++) {
        ans += alpha[dict[S[i]]+N];
    }
    cout << ans << "\n";
}

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

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;

    int s[15]={};
    for(int i = 0; i < n; i++) cin >> s[i];
    
   
    int ans = 0;
    int c[15];
    while(1){
      bool issame = true;
      for(int i = 0; i < n; i++){
	int sum = 0;	
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j] ) sum++;
	}
	if(s[i] != sum ) issame = false;
	c[i] = sum;
      }
      if(issame){
	cout << ans << endl;
      	for(int j = 0; j < n; j++){
	  if(j == n-1) cout << s[j] << "\n";
	  else cout << s[j] << " ";
	}
	break;
      }
      for(int j = 0; j < n; j++){
	s[j] = c[j];
      }
      ans++;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;

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

const int INF = 1e9;

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];

  queue<pair<int,int>> que;
  vector<int> dist(H * W, INF);
  dist[0] = 0;
  que.push(make_pair(-1, 0));
  while(!que.empty()) {
    auto p = que.front(); que.pop();
    if(p.first != -1 && dist[p.second] != INF) continue;
    dist[p.second] = dist[p.first] + 1;
    REP(k, 4) {
      int yk = p.second / W + dy[k];
      int xk = p.second % W + dx[k];
      if(yk < 0 || yk >= H || xk < 0 || xk >= W) continue;
      if(s[yk][xk] == '#') continue;
      int next = yk * W + xk;
      if(dist[next] != INF) continue;
      que.push(make_pair(p.second, next));
    }
  }

  int ret = 0;
  if(dist[H * W - 1] == INF) {
    ret = -1;
  }else{
    REP(i, H)REP(j, W) if(s[i][j] == '.') ret += 1;
    ret -= dist[H * W - 1];
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 100000
#define MOD 1000000007

int main() {
	static char s[N + 1];
	static int dp[N + 1][13];
	int n, i, r, d;	

	scanf("%s", s);
	n = strlen(s);
	dp[0][0] = 1;
	for (i = 0; i < n; i++)
		for (r = 0; r < 13; r++)
			if (s[i] == '?')
				for (d = 0; d <= 9; d++)
					dp[i + 1][(r * 10 + d) % 13] = (dp[i + 1][(r * 10 + d) % 13] + dp[i][r]) % MOD;
			else
				dp[i + 1][(r * 10 + (s[i] - '0')) % 13] = (dp[i + 1][(r * 10 + (s[i] - '0')) % 13] + dp[i][r]) % MOD;
	printf("%d\n", dp[n][5]);
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    ull B = 1000000007;

    ull now;
    ull plus;
    ull x;
    set<ull> s;
    for (int l = N/2; l >= 1; l--) {
        s.clear();
        now = 0;
        plus = 0;
        x = 1;
        for (int i = 0; i < l; i++) {
            x = x * B;
        }
        for (int i = 0; i < l; i++) {
            plus = plus * B + (S[i] - 'a');
        }
        for (int i = l; i < 2*l; i++) {
            now = now * B + (S[i] - 'a');
        }
        s.insert(plus);
        if(s.count(now)){
            printf("%d\n", l);
            return 0;
        }

        for (int i = 1; i < N - 2*l + 1; i++) {
            plus = plus * B - (S[i-1] - 'a') * x + (S[i+l-1] - 'a');
            now = now * B - (S[i+l-1] - 'a') * x + (S[i+2*l-1] - 'a');
            s.insert(plus);
                if(s.count(now)){
                    printf("%d\n", l);
                    return 0;
                }    
        }
    }
    printf("0\n");

}

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


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int minimum = INF;
    minimum = min({abs(b-a)+abs(c-b),abs(c-a)+abs(b-c), abs(a-b)+abs(c-a)});
    cout << minimum << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
n,m=map(int,input().split())
if 2<=n and 2<=m:
    print((m-2)*(n-2))
elif m==1 and 2<=n:
    print(n-2)
elif n==1 and 2<=m:
    print(m-2)
elif n==1 and m==1:
    print(1)



Measured memory_bytes: 2940
from heapq import heappop, heappush
from collections import defaultdict

N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

# Step 1: Choose greedy
X.sort(key=lambda x: -x[1])
pq = []
chosen = defaultdict(int)
cnt = 0
score = 0
for t, d in X[:K]:
    heappush(pq, (d, t))
    cnt += 1 if chosen[t] == 0 else 0
    chosen[t] += 1
    score += d
ans = score + cnt ** 2

# Step 2: Replace chosen items
idx = K
while pq:
    # Step 2.1
    d_p, t_p = heappop(pq)
    if chosen[t_p] <= 1:
        continue
    chosen[t_p] -= 1
    score -= d_p

    # Step 2.2
    while idx < N and chosen[X[idx][0]] != 0:
        idx += 1

    if idx == N:
        break
        
    cnt += 1
    chosen[X[idx][0]] += 1
    score += X[idx][1]
    ans = max(ans, score + cnt ** 2)
    
print(ans)



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

const int N = 2e5+10;
int n, a[N];
long long ans;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a+n, greater<int>());
  int id = 0;
  for(int i = 0; i < n-1; ++i) {
    ans += a[id];
    if(i % 2 == 0) ++id;
  }
  cout << ans << endl;
  
  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << ((a * 100 + b * 10 + c) % 4 == 0 ? "YES" : "NO") << endl;
  }
  
  return 0;
}


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

using namespace std; 

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl; 
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1e9; 
const int Maxn = 1005; 
const int dx[] = {-1, 0, 1, 0}; 
const int dy[] = {0, 1, 0, -1}; 

struct pos { int first, second, third; }; 

int n, k;

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin); 
		freopen("output.txt", "w", stdout); 
	#endif
	
	scanf("%d%d", &n, &k); 
	if ((n + 1) / 2 >= k) puts("YES"); 
	else puts("NO"); 
	
	return 0; 
}

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

X=int(input())
if X<600:
    print(8)
elif X<800:
    print(7)   
elif X<1000:
    print(6)   
elif X<1200:
    print(5)   
elif X<1400:
    print(4)   
elif X<1600:
    print(3)   
elif X<1800:
    print(2)   
elif X<2000:
    print(1)       


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string ans;
	for (int i = n; i <= 999; ++i) {
		string T;
		T = to_string(i);
		int s = 0;
		rep(j, 2) {
			if (T[j] != T[j + 1]) s++;
		}
		if (s == 0) {
			ans = T;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int N,X,C=0;
    int min,minN=0;
    int A[] = new int[100];

    N = scanner.nextInt();

    for(int i=0;i<N;i++){
      A[i] = scanner.nextInt();
    }

    for(int i=0;i<N;i++){
      min = A[i];
      for(int j=i;j<N;j++){
        if(min>A[j]){
          min = A[j];
          minN = j;
        }
      }
      if(min!=A[i]){
        X = A[minN];
        A[minN] = A[i];
        A[i] = X;
        C++;
      }
    }

    for(int i=0;i<N;i++){
      System.out.print(A[i]);
      if(i!=N-1){
        System.out.print(" ");
      }
    }
    System.out.print("\n");
    System.out.println(C);

  }
}


Measured memory_bytes: 26252
#include<bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a,int b)
{
  if(a==0) return b;
  else return gcd(b%a,a);
}
int32_t main()
{
  int t,n,i,j,k,l,l1;
  cin>>i>>j;
  k=gcd(i,j);
  cout<<(i*j)/k;
}

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

const int MOD = 1e9+7;
int n, k;
long long mx, mn, f[100005], a[100005];

long long binexp(long long x, long long y) {
    long long res = 1;
    x %= MOD;
    while (y) {
        if (y&1) {
        	res = (res * x) % MOD;
        }
        y >>= 1;
        x = (x * x) % MOD;
    }
    return res;
}

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

    f[0] = 1;
    for (int i = 1; i <= 100000; i++) {
    	f[i] = (f[i-1] * i) % MOD;
    }

    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    }

    sort(a+1, a+1+n);
    for (int i = k; i <= n; i++) {
    	long long res = (f[i-1] * binexp(f[k-1], MOD - 2)) % MOD;
    	res = (res * binexp(f[(i-1) - (k-1)], MOD - 2)) % MOD;
    	res = (a[i] * res) % MOD;
    	mx = (mx + res) % MOD;
    }

    for (int i = 1; i <= n-k+1; i++) {
    	long long res = (f[n-i] * binexp(f[k-1], MOD - 2)) % MOD;
    	res = (res * binexp(f[(n-i) - (k-1)], MOD - 2)) % MOD;
    	res = (a[i] * res) % MOD;
    	mn = (mn + res) % MOD;
    }

    cout << (mx - mn + MOD) % MOD << '\n';
   	
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    ll n, k;
    cin >> n >> k;
    vll a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(all(a));
    sort(rall(f));

    ll ok = 1e12, ng = -1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        ll s = 0;
        rep(i, n) {
            s += max(a[i] - mid / f[i], 0ll);
        }
        if (s <= k) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }

    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define oo 1000000007
#define maxN 207
using namespace std;

int f[2][207][207];
int a[207][207];
int b[1007];

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

    if (n < 2) {
        puts("0");
        return 0;
    }

    long long ans = 1LL;
    for (int i = 1; i <= n; ++i) ans = (10LL*ans)%oo;

    long long res = 1LL;
    for (int i = 1; i <= n; ++i) res = (8LL*res)%oo;

    long long tmp = 2LL;
    for (int i = 1; i <= n; ++i) tmp = (9LL*tmp)%oo;

    cout << ((((ans+res-tmp)%oo+oo)%oo)+oo)%oo << endl;
    return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, head, tail;
	string S;
	bool ans = true;

	cin >> S;
	N = S.length();

	head = 0;
	tail = N - 1;
	while (head < tail) {
		if (S[head] != S[tail]) ans = false;
		head++;
		tail--;
	}

	head = 0;
	tail = (N - 1) / 2 - 1;
	while (head < tail) {
		if (S[head] != S[tail]) ans = false;
		head++;
		tail--;
	}

	head = (N + 3) / 2 - 1;
	tail = N - 1;
	while (head < tail) {
		if (S[head] != S[tail]) ans = false;
		head++;
		tail--;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
    ll p,q,r;
    cin>>p>>q>>r;
    ll ans=INT_MAX;
    ans=min(ans,q+r);
    ans=min(ans,p+q);
    ans=min(ans,p+r);
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s,ANS="1";
	ll k;
	cin>>s>>k;
	if(s.size()<k){
		for(ll i=0;i<s.size();i++){
			if(s[i]!='1'){
				ANS=s[i];
				break;
			}
		}
		cout<<ANS<<endl;
	}
	else{
		for(ll i=0;i<k;i++){
			if(s[i]!='1'){
				ANS=s[i];
				break;
			}
		}
		cout<<ANS<<endl;
	}
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N, K;
    scan(N, K);
    auto ans = f(N, K);
    writeln(ans);
}

int f(int N, int K) {
    return N > 0 ? f(N / K, K) + 1 : 0;
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=n; i>=1; i--)
    {
        if(sqrt(i)-(int)sqrt(i)==0)
            break;
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
//const int MAX_INT = (1 << 31) - 1;


int main() {

	string s;
	cin >> s;
	cout << "2018";
	for (int i = 4; i < s.length(); i++)
		cout << s[i];
	return 0;
}

Measured memory_bytes: 256
double d[3],e[3],s[99][3];main(T,n,i,j,k,l){for(scanf("%d",&T);T;T--){
for(scanf("%lf%lf%lf%d",d,d+1,d+2,&n),i=0;i<n;i++)scanf("%lf%lf%lf",s[i],s[i]+1,s[i]+2);
for(i=0;i<n;i++)for(j=0;j<n;j++)for(k=0;k<n;k++)if(i!=j&&j!=k&&k!=i){
	e[0]=sqrt(pow(s[j][0]-s[i][0],2)+pow(s[j][1]-s[i][1],2)+pow(s[j][2]-s[i][2],2));
	e[1]=sqrt(pow(s[k][0]-s[j][0],2)+pow(s[k][1]-s[j][1],2)+pow(s[k][2]-s[j][2],2));
	e[2]=sqrt(pow(s[i][0]-s[k][0],2)+pow(s[i][1]-s[k][1],2)+pow(s[i][2]-s[k][2],2));
	for(l=0;l<3;l++)if(d[l]/d[(l+1)%3]-e[l]/e[(l+1)%3]>0.001)break;
	if(l==3)printf("%d %d %d\n",k+1,i+1,j+1);
}
}exit(0);}

Measured memory_bytes: 644
#include <stdio.h>
#define N 101
#define white 0
#define gray 1
#define black 2
int n, spt = 0, time = 0;
int A[N][N] = {0}, nt[N] = {0}, color[N], stack[N], d[N], f[N];

void push(int u) {
  stack[++spt] = u;
}

void pop(void) {
  --spt;
}

int next(int u) {
  for (int v = nt[u]; v <= n; ++v) {
    nt[u] = v + 1;
    if (A[u][v]) return v;
  }
  return -1;
}

void dfs(int u) {
  int v;
  push(u);
  color[u] = gray;
  d[u] = ++time;

  while (spt > 0) {
    u = stack[spt];
    v = next(u);
    if (v != -1) {
      if (color[v] == white) {
        color[v] = gray;
        d[v] = ++time;
        push(v);
      }
    }
    else {
      pop();
      color[u] = black;
      f[u] = ++time;
    }
  }
}

void dfs_init(void) {
  for (int i = 1; i <= n; ++i) color[i] = white;
  for (int u = 1; u <= n; ++u) {
    if (color[u] == white) {
      dfs(u);
    }
  }
}

void print(void) {
  for (int u = 1; u <= n; ++u) {
    if (color[u] == black) {
      printf("%d %d %d", u, d[u], f[u]);
      putchar('\n');
    }
  }
}

int main(void) {
  int u, k, v;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; ++j) {
      scanf("%d", &v);
      A[u][v] = 1;
    }
  }
  dfs_init();
  print();
}



Measured memory_bytes: 1932
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    b=str(input())
    a.append(b)
freq = {}
for item in a:
        if (item in freq):
            freq[item] += 1
        else:
            freq[item] = 1

t=0
b=[]
for items in freq.values():
    if items>t:
        t=items

for key,val in freq.items():
    if val==t:
        b.append(key)
b.sort()
for i in range(len(b)):
    print(b[i])






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

int main(){
  string s;
  cin >> s;
  if((s[0] == s[1] && s[1] == s[2]) ||
    (s[1] == s[2] && s[2] == s[3])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

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

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

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

int main(){
	int h,w;
	cin>>h>>w;
	vii a(h+1,vi(w+1,0));
	vii b(h+1,vi(w+1,0));
	vii dp(w+1,vi(80*80+1,0));
	vii dp2(w+1,vi(80*81+1,0));
	FOR(i,0,h){
		FOR(j,0,w){
			cin>>a[i][j];
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			cin>>b[i][j];
			if(a[i][j]>b[i][j]){
				swap(a[i][j],b[i][j]);
			}
			a[i][j]=b[i][j]-a[i][j];
		}
	}
	dp[0][a[0][0]]=1;
	FOR(i,0,h){
		FOR(j,0,w){
			int l=(i+j+1)*80+1;
			FOR(k,0,l){
				int d=dp[j][k];
				if(d==0)continue;
				//cerr<<i<<" "<<j<<" "<<k<<endl;
				int k0=k+a[i][j+1];
				int k1=abs(k-a[i][j+1]);
				dp[j+1][k0]|=d;
				dp[j+1][k1]|=d;
				k0=k+a[i+1][j];
				k1=abs(k-a[i+1][j]);
				dp2[j][k0]|=d;
				dp2[j][k1]|=d;
			}
		}
		dp=dp2;
		dp2=vii(w+1,vi(80*(80+i+2)+1,0));
	}
	int ans=mod;
	FOR(i,0,12801){
		if(dp[w-1][i]){
			ans=min(ans,i);
		}
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 13180
X, Y = map(int, input().split()) 
if (4 * X - Y) % 2 == 1:
    print("No")
    exit()
 
if (-2 * X + Y) % 2 == 1:
    print("No")
    exit()
 
turu = (4 * X - Y) // 2
kame = (-2 * X + Y) // 2
if turu < 0 or kame < 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 61864
#include <stdio.h>

int main() {
        int r, c;

        scanf("%d %d", &r, &c);

        int row[r+1][c+1];

        for (int i = 0; i < r; i++) {
                for (int j = 0; j < c; j++) {
                        scanf("%d", &row[i][j]);
                }
        }

        // 初期化
        for (int i = 0; i < r; i++) {
                row[i][c] = 0;
        }

        for (int i = 0; i < c; i++) {
                row[r][i] = 0;
        }

        row[r][c] = 0;

        // 行の合計計算
        for (int i = 0; i < r; i++) {
                for (int j = 0; j < c; j++) {
                        row[i][c] += row[i][j];
                }
        }

        // 列の合計計算
        for (int i = 0; i < c; i++) {
                for (int j = 0; j < r; j++) {
                        row[r][i] += row[j][i];
                }
        }

        for (int j = 0; j < c; j++) {
                row[r][c] += row[r][j];
        }

        for (int i = 0; i < r+1; i++) {
                for (int j = 0; j < c+1; j++) {
                        printf("%d", row[i][j]);
                        if (j != c) printf(" ");
                }
                printf("\n");
        }

}


Measured memory_bytes: 2100
<?php
fscanf(STDIN, "%s", $a);

$a = preg_split('//', $a, -1, PREG_SPLIT_NO_EMPTY);

$i = 0;
$ss = 0;
foreach ($a as $s) {
    if ($s !== 'A' && $s !== 'T' && $s !== 'G' && $s !== 'C'){
        if ($ss < $i) $ss = $i;
        $i = 0;
    } else {
        $i++;
    }
}

echo ($ss < $i) ? $i : $ss;

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	int h,w;cin>>h>>w;
	vector<string> v(h);
	int g[1010][1010];
	Fill(g,INF);
	queue<pii> q;
	rep(i,h){
		cin>>v[i];
		rep(j,w){
			if(v[i][j]=='#'){
				g[i][j]=0;
				q.push(make_pair(i,j));
			}
		}
	}
	while(!q.empty()){
		pii now = q.front();q.pop();
		rep(i,4){
			int y = now.first+y_pos[i], x=now.second+x_pos[i];
			if(x <0|| w <= x || y < 0 || h <= y)continue;
			if(g[now.first][now.second]+1 < g[y][x]){
				g[y][x] = g[now.first][now.second] + 1;
				q.push(make_pair(y,x));
			}
		}
	}
	int ans = 0;
	rep(i,h)rep(j,w)ans = max(ans,g[i][j]);
	cout << ans << endl;
}

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

//#template
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); }
template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); }
//#endtemplate

//#define
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define clr(x) memset(x, 0, sizeof(x))
#define mmid ((lf + rg) >> 1)
#define lson root * 2, lf, mmid
#define rson root * 2 + 1, mmid + 1, rg
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <class T, class S> ostream &operator<<(ostream &o, const pair<T, S> &A) {
    o << "(" << A.fi << " " << A.se << ")";
    return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &A) {
    o << "[";
    for (auto &i : A) {
        o << " " << i;
    }
    o << " ]";
    return o;
}
//#enddefine

const int mod = int(1e9) + 7;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int dx[] = { -1, 0, 1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

const int N = 1e5 + 5;
int a[N];

void sol() {
    // Solve Function
    ll ans[3];
    while (cin >> ans[0] >> ans[1] >> ans[2]) {
        int k;
        cin >> k;
        sort(ans, ans + 3);
        for (int i = 0; i < k; ++i) {
            ans[2] *= 2;
        }
        cout << ans[0] + ans[1] + ans[2] << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(0);
#ifdef CFENGLV
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    clock_t _time = clock();
#endif
    int T;
    // cin >> T;
    // for (int cas = 1; cas <= T; ++cas) {
    // cout << "Case #" << cas << ": ";
    sol();
    // }
#ifdef CFENGLV
    cerr << "Time: " << static_cast<double>(clock() - _time) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define L 100

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
  int f[N2],space,MD;
};

Puzzle state;
int limit;
int path[L];

int get(Puzzle pz){
  int sum=0;
  int i;

  for(i=0;i<N2;i++){
    if(pz.f[i]==N2) continue;
    sum+=MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool is(){
  int i;
  for(i=0;i<N2;i++)
    if(state.f[i]!=i+1)
      return false;
  return true;
}

bool dfs(int depth,int prev){
  if(state.MD==0)
    return true;

  if(depth+state.MD>limit)
    return false;

  int sx=state.space/N;
  int sy=state.space%N;
  Puzzle tmp;

  int r;
  for(r=0;r<4;r++){
    int tx=sx+dx[r];
    int ty=sy+dy[r];

    if(tx<0||ty<0||tx>=N||ty>=N)
      continue;
    if(max(prev,r)-min(prev,r)==2)
      continue;
    tmp=state;

    state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty],state.f[sx*N+sy]);
    state.space=tx*N+ty;
    if(dfs(depth+1,r)){
      path[depth]=r;
      return true;
    }
    state=tmp;
  }
  return false;
}

string itera(Puzzle in){
  in.MD=get(in);
  for(limit=in.MD;limit<=L;limit++){
    state=in;
    if(dfs(0,-100)){
      string ans="";
      int i;

      for(i=0;i<limit;i++)
	ans+=dir[path[i]];
      return ans;
    }
  }
  return "unsolvable";
}

int main(){
  int i,j;

  for(i=0;i<N2;i++)
    for(j=0;j<N2;j++)
      MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
  Puzzle in;

  for(i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=itera(in);
  cout<<ans.size()<<endl;
  return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> s(n);
  rep(i,n){
    ll a, b;
    cin >> a >> b;
    s.pb(mp(a, b));
  }
  sort(all(s));
  ll total = 0;
  for (ll i = 0; m>0;i++){
    if(s[i].S<=m){
      total += s[i].F*s[i].S;
      m -= s[i].S;
    }
    else{
      total += s[i].F * m;
      m = 0;
    }
  }
  print(total);
}

Measured memory_bytes: 3968
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int t;
    int* r1;
    int* r2;
    cin >> t;
    r1 = new int[t];
    r2 = new int[t];
    for (int i = 0; i < t; i++)
    {
        cin >> r1[i];
        cin >> r2[i];
    }
    
    for (int i = 0; i < (t - 2); i++)
    {
        if(r1[i] == r2[i])
        {
            if(r1[i + 1] == r2[i + 1])
            {
                if(r1[i + 2] == r2[i + 2])
                {
                    cout << "Yes";
                    return 0;
                }
            }
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string, string> pii;

int n;
string s;
map<pii, ll> m;
ll ans = 0;

int main() {
	cin >> n;
	cin >> s;
	for (int i = 0; i < (1<<n); ++i) {
		string a, b;
		for (int j = 0; j < n; ++j) {
			if ((i&(1<<j)) == 0)
				a += s[j];
			else
				b += s[j];
		}
		m[pii(a, b)]++;
	}

	for (int i = 0; i < (1<<n); ++i) {
		string a, b;
		for (int j = 0; j < n; ++j) {
			if ((i&(1<<j)) == 0)
				a += s[2*n-1-j];
			else
				b += s[2*n-1-j];
		}
		ans += m[pii(b, a)];
	}
	cout << ans << endl;
}

Measured memory_bytes: 91904
#include <stdio.h>
int main(void){
  int a,b,c,x,y,p;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  c*=2;
  if(a+b<c)p=a*x+b*y;
  else{
    int ab=(x<y)?x:y;
    x-=ab; y-=ab;
    p=c*ab+((a<c)?a:c)*x+((b<c)?b:c)*y;
  }
  printf("%d",p);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>  
using namespace std;
int main(void){
    // Your code here!
    int N;
    vector<string> S;
    cin >> N;
    string s;
    
    for(int i = 0; i < N; i++){
        cin >> s;
        S.push_back(s);
        //cout << s << endl;
    }
    
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(),S.end()), S.end());

    cout << S.size()<<endl;
    
    
    
    
    
    
    
}


Measured memory_bytes: 11664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする gre<型>()
#define pri_queue priority_queue //優先度付きキュー
const int mod = 1000000007;
ll n,m;
map<ll,ll> a;
int main(){
  cin >> n >> m;
  for (size_t i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    a[temp]++;
  }
  for (size_t i = 0; i < m; i++) {
    ll temp1,temp2;
    cin >> temp1 >> temp2;
    a[temp2] += temp1;
  }
  ll ans=0,c=0;
  for (auto itr = a.end();;itr--) {
    if(itr == a.end())itr--;
    ans += min(n,itr->second)*itr->first;
    n -= itr->second;
    if(itr == a.begin())break;
    if(c >= n) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll n;cin >> n;
  vector<int> a(n);

  rep(i,n) cin >> a.at(i);
  ll sum = 0;
  rep(i,n + 1) {
    if(i == 0) sum += abs(a.at(i));
    else if(i == n) sum += abs(a.at(i-1));
    else sum += abs(a.at(i) - a.at(i-1));
  }

  //cout << sum << endl;

  ll current = 0;

  rep(i,n) {
    ll money = 0;
    if(i == 0) {
      ll dis01 = abs(a.at(0) - a.at(1));
      ll diss0 = abs(a.at(0));
      ll dis_p0 = abs(a.at(1));
      money = sum - dis01 - diss0 + dis_p0;
    }
    else if(i == n - 1) {
      ll disn_1n_2 =abs(a.at(n-1) - a.at(n-2));
      ll disn_1_e = abs(a.at(n - 1));
      ll disn_2_p = abs(a.at(n - 2));
      money = sum - disn_1n_2 - disn_1_e + disn_2_p;
    }
    else {
      ll dis_b = abs(a.at(i) - a.at(i - 1));
      ll dis_a = abs(a.at(i) - a.at(i + 1));
      ll dis_p = abs(a.at(i - 1) - a.at(i + 1));
      money = sum - dis_a - dis_b + dis_p;
    }
    cout << money << endl;
  }
}



Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int N;
	cin >> N;
	int res = 0;
	for (int i=1; i<=N; i++) {
		if (i%2==0) continue;
		int cnt = 0;
		for (int j=1; j<=i; j++){
			if (i%j==0) cnt++;
		}
		if (cnt==8) res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int n,cnt,hantei=0;
		cin>>n;
		if(n==0)
			break;
		for (int i=n+1;i<=2*n;i++){
			cnt=0;
			for(int j=2;j*j<=i;j++){
				if(i%j==0){
					cnt++;}
			}
			if(cnt==0)
				hantei++;
		}
		cout<<hantei<<endl;	
	}
		return 0;
}


Measured memory_bytes: 3016