akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    t=input()
    lt,ls=len(t),len(s)
    if lt>ls:
        print('UNRESTORABLE')
        return
    for i in range(ls-lt,-1,-1):
        sc=s[i:i+lt]
        flag=True
        for tt,ss in zip(t,sc):
            if ss!='?' and tt!=ss:
                flag=False
                break
        if flag:
            break
    if not flag:
        print('UNRESTORABLE')
        return 
    ans=""
    for k in range(ls):
        if i<=k<i+lt:
            ans+=t[k-i]
        elif s[k]=='?':
            ans+="a"
        else:
            ans+=s[k]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
n = int(input())
datn = list(map(int, input().split()))
m = int(input())
datm = list(map(int, input().split()))
import collections
d = collections.defaultdict(int)
for i in range(n):
    d[datn[i]] += 1
f = True
for j in range(m):
    c = d[datm[j]]
    if c == 0:
        f = False
    d[datm[j]] -= 1
print("YES" if f  else "NO")

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

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
int main()
{
	int a,b,n,k,ans = 0;
	bool z = true;
	cin >> n;
	vi t(n),x(n),y(n);
	rep(i,n){
		cin >> t[i];
		cin >> x[i];
		cin >> y[i];
	}
	rep(i,n){
		if(t[i] < (x[i]+y[i])){
			puts("No");
			return 0;
		}
		if(t[i]%2 == (x[i]+y[i])%2)
			continue;
		else
			z = false;
	}
	if(z)
		puts("Yes");
	else
		puts("No");
		

	return 0;
}

Measured memory_bytes: 1408
/*
  AtCoder Beginner Contest 083
  A - Libra
*/

#include<iostream>
using namespace std;

int A, B, C, D;

int main() {
  scanf("%d %d %d %d", &A, &B, &C, &D);
  if (A + B == C + D) printf("Balanced\n");
  else if (A + B > C + D) printf("Left\n");
  else printf("Right\n");
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> H(N);
	for (int i = 0; i < N; i++) cin >> H[i];
	H[0]--;

	bool flag = true;
	for (int i = 0; i < N - 1; i++) {
		if (H[i] > H[i + 1]) flag = false;
		else if (H[i] < H[i + 1]) H[i + 1]--;
	}

	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
  long long int n,k,ans;
  cin>>n>>k;
  if(n==0)ans=0;
  else if(n%k==0)ans=0;
  else { 
    long long int i=n/k;
    double d=n%k;
    ans=min(d,fabs(n-k*(i+1)));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<string, int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

#define MAX_V 1000

struct edge{
	long long int to, cap, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
bool used[MAX_V];

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size() - 1}); // 有向辺
	// G[to].push_back((edge){from, cap, G[from].size() - 1}); // 無向辺
}

// 増加パスを dfs で探す
long long int dfs(int v, int t, long long int f){
	if(v == t){
		return f;
	}
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			long long int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// s から t への最大流を求める
long long int max_flow(int s, int t){
	long long int flow = 0;
	while(true){
		fill(used, used + MAX_V, 0);
		long long int f = dfs(s, t, INF);
		if(f == 0){
			return flow;
		}
		flow += f;
	}
}

int main(){
	
	int N;
	cin >> N;
	
	int a[200], b[200], c[200], d[200];
	
	for(int i = 0; i < N; i++){
		add_edge(0, i + 1, 1);
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < N; i++){
		add_edge(N + i + 1, 2 * N + 1, 1);
		cin >> c[i] >> d[i];
	}
	
	for(int i = 0; i < N; i++)
	for(int j = 0; j < N; j++){
		if(a[i] < c[j] && b[i] < d[j]){
			add_edge(i + 1, N + j + 1, 1);
		}
	}
	
	cout << max_flow(0, 2 * N + 1) << endl;
	
	return 0;
}

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


using namespace std;



int main()
{
	int a, b;

	cin >> a >> b;

	int c = b - a;

	int hl = 0;
	for (int ni = 1; ni < c; ni++) {
		hl += ni;
	}

	printf("%d", hl - a);

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>  // This will work only for g++ compiler.
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forab(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define __builtin_popcount(x) ones(x)
#define __builtin_popcountl(x) onesl(x)
#define __builtin_popcountll(x) onesll(x)// to be used with algorithms that processes a container Eg: find(all(c
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define InputOuput freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
ll inf = 1e9 +5;
int main(){
   // InputOuput;
    Fast;
    int n ; cin >> n ;
    vvi points(n+1, vi(4,0));
    vvi dp(n+1, vi(4,0));
    for1(i,n)
        for1(j,3)
            cin >> points[i][j];

    for1(i,n){
        for1(j,3){
            for1(last,3 ){
                if(last == j) ;
                else dp[i][j] = max( dp[i][j] , points[i][j] + dp[i-1][last]);
            }
            dp[i][0] = max(dp[i][0], dp[i][j]);
        }
    }
    cout << dp[n][0] << '\n';
    return 0;

}

Measured memory_bytes: 14216
#include<bits/stdc++.h>
#define pb   push_back
#define m_p  make_pair
#define ll   long long
#define P    pair<ll,ll>
#define se   second
#define fi   first
#define itll map<ll,ll>::iterator
#define po   pop
#define p_b  pop_back
#define st   stack
#define vs   vector<string>
#define vl   vector<ll>
#define vvl  vector<vl>
#define vvs  vector<vs>
#define vp   vector<P>
#define cl   clear
#define fr   front
#define mpll map<ll,ll>
#define vo   void
using namespace std;
int main() 
{
	ll n,m,K;
	cin>>n>>m>>K;
	vs all(n);
	for(ll i=0;i<n;i++)
		cin>>all[i];
	ll mi = 1e9;
	for(int mask=0;mask<(1<<(n-1));mask++)
	{
		vl cuts;
		cuts.pb(0);
		ll cut=0;
		for(int i=0;i<n;i++)
			if((mask>>i)&1)
				cuts.pb(i+1),
				cut++;
		cuts.pb(n);
		ll sz = cuts.size()-1;
		vl cnt(sz,0);
		for(ll i=0;i<m;i++)
		{
			ll pos = 0;
			vl column_add(sz,0);
			for(ll j=0;j<n;j++)
			{
				if(j == cuts[pos+1])
					pos++;
				if(all[j][i] == '1')
					column_add[pos]++;
			} 
			for(ll j=0;j<sz;j++)
				cnt[j]+=column_add[j];
			bool isok = true;
			for(ll j=0;j<sz;j++)
				if(cnt[j]>K) 
				{
					isok = false;
					break;
				}
			if(isok)
				continue;
			isok = true;
			cut++;
			for(ll j=0;j<sz;j++)
				cnt[j] = column_add[j];
			for(ll j=0;j<sz;j++)
				if(cnt[j]>K)
				{
					isok = false;
					break;
				}
			if(!isok)
				cut = 1234567891011;
		}
		mi = min(cut,mi);
	}
	cout<<mi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>


static int A[100+1][100+1];

int main(int argc, char* argv[]) {
    int n, i, j, u, k; 

    memset(A, 0x00, sizeof(A));
    
    scanf("%d\n", &n);

    for ( i = 1; i <= n; i++ ) {
        scanf("%d", &u);
        scanf("%d", &k);

        for ( j = 1; j <= k; j++ ) {
            int v;
            scanf("%d", &v);

            A[u][v] = 1;
        }
        fgetc(stdin);           /* new line */
    }

    for ( i = 1; i <= n; i++ ) {
        for ( j = 1; j <= n; j++ ) {
            printf("%d", A[i][j]);
            if ( j + 1 <= n ) {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}
                  



Measured memory_bytes: 2044
#include<stdio.h>

/*Ã¦ÂÂ¹Ã©ÂÂÃ¢ÂÂ BMIÃ£ÂÂÃ£ÂÂÃ¯Â¼ÂÃ¯Â¼ÂÃ£ÂÂÃ¥Â¼ÂÃ£ÂÂÃ£ÂÂÃ¥ÂÂ¤Ã£ÂÂ§Ã¦Â¯ÂÃ¨Â¼ÂÃ£ÂÂÃ£ÂÂ*/

int main(){
  int i,h,w,n,j,no=100000000;
  double BMI,BMI2=1000,BMIH;

  while(1){
    scanf("%d",&n);
    if(n==0)break; /*whileÃ§ÂµÂÃ¤ÂºÂÃ¦ÂÂ¡Ã¤Â»Â¶*/

    for(j=0;j<n;j++){
      scanf("%d%d%d",&i,&h,&w);
      BMI=(double)w/((h/100.0)*(h/100.0));
      BMIH=(BMI-22);

      if(BMIH<0)
	{
	  BMIH=-BMIH;
	}

      if(BMIH<BMI2)
	{
	  BMI2=BMIH;
	  no=i;
	}
      else if(BMIH==BMI && i<no)
	{
	  no=i;
	}
      
    }/*E for*/

    printf("%d\n",no);
    no=100000000;
    BMI2=1000;
  } /*E while*/
  
    return 0;
}/*E main*/

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  string s;cin>>s;
  int a=0;
  for(int i=1;i<n;i++){
    if(s[i]=='E')a++;
  }
  int ans=a;
  for(int i=1;i<n;i++){
    if(s[i]=='E')a--;
    if(s[i-1]=='W')a++;
    ans=min(a,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 900
#include<stdio.h>

#define MAX 100005
#define NIL -1

typedef struct{
  int p,l,r;
}Node;

Node T[MAX];
int n,D[MAX];

void print(int);
int rec(int,int);

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j == 0)T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }

  for(i=0;i<n;i++)
    if(T[i].p == NIL)r = i;

  rec(r,0);
  for(i=0;i<n;i++)
    print(i);

  return 0;
}

void print(int u){
  int i,c;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);

  if(T[u].p == NIL)printf("root, [");
  else if(T[u].l == NIL)printf("leaf, [");
  else printf("internal node, [");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){

  D[u] = p;
  if(T[u].r != NIL)rec(T[u].r,p);
  if(T[u].l != NIL)rec(T[u].l,p+1);
}

Measured memory_bytes: 5296
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a[] = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		int ans = 0, count = 0;
		sc.close();
		Arrays.sort(a);
		int tmp = a[0];
		for (int i = 0; i < n; ++i) {
			if (tmp == a[i])
				++count;
			else {
				if (tmp < count)
					ans += (count - tmp);
				else if (tmp > count)
					ans += count;
				tmp = a[i];
				count = 1;
			}
			if (i == n - 1) {
				if (tmp != count) {
					if (tmp > count)
						ans += count;
					else ans += (count - tmp);
				}
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 51812
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <cstring>

using namespace std;

#define watch(x) cout << #x << " = " << x << endl

const long long INF = 1e18;
const int N = 101, V = 1e3 + 1;
int n, x, w[N], v[N];
int64_t dp[V * N];

int main(int argc, char** argv)
{
#ifdef LOCAL
  freopen(strcat(argv[0], ".in"), "ab+", stdin);
#endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> w[i] >> v[i];

  fill(dp, dp + N * V, INF);

  dp[0] = 0;
  for (int k = 0; k < n; k++) {
    for (int s = V * N - 1; s >= 0; s--) {
      if (dp[s] != INF) {
        dp[s + v[k]] = min(dp[s + v[k]], dp[s] + w[k]);
        //watch(w[k]);
      }
    }
  }

  int64_t val = INF, ans = -1;
  for (int i = 1; i < N * V; i++) 
    if (i > ans && dp[i] <= x) ans = i;
  cout << ans;
  
  return 0;
}


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

ll solve(vector<vector<ll>>& dp, vector<ll>& a, int head, int tail){
	if(head >= tail){
		return dp[head][tail] = a[head];
	}
	if(dp[head][tail] != 0) return dp[head][tail];

	ll best = max(
		-solve(dp,a,head,tail-1) + a[tail],
		-solve(dp,a,head+1,tail) + a[head]
		);

	return dp[head][tail] = best;
}

int main(){
	int N;
	cin >> N;
	vector<ll> a(N);
	for(int i=0; i<N; i++) {
		cin >> a[i];
	}

	vector<vector<ll>> dp(N,vector<ll>(N));
	cout << solve(dp,a,0,a.size()-1) << endl;

	return 0;


}



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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = (h2 * 60 + m2) - k - (h1 * 60 + m1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 5050;
int p[N],c[N];
int val[N];
int32_t main(){
  fastio;
  int n,k;
  cin >> n >> k;
  for(int i=1;i<=n;i++){
    cin >> p[i];
  }
  for(int i=1;i<=n;i++){
    cin >> c[i];
  }
  ll best=-1e18;
  for(int st=1;st<=n;st++){
    // start here:
    ll cic=0;
    int cur = p[st];
    int t = 0;
    while(cur!=st){
      cic+=c[cur];
      val[++t] = cic;
      cur = p[cur];
    }
    cic+=c[cur];
    val[++t] = cic;
    best = max(best,val[1]);
    for(int i=1;i<=t;i++){
      ll falta = max(0LL,(1ll * ((k - i)/t) * val[t]));
   //   cout << i<<" "<<st<<" "<<val[i]<<" "<<cic<<" "<<(k-i)/x << endl;
      ll res = val[i] + falta;
      if(i > k)break;
      best = max(best,res);
    }

  }
  cout << best << endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3752
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define re register
#define FOR(i,a,b) for(re int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(re int i=(a);i>=(b);i--)
#define temT template<typename T>
using namespace std;
typedef long long ll;
const int N=int(2e5)+10;

int a[N],n;	ll res;
int b[N],c[N],L[N],R[N];

inline int gvl(int x){return a[c[L[x]]];}
inline int gvr(int x){return a[c[R[x]]];}
inline void del(int x){
	R[L[x]]=R[x];	L[R[x]]=L[x];
}

int main(){
	cin>>n;	FOR(i,1,n)	cin>>a[i];
	sort(a+1,a+n+1);
	int pi=1,pj=n;
	FOR(i,1,n){
		if(i&1)
			b[pj]=i,c[i]=pj,pj--;
		else
			b[pi]=i,c[i]=pi,pi++;
	}
	FOR(i,1,n){
		L[i]=(i==1)?n:i-1;
		R[i]=(i==n)?1:i+1;
	}
	FOR(i,1,n-1)
		res+=min(gvl(b[i]),gvr(b[i])),del(b[i]);
	cout<<res;
	return 0;
}

Measured memory_bytes: 7480
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << max(a*b,max(a+b,a-b));
	return 0;
}

Measured memory_bytes: 256
N, M, *AB = map(int, open(0).read().split())
L = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

L.sort(key=lambda t: t[1])

ans = end = 0
for a, b in L:
    if a >= end:
        end = b
        ans += 1

print(ans)


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

using namespace std;

int calc(int x) {
  if (x % 100 != 0) return 0;
  return calc(x / 100) + 1;
}

int main() {
  int d, n;
  cin >> d >> n;
  int cnt = 0;
  for (int i = 1;; i++) {
    if (calc(i) == d) {
      cnt++;
      if (cnt == n) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    string s;
    string p="peach",a="apple";
    getline(cin,s);
    rep(i,0,s.length()-4){
        if(s.substr(i,5)=="peach"){
            rep(j,0,5)s[i+j]=a[j];   
        }else if(s.substr(i,5)=="apple"){
            rep(j,0,5) s[j+i]=p[j];
        }
    }
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3208
def main():
    #infile = open("compprog.txt", mode="r")
    n, m = [int(x) for x in input().split()]
    students = []
    cpoints = []
    for _ in range(n):
        students.append([int(x) for x in input().split()])
    for _ in range(m):
        cpoints.append([int(x) for x in input().split()])
    for student in students:
        res = 1
        closest_dis = man_dis(student[0], cpoints[0][0], student[1], cpoints[0][1])
        for c_idx in range(1, m):
            this_dis = man_dis(student[0], cpoints[c_idx][0], student[1], cpoints[c_idx][1])
            if this_dis < closest_dis:
                closest_dis = this_dis
                res = c_idx + 1
        print(res)
    #infile.close()


def man_dis(x1, x2, y1, y2):
    return abs(x1 - x2) + abs(y1 - y2)


if __name__ == "__main__":
    main()


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

int main() {
    int n;
    long long int ans = 3;
    cin >> n;
    int a[n], rgb[3] = {0};
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
  	if(a[0] != 0) {
    	cout << 0 << '\n';
      	return 0;
    }
    rgb[0] = 1;
    for(int i = 1; i < n; ++i) {
        int sum = 0;
        for(int j = 0; j < 3; ++j) {
            if(rgb[j] == a[i]) sum++;
        }
        ans *= sum;
        ans %= MOD;
        for(int j = 0; j < 3; ++j) {
            if(rgb[j] == a[i]) {
                rgb[j]++;
                break;
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int X;
  cin >> X;
  int dayOfWeek = X % 7;

  if (dayOfWeek == 0) cout << "thu" << endl;
  if (dayOfWeek == 1) cout << "fri" << endl;
  if (dayOfWeek == 2) cout << "sat" << endl;
  if (dayOfWeek == 3) cout << "sun" << endl;
  if (dayOfWeek == 4) cout << "mon" << endl;
  if (dayOfWeek == 5) cout << "tue" << endl;
  if (dayOfWeek == 6) cout << "wed" << endl;
  
}



Measured memory_bytes: 3144
A, B, C, D, E, F = map(int, input().split())

best_dense = -float("inf")
for a in range(31):
    for b in range(31):
        for c in range(1501):
            for d in range(1501):
                w_sum = 100 * A * a + 100 * B * b
                s_sum = C * c + D * d
                sum = w_sum + s_sum
                if sum > F: break
                if w_sum == 0: break
                if E * (w_sum / 100) < s_sum: break
                dense = s_sum / sum
                if dense > best_dense:
                    best_dense = dense
                    ans_sum = sum
                    ans_s_sum = s_sum
print(ans_sum, ans_s_sum)


Measured memory_bytes: 68444
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x7fffffff
#define INFL 0x7fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	str;

	cin >> n >> m;
	for(i=0;i<m; i++) {
		cin >> a;
		ans += a;
	}

	ans = n - ans;
	if (ans<0) ans = -1;
	cout << ans << endl;

}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
//***** Jai Gurudev *****//
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define all(x) x.begin(),x.end()
#define vii vector<pair<int,int> >
#define vll vector<pair<ll,ll> >
#define pb push_back
#define fi first
#define se second
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI 3.1415926535897932384626433832795
#define inf 1e18+5
#define mod 1000000007
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;}
bool isprime(ll n) {bool flag=true;for(ll i=2; i<=sqrt(n);i++){if(n%i==0){flag=false;break;}}return flag;}
using namespace std;
vl seive(){ll n=2;vl pr(200000,-1);for(int i=n;i<200000;i++){if(pr[i]==-1)pr[i]=1;else continue;for(int j=2*i;j<200000;j+=i)pr[j]=0;}return pr;}
int main()
{
	fast
	int p,q,x;
	cin>>p>>q>>x;
	vi a(p),b(q);
	for(int i=0;i<p;i++)
	cin>>a[i];
	for(int i=0;i<q;i++)
	cin>>b[i];
	int c=p+q;
     int sum=0,i=0,count,j=0;
     while(i<a.size()&&sum+a[i]<=x)
     {
        sum+=a[i];
        i++;
     }
     count=i;
     while(j<b.size()&&i>=0)
     {
         sum+=b[j];
         j++;
         while(sum>x)
         {
             i--;
             sum-=a[i];
         }
         if(sum<=x&&i+j>count)
         count=i+j;
     }
     cout<<count<<"\n";
	return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define ll long long int
#define fori(a,b) for(i=a;i<b;i++)
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll n,i;
  cin>>n;
  unordered_map<string,ll>m;
  fori(0,n)
  {
  	string s;
  	cin>>s;
  	m[s]=1;
  }
  ll count=0;
  for(auto x:m)
  {
  	if(x.second==1)
  	count++;
  }
  cout<<count<<endl;
return 0;
}


Measured memory_bytes: 17724
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define LL long long
using namespace std;
int n,m,fa[maxn],use[maxn],cnt;
LL ans;
struct node { int w;bool vis; } a[maxn];
bool cmp(node p,node q) 
{
	if(p.vis) return false;
	if(q.vis) return true;
	return p.w<q.w; 
}
int find(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].w);
		fa[i]=i;use[i]=i;
		a[i].vis=true;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		u++,v++;
		int r1=find(u),r2=find(v);
		if(r1!=r2)
		{
			if(a[use[r2]].w<a[use[r1]].w)
			{
				a[use[r1]].vis=false;
				use[r1]=use[r2];
			}
			else a[use[r2]].vis=false;
			fa[r2]=r1;
		}
	}
	for(int i=1;i<=n;i++)
		if(find(i)==i) 
		{
			ans+=1ll*a[use[i]].w;
			cnt++;
		}
	if(cnt==1)
	{
		printf("0\n");
		return 0;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=cnt-2;i++)
		if(a[i].vis)
		{
			printf("Impossible\n");
			return 0;
		}
		else ans+=1ll*a[i].w;
	printf("%lld\n",ans);
}

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

using namespace std;

int main(void)
{
    unsigned long int A;
    double B;
    cin >> A >> B;

    int C = 100 * B + 0.5;
    if(A == 0 || C == 0){
        cout << 0 << endl;
    }
    else{
    cout <<  A * C / 100 << endl;
    }
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
typedef long double ld;

int T, N, A, B, C, X, Y, Z;
string S;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> X >> Y >> Z;
	cout << Z << ' ' << X << ' ' << Y << '\n';
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define Spa putchar(32)
const int maxn=111111;
int N,M;
struct hhh
{
	int aa,bb;
}h[maxn];
bool cmp(const hhh &x,const hhh &y)
{
	return x.aa<y.aa;
}
int read()
{
	int s=0,c=getchar(),f=1;
	while(c<48||c>57)
	{
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*f;
} 
void write(LL x)
{
	if(x>=10) write(x/10);
	putchar(x%10+48);
}
void W(int x)
{
	if(x<0) x=-x,putchar(45);
	write(x);
}
int main()
{
	N=read(),M=read();
	for(int i=1;i<=N;++i)
	{
		h[i].aa=read(),h[i].bb=read();
	}
	sort(h+1,h+1+N,cmp);
	LL ans=0;
	int uuu;
	for(int i=1;i<=N;++i)
	{
		if(M>h[i].bb) M-=h[i].bb,ans+=((LL)h[i].aa*h[i].bb);
		else
		{
			uuu=i;
			break;
		}
	}
	ans+=((LL)M*h[uuu].aa);
	write(ans);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int solve(int,int,int);

int A[20];
 
int main(){
  int i,n,m,q,sta;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    sta=solve(0,m,n);
    if(sta==1)printf("yes\n");
    else if(sta==0)printf("no\n");
  }
  return 0;
}

int solve(int i,int m,int n){
  int res;
  if(m==0)return 1;
  if(i>=n)return 0;
  res=solve(i+1,m,n)||solve(i+1,m-A[i],n);
  return res;
}

Measured memory_bytes: 580
#include<stdio.h>
int graph[101][101],n,c,d;

void warshall_floyd(){
  int i,j;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
}

int min(int x,int y){
  return x<y?x:y;
}

int main(){
  int k,i,j,x,e,a,b;

  while(scanf("%d %d",&n,&k),n,k){

    for(i=0;i<=n;i++)
      for(j=0;j<=n;j++)
	graph[i][j]=i==j?0:1000000;

    for(i=0;i<k;i++){
      if(scanf("%d",&x),x){
	scanf("%d %d %d",&c,&d,&e);

	if(graph[c][d]>e){
	graph[c][d]=graph[d][c]=e;
	warshall_floyd();
	}
      }else{
	scanf("%d %d",&a,&b);
	printf(graph[a][b]>=1000000?"-1\n":"%d\n",graph[a][b]);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	s, t := sc.nextStr(), sc.nextStr()
	fmt.Printf("%s%s\n", t, s)
}

type scanner struct {
	sc *bufio.Scanner
}

var sc *scanner

func init() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	sc = &scanner{sc: s}
}

func (s *scanner) nextInts(ints ...*int) {
	for i := range ints {
		s.sc.Scan()
		*ints[i], _ = strconv.Atoi(s.sc.Text())
	}
}

func (s *scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

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

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

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


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

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;

    int a[Q], b[Q], c[Q], d[Q];
    int ai, bi, ci, di;
    rep(i, Q) {
        cin >> ai >> bi >> ci >> di;
        ai--, bi--;
        a[i] = ai, b[i] = bi, c[i] = ci, d[i] = di;
    }

    int ans = 0;
    int A[10];
    for (int a0=1; a0<=M; a0++)  { A[0] = a0;
    for (int a1=a0; a1<=M; a1++) { A[1] = a1;       
    for (int a2=a1; a2<=M; a2++) { A[2] = a2;       
    for (int a3=a2; a3<=M; a3++) { A[3] = a3;       
    for (int a4=a3; a4<=M; a4++) { A[4] = a4;        
    for (int a5=a4; a5<=M; a5++) { A[5] = a5;       
    for (int a6=a5; a6<=M; a6++) { A[6] = a6;       
    for (int a7=a6; a7<=M; a7++) { A[7] = a7;       
    for (int a8=a7; a8<=M; a8++) { A[8] = a8;       
    for (int a9=a8; a9<=M; a9++) { A[9] = a9;    
        int score = 0;
        rep(i, Q) if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
        ans = max(ans, score);
    }}}}}}}}}}

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm> 
#include<functional> 
#include<cassert>
#include<numeric> // std::accumulate(vec.begin(),vec.end(),0) sum of element
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>


using namespace std;


typedef long long ll;
typedef std::pair<int, int> P;
typedef vector<int> vi;


#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(c) c.begin(),c.end()
#define show(x) cout << #x << " = " << x << endl

#define fi first
#define se second
#define pb push_back



#define DEBUG


// void print_vector(const std::vector<int> &t);
// void unique_vector(std:: vector<int> &t);

template <class X>
void print_vector(const std::vector<X> &t);
template <class X>
void unique_vector(std:: vector<X> &t);


int w, h;

vector<int> xl={-1, 0, 1, 0};
vector<int> yl={0, 1, 0, -1};

int main(){

  vi ans;
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<vector<char>> f(h, vector<char>(w));
    queue<P> ser;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++) {
	cin >> f[i][j];
	if(f[i][j] == '@')
	  ser.push(make_pair(i, j));
      }
    }
    int c = 0;
    while(!ser.empty()){
      P t = ser.front();
      ser.pop();
      int y = t.fi, x = t.se;
      // show(x); show(y);
      if(f[y][x] == '@') f[y][x] = '#';
      for(int i = 0; i < 4; i++) {
	int dx = x+xl[i], dy=y+yl[i];
	// cout << dx << ' ' << dy << endl;
	// show(dx); show(dy);
	if(dy < 0 || dy >= h || dx < 0 || dx >= w || f[dy][dx] == '#')
	  continue;
	
	if(f[dy][dx] == '.'){
	  c++;
	  ser.push(make_pair(dy, dx));
	  f[dy][dx] = '#';
	}
      }	
      // for(int i = 0; i < h; i++) {
      // 	for(int j = 0; j < w; j++) {
      // 	  cout << f[i][j] << ' ';
      // 	}
      // 	cout << endl;
      // }
      // cout << endl;
    }
    ans.pb(c+1);
  }
  for(auto &i : ans) cout << i << endl;
}

template <class X>
void unique_vector(std::vector<X> &t)
{
  std::sort(t.begin(), t.end());
  t.erase( std::unique(t.begin(), t.end()), t.end() );
}

template <class X>
void print_vector(const std::vector<X> &t){
  for(auto itr=t.begin(); itr != t.end(); itr++){
    std::cout << *itr;
    if(itr != t.end()-1) std::cout << ' ';
  }
  std::cout << std::endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <numeric>
#include <iterator>
#include <stdio.h>
#define ll long long
#define ull unsigned long long int
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fr(i,p,n) for(int i=p;i<n;i++)
#define precise cout << std::setprecision(10) << std::fixed;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
//ll M=1000000007;
//ll M=  998244353;
typedef pair<int, int> pairs;
string x,y;
int dp[3001][3001];
int lcs(int n,int m){
    //string a="";

    if(n==0||m==0) { dp[n][m]=0; return 0; }
    if(x[n-1]==y[m-1]) {
    if(dp[n-1][m-1]==-1) dp[n-1][m-1]=lcs(n-1,m-1);
    dp[n][m]=1+dp[n-1][m-1];
    return dp[n][m]; }
    else {
        if(dp[n-1][m]==-1) dp[n-1][m]=lcs(n-1,m);
        if(dp[n][m-1]==-1) dp[n][m-1]=lcs(n,m-1);
        dp[n][m]=max(dp[n-1][m],dp[n][m-1]);
       return dp[n][m];
    }
}
int main()
{
    fastio; precise;
    int T=1;
    //cin>>T;
    while(T--){
        string ans="";
        int a;
        cin>>x>>y;
        int n=x.length(),m=y.length();
        fr(i,0,n+1) fr(j,0,m+1) dp[i][j]=-1;
        a=lcs(x.length(),y.length());
        while(sz(ans)<a){
            if(x[n-1]==y[m-1]) { ans+=x[n-1]; n--; m--; }
            else if(dp[n-1][m]>dp[n][m-1]) n--;
            else m--;
        }
        reverse(all(ans));
        cout<<ans<<endl;


    }
     return 0;
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    for(int i = x; i <= y; i *= 2){
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n, k;
int a[N];

int main() {

	FAST;

	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		if (a[i] >= k) ans ++;
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
  long long N, M, S = 0, H = 0;
  cin >> N >> M;
  vector<int> vec1(N);
  for(int i = 0; i < N; i++){
    cin >> vec1[i];
  }
   priority_queue<int> pq;
   for(int i = 0; i < N; i++){
     pq.push(vec1[i]);
   }
  for(int i = 0; i < M; i++){
    S = pq.top() / 2;
    pq.pop();
    pq.push(S);
  }
  for(int i = 0; i < N; i++){
    H += pq.top();
    pq.pop();
  }
  cout << H <<endl;
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 1003;

int c[MAX_N*4][MAX_N*4];

int main(){
  int N,K; cin >> N >> K;
  fill(c[0],c[MAX_N*3-1],0);
  rep(i,N){
    int x,y; char cc;
    cin >> x >> y >> cc;
    if(cc=='B') x += K;
    x %= (2*K); y %= (2*K);
    c[x][y] += 1;
    c[x][y+K] -= 1;
    c[x+K][y] -= 1;
    c[x+K][y+K] += 1;
    c[x+K][y+K] += 1;
    c[x+K][y+K*2] -= 1;
    c[x+K*2][y+K] -= 1;
    c[x+K*2][y+K*2] += 1;
  }
  rep(xs,K*4) REP(ys,1,K*4){
    c[xs][ys] += c[xs][ys-1];
  }
  REP(xs,1,K*4) rep(ys,K*4){
    c[xs][ys] += c[xs-1][ys];
  }
  // rep(xs,K*4){
  //   rep(ys,K*4) cout << c[xs][ys];
  //   cout << "" << endl;
  // }
  rep(xs,K*2) REP(ys,K*2,K*4) c[xs][ys%(K*2)] += c[xs][ys];
  REP(xs,K*2,K*4) rep(ys,K*4) c[xs%(K*2)][ys%(K*2)] += c[xs][ys];
  int ans = -INF;
  rep(xs,K*2){
    rep(ys,K*2) ans = max(ans,c[xs][ys]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 62976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		String[] S=sc.next().split("");
		long ans=0;

		for(int i=0;i<Math.pow(2,S.length-1);i++) {

			StringBuilder sb=new StringBuilder();

			for(int j=0;j<S.length;j++) {

				sb.append(S[j]);

				if((1&i>>j)==1) {

					ans+=Long.parseLong(sb.toString());
					sb.setLength(0);
				}
			}
			if(sb.length()!=0) {
				ans+=Long.parseLong(sb.toString());
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 23380
import java.util.*;

public class Main {
	
       public static void main(String[] args) {
    	  Scanner in=new Scanner( System.in)	;
          long n=in.nextLong(),m=in.nextLong(),k=in.nextLong();
          HashMap<pointt,Long> map=new HashMap<pointt,Long>();
          for(int i=1;i<=k;i++)
          {
        	 int a=in.nextInt();
        	 int b=in.nextInt();
        	 for(int x=Math.max(1, a-2);x<=Math.min(n-2, a);x++)
        		 for(int y=Math.max(1, b-2);y<=Math.min(m-2, b);y++)
        		 {
        			 pointt p=new pointt(x, y);
                	 Long v=map.get(p);
                	// System.out.println(v);
                	 if(v==null)
                	 {
                		 v=(long) 1;
                	 }
                	 else v++;
                	 
                	
                	 map.put(p, v);
                	// System.out.println(x+"  "+y);
        		 }
          }
          long[] ans=new long[15];
          ans[0]=(n-2)*(m-2);
          
          for(long value:map.values())
          {
        	  ans[(int) value]++;
              ans[0]--;  
          }
          for(int i=0;i<=9;i++)
          {
        	  System.out.println(ans[i]);
          }
	}
}
class pointt {
    int x,y;

	public pointt(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		pointt other = (pointt) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}
 
	
	
	
}


Measured memory_bytes: 171276
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <deque>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	int n;
	cin>>n;
	bool flag = false;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<n-2;i++){
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3624
import sys,itertools
def input():
    return sys.stdin.readline()[:-1]

H,W,K = map(int,input().split(' '))
l = [list(input()) for _ in range(H)]

MAP = [None]*H
for i in range(H):
    MAP[i] = [None]*W

cnt = 1
dp = []
for i in range(H):
    all_white_f = True
    flag = True
    for j in range(W):
        k = l[i][j]
        if k=='#':
            if not flag:
                cnt += 1
            all_white_f = False
            flag = False
        MAP[i][j] = str(cnt)
    if all_white_f:
        MAP[i] = None
        dp.append(i)
        cnt -= 1
    cnt += 1
pre = -1
tmp = []

if len(dp)==0:
    for i in range(H):
        print(' '.join(MAP[i]))
    exit()


if dp[0]==0:
    for i in dp:
        if i-pre==1:
            tmp.append(i)
            pre = i
        else:
            if len(tmp)!=0:
                for j in tmp:
                    first = tmp[-1]+1
                    MAP[j] = MAP[first]
                tmp = []
            MAP[i] = MAP[i-1]
    if len(tmp)!=0:
        for j in tmp:
            first = tmp[-1]+1
            MAP[j] = MAP[first]
else:
    for i in dp:
        MAP[i] = MAP[i-1]
for i in range(H):
    print(' '.join(MAP[i]))


Measured memory_bytes: 10100
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=1e5+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),n,m,x,y,i,j,temp,t,k,ans(0),sum(0),mn(M),mx(-9e9);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>x>>y>>k;
	if(x<=k)
	{
		k-=x;
		x=0;
	}else{
		x-=k;
		k=0;
	}
	if(y<=k)
	{
		k-=y;
		y=0;
	}else{
		y-=k;
		k=0;
	}
	cout<<x<<" "<<y;
	
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)


int main() {
	vector<pair<int, int>> ab;
	int n, m;
	cin >> n >> m;
	FOR(i, 1, n) {
		int a, b;
		cin >> a >> b;
		ab.push_back(MP(a, b));
	}
	sort(ALL(ab));
	priority_queue<int> pq;

	int starti = 0;
	int now = 1;
	ll res = 0;
	while (1) {
		FOR(i, starti, n - 1) {
			if (ab[i].F == now) {
				pq.push(ab[i].S);
			}
			else {
				starti = i;
				break;
			}
		}
		if (!pq.empty()) {
			res += pq.top();
			pq.pop();
		}
		now++;
		if (now == m + 1)break;
	}
	pv(res);
}

Measured memory_bytes: 1908
#include <iostream>

int main() {
    std::string S;
    std::cin >> S;
    
    int ans = 0;
    for (size_t i=0; i<S.size(); ++i) {
        if (S[i]=='+')
            ans++;
        else
            ans--;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;



int main(){
    string s;
    cin >> s;
    ll N=s.size();
    vector<ll> noX(0);
    vector<ll> rnoX(0);
    for(ll i=0;i<N;i++){
        if(s[i]!='x'){
            noX.emplace_back(s[i]);
            rnoX.emplace_back(s[i]);
        }
    ;}
    reverse(rnoX.begin(), rnoX.end());
    bool check=1;
    ll M=noX.size();
    for(ll i=0;i<M;i++){
        if(noX[i]!=rnoX[i])check=0;
    ;}
    if(!check){cout<<-1<<endl;return 0;}
    vector<ll> countX(0);
    vector<ll> rcountX(0);
    ll counter=0;
    for(ll i=0;i<N;i++){
        if(s[i]=='x'){counter++;}
        else {
            countX.emplace_back(counter);
            rcountX.emplace_back(counter);
            counter=0;}
    ;}
    countX.emplace_back(counter);
    rcountX.emplace_back(counter);
    reverse(rcountX.begin(), rcountX.end());
    counter=0;
    for(ll i=0;i<countX.size();i++){
        counter+=abs(countX[i]-rcountX[i])
    ;}
    cout<<counter/2<<endl;



    return 0;
}


Measured memory_bytes: 4460
n=int(input())
listv = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

lista=[]

for i in range(n):
	a=listv[i]-listc[i]
	if a<0:
		a=0
	lista.append(a)
	
print(sum(lista))

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

using namespace std;

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

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n,m;
void solve(){
	cin >> n >> m;
	
	i64 ans = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			if(m-i-j > n || m-i-j < 0) continue;
			ans++;
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256