akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long a, b;
    cin >> a >> b;
    if(2 * a >= b) {
        cout << b / 2;
    } else {
        long long ans = a;
        b -= 2 * a;
        cout << ans + (b / 4);
    }
}

Measured memory_bytes: 3584
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
s=input()
digits=list(int(i) for i in s)
n=len(s)
powermod=[0]*2019
powermod[0]=1
pow10=1
num=0
ans=0
for digit in reversed(digits):
    num+=digit*pow10
    rem=num%2019
    ans+=powermod[rem]
    pow10*=10
    powermod[rem]+=1
    num=rem
    pow10%=2019
print(ans)


Measured memory_bytes: 75864
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] color = new int[9];
        
        for(int i = 0; i < N; i++) {
            int rate = scan.nextInt();
            if(rate >= 3600) rate = 3200;
            color[rate/400]++;
        }
        
        int min = 0, max = 0;
        for(int i = 0; i < 9; i++) {
            if(i != 8) {
                if(color[i] != 0) {
                    min++;
                    max++;
                }
            } else {
                if(color[i] != 0) {
                    max += color[i];
                }
            }
        }
        if(min == 0) min = 1;
        System.out.println(min + " " + max);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

vector<int> g[1000];
vector<int> x;
bool ans;

int highestNum(vector<pair<int, int>> v, int n){
	vector<bool> dp(n + 1, false);
	dp[0] = true;
	for(auto i : v){
		vector<bool> _dp(n + 1, false);
		rep(j,n + 1){
			if(j + i.first <= n){
				_dp[j + i.first] = _dp[j + i.first] bitor dp[j];
			}
			if(j + i.second <= n){
				_dp[j + i.second] = _dp[j + i.second] bitor dp[j];
			}
		}
		dp = _dp;
	}

	for(int i = n; i >= 0; i--){
		if(dp[i]) return i;
	}
	return -1;
}

pair<int, int> dfs(int cur){
	vector<pair<int, int>> v;
	for(auto i : g[cur]){
		v.emplace_back(dfs(i));
	}
	//show(cur)

	int sum = 0, mini = 0;
	for(auto i : v){
		sum += i.first + i.second;
		mini += min(i.first, i.second);
		//cout << i.first << ' ' << i.second << endl;
	}
	if(mini > x[cur]){ //白黒どちらにしても、合計がx[cur]を超える場合
		ans = false;
	}

	int maxi = highestNum(v, x[cur]);
	//cout << x[cur] << ' ' << sum - maxi << endl;
	return make_pair(x[cur], sum - maxi);
}

int main(){
	int n;
	while(cin >> n){
		rep(i,1000) g[i].clear();
		x.clear();
		ans = true;

		range(i,1,n){
			int p;
			cin >> p;
			p--;
			g[p].emplace_back(i);
		}

		x = vector<int>(n);
		rep(i,n){
			cin >> x[i];
		}
		pair<int, int> s = dfs(0);
		if(ans){
			cout << "POSSIBLE" << endl;
		}else{
			cout << "IMPOSSIBLE" << endl;
		}
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
lint p=1e9+7;

lint pow_mod(lint b, lint n,lint p){
  lint ans=1;
  lint i=b;
  while(n>0){
    if(n%2==1){
      ans*=i;
      ans%=p;
    }
    i*=i;
    i%=p;
    n/=2;
  }
  return ans;
}

lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);
}

using namespace std;

int main(){
  lint n,k;
  cin>>n>>k;
  lint F[n+1];
  F[0]=1;
  FOR(i,1,n+1){
    F[i]=F[i-1]*i;
    F[i]%=p;
  }
  lint ans=0;
  REP(i,min(n,k+1)){
    lint nu=1,de=1;
    nu*=F[n];
    nu%=p;
    nu*=F[n-1];
    nu%=p;
    de*=F[i];
    de%=p;
    de*=F[n-i];
    de%=p;
    de*=F[i];
    de%=p;
    de*=F[n-i-1];
    de%=p;
    ans+=(nu*inv_mod(de,p))%p;
    // cerr<<i<<" "<<nu/de<<endl;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int H, W, D, Q;
    int A[310][310];
    int L[100010], R[100010];
    cin >> H >> W >> D;
    for (int i=0;i<H;i++) for (int j=0;j<W;j++) cin >> A[i][j];
    cin >> Q;
    for (int k=0;k<Q;k++) cin >> L[k] >> R[k];

    map<int,pair<int,int>> M;
    for (int i=0;i<H;i++) for (int j=0;j<W;j++) {
        M[A[i][j]] = make_pair(i,j);
    }

    vector<int> score(H*W+1,0);
    for (int i=D+1;i<=H*W;i++) {
        auto src = M[i-D], dest = M[i];
        score[i] = score[i-D] + abs(dest.first - src.first) + abs(dest.second - src.second);
    }

    for (int k=0;k<Q;k++) {
        cout << score[R[k]] - score[L[k]] << endl;
    }

    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  set<int> st, unite;
  rep(i, K)
    st.insert(P[i]);
  for (int i=K; i<N; i++) {
    if (P[i-K] == *(st.begin()) && P[i] > *(st.rbegin()))
      unite.insert(i);
    st.erase(P[i-K]);
    st.insert(P[i]);
  }
  int cnt = 1;
  bool flag = 0;
  for (int i=1; i<N; i++) {
    if (P[i] > P[i-1]) {
      cnt++;
      if (cnt >= K) {
        flag = 1;
        unite.insert(i);
      }
    } else
      cnt = 1;
  }
  cout << N-K+1-unite.size()+flag << endl;
  return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
inline ll LCM(ll a, ll b){return a * b / GCD(a, b);}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

ll a, b, c, d;
ll cntdiv(ll x){
    return x - x/c - x/d + x/LCM(c, d);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    cout << cntdiv(b)-cntdiv(a-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<pair<int, int>> pv;
  REP(i,n){
    int a; cin >> a;
    pv.emplace_back(a,i);
  }
  sort(ALL(pv));
  REP(i,n){
    cout << pv[i].second+1 << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4260
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <chrono>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef tuple<ll,ll,ll> tll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	int N,K;
	cin>>N>>K;
	vint H;
	for(int i=0;i<N;i++){
		int h;
		cin>>h;
		H.pb(h);
	}
	sort(H.begin(),H.end());
	int mini=INF;
	for(int i=0;i<=N-K;i++)
		mini=min(mini,H[i+K-1]-H[i]);
	cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def eratosthenes_sieve(n):
    """ 素数列挙(エラトステネスの篩) """

    table = [0] * (n + 1)
    prime_list = []
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    return prime_list

MAX = 10 ** 5
# 素数列挙
primes = set(eratosthenes_sieve(MAX))
acc = [0] * (MAX+1)
for a in range(3, MAX+1, 2):
    # 条件を満たす数を確認
    if a in primes and (a + 1) // 2 in primes:
        acc[a] = 1
# 累積和
acc = list(accumulate(acc))

for i in range(INT()):
    l, r = MAP()
    # 各クエリO(1)で対応
    ans = acc[r] - acc[l-1]
    print(ans)


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

int main(){
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int ans=0;
  for(int j=0;j<n;j++){
    while(a.at(j)%2==0){
      a.at(j)/=2;
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(void){
    int n;
  cin >> n;
  int num;
  if(n % 1000 == 0){
  	num = n / 1000;
  }
  else{
  	num = (n / 1000) + 1;
  }
  cout << 1000 * num - n << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),x(n+1),y(n),dif(n);
  for(ll &e:a)cin>>e;
  x[n]=accumulate(a.begin(),a.end(),0LL);
  y[0]=x[n]-a[0];
  x[0]=a[0];
  dif[0]=abs(x[0]-y[0]);
  for(int i=1;i<n-1;i++){
    y[i]=y[i-1]-a[i];
    x[i]=x[n]-y[i];
    dif[i]=abs(x[i]-y[i]);
  }
sort(dif.begin(),dif.end()-1);
 
cout << dif[0]<< endl;
      return 0;
}


Measured memory_bytes: 6528
from subprocess import*
call(('pypy3','-c',"""
def main():
  from heapq import heappush,heappop,heapify
  inf=2**31-1
  n,m,*t=map(int,open(0).read().split())
  z=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    z.extend([a,b,a+n*c,b+n*c])
  z={i:v for v,i in enumerate(sorted(set(z)))}
  try:
    z[1]
  except:
    print(-1)
    exit()
  edge=[[]for _ in range(len(z))]
  d={}
  l=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    if b<a:a,b=b,a
    i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c]
    if b==n:
      l.append(y)
    edge[i].append((1,x))
    edge[j].append((1,y))
    edge[x].extend([(0,i),(0,y)])
    edge[y].extend([(0,j),(0,x)])
  used=[False]+[True]*~-len(z)
  d=[0]+[inf]*~-len(z)
  edgelist=edge[0]
  heapify(edgelist)
  while edgelist:
    m=heappop(edgelist)
    if not used[m[1]]:
      continue
    d[m[1]]=m[0]
    used[m[1]]=False
    for e in edge[m[1]]:
      if used[e[1]]:
        heappush(edgelist,(e[0]+m[0],e[1]))
  a=min([d[i]for i in l]or[inf])
  print([a,-1][a==inf])
if __name__=='__main__':
  main()
"""))

Measured memory_bytes: 182140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>
int main()
{
    char a[27];
    scanf("%s",a);
    if(strcmp(a,"zyxwvutsrqponmlkjihgfedcba")==0)
        printf("-1");
    else
    {
        int l=strlen(a);
        int i;
        if(l<26)
        {
            for(i=0; i<l; i++)
                printf("%c",a[i]);
            int q[27];
            memset(q,0,sizeof(q));
            for(i=0; i<l; i++)
            {
                int k=a[i]-97;

                q[k]=1;
            }
            for(i=0; i<=26; i++)
            {
                if(q[i]==0)
                {
                    int e=97+i;
                    char x=e;
                    printf("%c",x);
                    break;
                }
            }

        }
        if(l==26)
        {
            int h=25;
            if(a[24]<a[25])
            {
                for(i=0; i<=23; i++)
                    printf("%c",a[i]);
                printf("%c",a[25]);

            }
            else
            {
                for(h=25; h>=0; h--)
                {
                    if(a[h-1]<a[h])
                       break;

                }
                int j;
                for(j=25;j>=h;j--)
                {
                    if(a[j]>a[h-1])
                      {
                          a[h-1]=a[j];
                          break;
                      }

                }
                for(i=0;i<h;i++)
                    printf("%c",a[i]);
            }

        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	cout << s[0];
	cout << s.length() - 2;
	cout << s[s.length() - 1];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    k--;
    int v = w - 1;

    int s[8][3] = {};
    for (int k = 0; k < 1 << v; k++) {
        int b = 1;
        for (int j = 0; j < v - 1; j++) {
            if (!(~(k >> j) & 3)) b = 0;
        }
        if (b) {
            int l[3] = { k << 1, ~(k ^ k << 1), k };
            for (int j = 0; j < w; j++) {
                for (int x = 0; x < 3; x++) {
                    if (l[x] >> j & 1) s[j][x]++;
                }
            }
        }
    }
    //for (int j = 0; j < w; j++) {
    //    for (int x = 0; x < 3; x++) {
    //        cout << s[j][x] << ' ';
    //    }
    //    cout << '\n';
    //}

    ll p[8] = { 1 }, q[8];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            q[j] = 0;
            for (int x = 0; x < 3; x++) {
                if (s[j][x]) q[j] += p[j - 1 + x] * s[j][x];
            }
        }
        for (int j = 0; j < w; j++) {
            p[j] = q[j] % P;
        }
    }

    cout << p[k] << endl;

    return 0;
}

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

int main() {
  int N = 0, S = 0, X = 0;
  cin >> N;
  X = N;
  while (X != 0) {
    S += (X % 10);
    X /= 10;
  }

  if (N % S == 0)
    cout << "Yes" << endl;
  else
   cout << "No" << endl;
}


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

const int N = 1010101;

char GetC(void) {
  static char pool[100000], *p1 = pool, *p2 = pool;
  return p1 == p2 && (p2 = (p1 = pool) + fread(pool, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}

void Read(int &x) {
  x = 0; char ch = GetC();
  while(!isdigit(ch)) ch = GetC();
  while(isdigit(ch))
    x = x * 10 + ch - 48, ch = GetC();
}

int zero[N], f[N], n, m, Ans;
vector<int> g[N];

void Dfs(int x, int fa) {
  zero[x] = 0;
  for(int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    if(v == fa) {
      continue;
    }
    Dfs(v, x);
    zero[x] += !f[v];
    f[x] += f[v];
  }
  if(zero[x]) {
    f[x] += zero[x] - 1;
  }
}

void Solve(int x, int fa) {
  if(g[x].size() == 1) {
    Ans = min(Ans, f[x] + 1);
  }
  for(int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    if(v == fa) {
      continue;
    }
    f[x] -= f[v];
    if(!f[v] && --zero[x]) {
      f[x]--;
    }
    f[v] += f[x];
    if(!f[x] && zero[v]++) {
      f[v]++;
    }
    
    Solve(v, x);
    
    if(!f[x] && --zero[v]) {
      f[v]--;
    }
    f[v] -= f[x];
    if(!f[v] && zero[x]++) {
      f[x]++;
    }
    f[x] += f[v];
  }
}

int main(void) {
  //freopen("beacon.in", "r", stdin);
  //freopen("beacon.out", "w", stdout);
  Read(n);
  for(int i = 1, u, v; i < n; i++) {
    Read(u), Read(v);
    u++; v++;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  Ans = 1e9;
  Dfs(1, 0);
  Solve(1, 0);
  printf("%d\n", Ans);
  return 0;
}


Measured memory_bytes: 37760
# ABC_123_B_Good_Distance.py
from math import sqrt

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

ct = 0
# ans=[]
# dis=[]
for i in range(N):
    for j in range(i+1,N):
        sum = 0
        for k in range(D):
            sum += (x[i][k] - x[j][k])**2
        # dis.append((i,j,sum))
        if int(sqrt(sum))**2 == sum:
            ct += 1
            # ans.append((i,j))
print(ct)
# print(dis)
# print(ans)


Measured memory_bytes: 62204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

		for (int i = 0; i < c; i++) {
			System.out.print(sum2[i]);
			System.out.print(" ");
		}

		System.out.println(bigsum);

	}

}

Measured memory_bytes: 34736
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll K;
    cin >> K;
    ll mx = 0;
    if(K <= A){
        mx = K;
    }else if(A < K && K <= A + B){
        mx = A;
    }else{
        ll sub = K - (A + B);
        mx = A - sub;
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 3636
N, A, B = map(int, input().split())
chem = []
for i in range(N):
    a, b, c = map(int, input().split())
    chem.append((a, b, c))

MAXX = N*10 + 1
MAXMONEY = 100*MAXX
money = [[MAXMONEY]*MAXX for _ in range(MAXX)]
ans = MAXMONEY

money[0][0] = 0
for i in range(N):
    a, b, cc = chem[i]
    for c1 in range(MAXX-1, -1, -1):
        for c2 in range(MAXX-1, -1, -1):
            if money[c1][c2] < MAXMONEY:
                newm = money[c1][c2] + cc
                if (c1 + a < MAXX) and (c2+b < MAXX) and (money[c1+a][c2+b] > newm):
                    money[c1 + a][c2 + b] = newm


rr = int(min((MAXX+0.9*A)//A, (MAXX+0.9*B)//B))
for bai in range(1, rr):
    if money[A*bai][B*bai] < ans:
        ans = money[A*bai][B*bai]

if ans >= MAXMONEY: ans = -1
print(ans)


Measured memory_bytes: 75160
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int main()
{
    string p,y="YYMM",a="AMBIGUOUS",m="MMYY",n="NA";
    cin>>p;
    p[0]=p[0]-'0';
    p[1]=p[1]-'0';
    p[2]=p[2]-'0';
    p[3]=p[3]-'0';
    if(((p[2]==0&&p[3]>=1&&p[3]<=9)||(p[2]==1&&(p[3]==0||p[3]==1||p[3]==2)))&&((p[0]==0&&p[1]>=1&&p[1]<=9)||(p[0]==1&&(p[1]==0||p[1]==1||p[1]==2))))
    cout<<a;
    else if((p[0]==0&&p[1]>=1&&p[1]<=9)||(p[0]==1&&(p[1]==0||p[1]==1||p[1]==2)))
      cout<<m;
    else if((p[2]==0&&p[3]>=1&&p[3]<=9)||(p[2]==1&&(p[3]==0||p[3]==1||p[3]==2)))
      cout<<y;
    else
      cout<<n;
    nl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int a,b;
    char enz[1];
    scanf("%d %c %d",&a,&enz[0],&b);
    switch (enz[0]){
        case '+':printf("%d\n",a+b);break;
        case '-':printf("%d\n",a-b);break;
    }
    return 0;
}

Measured memory_bytes: 128
def abc151_c():
    N, M = map(int, input().split())
    seen = [0]*(N+1)
    ac = 0
    wa = 0

    for _ in range(M):
        p, c = input().split()
        p = int(p)
        if seen[p] == -1:
            continue
        if c == "WA":
            seen[p] += 1
        else:
            ac += 1
            wa += seen[p]
            seen[p] = -1
    print("{} {}".format(ac, wa))
abc151_c()

Measured memory_bytes: 3828
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	int broken[m+5];
	for(int i=0; i<m; i++){
		scanf("%d", &broken[i]);
	}
	
	int i=3, j=0;
	unsigned long int temp, way1, way2;
	if(broken[0] == 1){
		if(broken[1] == 2){
			way1 = 0;
			i = n+1;
			j = 2;
		}
		else{
			way1 = 1;
			way2 = 0;
			j = 1;
			if(n==1) way1 = 0;
		}
	}
	else{
		if(broken[0] == 2){
			way1 = 0;
			way2 = 1;
			j = 1;
			if(n==1) way1 = 1;
		}
		else{
			way1 = 2;
			way2 = 1;
			if(n==1) way1 = 1;
		}
	}
	while(i<=n){
		if(i == broken[j]){
			temp = 0;
			j++;
			//printf("Yes");
		}
		else{
			temp = way1+way2;
		}
		way2 = way1;
		way1 = temp;
		//printf("%d段目:%lu\n", i, temp);
		temp = temp%1000000007;
		way1 = way1%1000000007;
		way2 = way2%1000000007;
		i++;
	}
	
	way1 = way1%1000000007;
	printf("%lu", way1);
	
	
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){

    int Go,Ga;

    scanf("%d %d",&Go,&Ga);

    if (Go > Ga){

        printf("a > b\n"); 

    }else if (Go < Ga){

        printf("a < b\n"); 

    } else if (Go == Ga){

        printf("a == b\n");

    } else  {
   
    }

    return 0;

}


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

int n;
int half;
double probs[3000];
long double dp[3000][3000];

long double solve_dp() {

    dp[0][0] = 1.0;
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = (1 - probs[i - 1]) * dp[i - 1][0];
    }
    for (int i = 1; i <= n; ++i) {
        dp[i][i] = dp[i - 1][i - 1] * probs[i - 1];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < i; ++j) {
            dp[i][j] = dp[i - 1][j] * (1 - probs[i - 1]) + dp[i - 1][j - 1] * probs[i - 1];
        }
    }

    long double sum = 0.0;
    for (int i = half; i <= n; ++i) {
        sum += dp[n][i];
    }

    return sum;
}

int main() {

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

    half = n / 2 + 1;
    long double ans = solve_dp();
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 139008
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
//sum
using namespace std;

int main() {
    int c1 = 0;
    int c2 = 0;
    int ans;
    int i;
    string s1;
    cin >> s1;
    for (i=0;s1.size()>i;i++) {
        if (i % 2 == 0) {
            if (s1[i] == '0') {
                c1++;
            }
        } else {
            if (s1[i] == '1') {
                c1++;
            }
        }
    }

    for (i=0;s1.size()>i;i++) {
        if (i % 2 == 0) {
            if (s1[i] == '1') {
                c2++;
            }
        } else {
            if (s1[i] == '0') {
                c2++;
            }
        }
    }
    cout << min(c1, c2) << endl;
}  

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, m, k;
    cin >> n >> m >> k;
    int sx, sy;
    cin >> sx >> sy;
    --sx, --sy;
    string s, t;
    cin >> s >> t;
    bool win = false;
    int cx = sx;
    for (int i = 0; i < k; ++i) {
    	if (s[i] == 'U') --cx;
    	if (cx < 0) win = true;
    	if (t[i] == 'D' && cx + 1 < n) ++cx;
    }
    cx = sx;
    for (int i = 0; i < k; ++i) {
    	if (s[i] == 'D') ++cx;
    	if (cx >= n) win = true;
    	if (t[i] == 'U' && cx > 0) --cx;
    }
    int cy = sy;
    for (int i = 0; i < k; ++i) {
    	if (s[i] == 'L') --cy;
    	if (cy < 0) win = true;
    	if (t[i] == 'R' && cy + 1 < m) ++cy;
    }
    cy = sy;
    for (int i = 0; i < k; ++i) {
    	if (s[i] == 'R') ++cy;
    	if (cy >= m) win = true;
    	if (t[i] == 'L' && cy > 0) --cy;
    }
    cout << (win ? "NO" : "YES") << '\n';
}

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

// Snuke Festival
int main() {
	int N;
	cin >> N;

	vector<int> vA(N), vB(N), vC(N);
	for (int i=0; i<N; i++) cin >> vA.at(i);
	for (int i=0; i<N; i++) cin >> vB.at(i);
	for (int i=0; i<N; i++) cin >> vC.at(i);

	// 降順ソート
	sort(vA.begin(), vA.end(), greater<int>());
	sort(vB.begin(), vB.end(), greater<int>());
	sort(vC.begin(), vC.end(), greater<int>());

	vector<int> vAonB(N,N);
	int now_B = 0;
	for (int i=0; i<N; i++) {
		while (now_B < N) {
			if (vA.at(i) >= vB.at(now_B)) {
				vAonB.at(i) = now_B;
				break;
			}
			else {
				now_B++;
			}
		}
	}

	vector<int> vBonC(N,N);
	int now_C = 0;
	for (int i=0; i<N; i++) {
		while (now_C < N) {
			if (vB.at(i) >= vC.at(now_C)) {
				vBonC.at(i) = now_C;
				break;
			}
			else {
				now_C++;
			}
		}
	}

	// 累積和
	vector<int64_t> vBonCsum(N + 1, 0);
	for (int i=0; i<N; i++) {
		vBonCsum.at(i+1) = vBonC.at(i) + vBonCsum.at(i);
	}

	int64_t res = 0ll;
	for (int i=0; i<N; i++) {
		res += vBonCsum.at(vAonB.at(i));
	}

	cout << res << endl;
	return 0;
}

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

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

    int size = S.size();

    if(size <= K){
        cout << S << endl;
    }else{
        cout << S.erase(K) << "..." << endl;
    }
}

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

bool hantei(int n, int d[], int k)
{
    for(int i = 0; i < k; i++){
        if(n == d[i]) return 0;
    }
    return 1;
}

int main()
{
    int n, k, d[10];
    cin >> n >> k;
    for(int i = 0; i < k; i++){
        cin >> d[i];
    }
    for(int j = n; ; j++){
        int l = j, mul = 1;
        while(l != 0){
            mul *= hantei(l % 10, d, k);
            l /= 10;
        }
        if(mul == 1){
            cout << j << endl;
            return 0;
        }
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        ulong person = ulong.Parse(ReadLine());

        List<ulong> input = new List<ulong>();
        for (ulong i = 0; i < 5; i++)
        {
            input.Add(ulong.Parse(ReadLine()));
        }

        ulong min = input.Min();

        ulong count = person / min + (person % min == 0 ? 0ul : 1ul);

        WriteLine(count + 4);

        ReadKey();
    }
}

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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;

int main() {
    int n, k, sum = 0;
    cin >> n >> k;
    double probability = 0;
    for(int i = 1; i <= n; i++) {
        sum += i;
       double pro = 1.0/n;
        while(sum < k) {
            pro *= 1.0/2;
            sum *= 2;
        }
        probability += pro;
        sum = 0;
    }
    cout << fixed << setprecision(10) << probability << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n+1];
    long[] b = new long[n+1];
    int cnt = 0;
    long min = 1000000000;
    for(int i = 1;i <= n;i++){
      a[i]=sc.nextLong();
      if(a[i]<0){
        cnt++;
      }
      b[i]=Math.abs(a[i]);
      min = Math.min(min,b[i]);
    }
    long sum = 0;
    for(int i = 1;i <= n;i++)sum+=b[i];
    if(cnt%2==0){
      System.out.println(sum);
    }else{
      sum -= min*2;
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 62540
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
int A, B, K;
int main() {
	cin >> K >> A >> B;
	for (int i = A; i <= B; i++) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 1;
 
vector <int> maxv(100002,1000000001);
vector <int> a;
vector <int> b;
int main(){
	int n,x;
	cin>>n>>x;
	int aa,bb;
	for(int i=0;i<n;i++){
		cin>>aa>>bb;
		a.push_back(aa);
		b.push_back(bb);
		
	}
	maxv[0]=0;
	for(int i=0;i<n;i++){
		for(int j=100000;j>=0;j--){
			if(j+b[i]<=100000){
				maxv[j+b[i]]=min(maxv[j+b[i]],a[i]+maxv[j]);
			}
		}
	}
	
	int i;
	for(i=100000;i>=0;i--){
		if(maxv[i]<=x)break;
	}
	
	cout<<i;
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
ll bigp = 1000000007;

//UnionFind //0-indexedに注意
struct UnionFind {
    vector <ll> par; 
    vector <ll> siz;
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
    ll size(ll x) {
        return siz[root(x)];
    }
};

int main()
{
    ll n,m;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    ll num_merge = 0;
    rep(i,m){
        ll x,y,z;
        cin >> x >> y >> z;
        if(!uf.issame(x,y)){
            uf.merge(x,y);
            num_merge++;
        }
    }
    cout << n-num_merge;
}


Measured memory_bytes: 1792
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    if(N&1):
        print((N+1)*(N-1)//2 -(N-1))
        pair = N-2
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)
    else:
        print(N*(N-2)//2)
        pair = N-1
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6032
#include <iostream>
using namespace std;
int main(){
        long long int n,m;
        cin >> n >>m;
        if(n>m) swap(n,m);
        if(n==1&&m==1) cout <<1 << endl;
        else if(n==1) cout << m-2 << endl;
        else{
                long long int ans=(n-2)*(m-2);
                cout << ans << endl;
        }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <chrono>
#include <ctime>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e6 + 10, INF = 1e9 * 100, K = 300, MOD = 1e9 + 7;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<ll>> gr;

ll f(ll b, ll n) {
    if (n < b) return n;
    else {
        return f(b, n / b) + (n % b);
    }
}

int main() {
    fastInp;

    ll n, s;
    cin >> n >> s;

    if (s == n) {
        cout << n + 1;
        return 0;
    }
    ll sq = sqrt(n);
    for (ll i = 2; i <= sq; i++) {
        ll vl = f(i, n);
        if (vl == s) {
            cout << i;
            return 0;
        }
    }
    /*for (int i = 2; i <= 1000; i++) {
        ll q = f(i, n);
        if (q) {
            cout << q << " " << i << "\n";
        }
    }*/

    sq = sqrt(n - s);
    ll mn = INF, dif = n - s;
    for (ll p = 1; p <= sq; p++) {
        if (dif % p == 0) {
        ll b = p;

        if (b >= 1 && mn > b + 1 && f(b + 1, n) == s) mn = b + 1;
        if (b > 0 && dif / b >= 1 && mn > dif / b + 1 && f(dif / b + 1, n) == s) mn = dif / b + 1;    
        }
    }
    if (mn == INF) {
        cout << "-1";
    } else {
        cout << mn;
    }
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <string>
 
using namespace std;
 
int main(){
    int a, b, c, d;
    int cnt = 0;
    cin >> a >> b >> c >> d;
    int t[101] = {};
    for (int i = 0; i < 101; i++)
    {
        if(i >= a and i <= b){
            t[i] += 1;
        } 
        if(i >= c and i <= d){
            t[i] += 1;
        } 
    }
    for (int i = 0; i < 101; i++)
    {
        if(t[i] == 2){
            cnt++;
        } 
    }
    if (!cnt) cout << 0 << endl;
    else cout << cnt - 1 << endl;
    

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int n, m;
	cin >> n >> m;
	priority_queue<ll> a;
	ll tmp;
	rep(i, n)
	{
		cin >> tmp;
		a.push(tmp);
	}

	rep(i, m)
	{
		a.push(a.top() / 2);
		a.pop();
	}
	ll ans = 0;
	while (!a.empty())
	{
		ans += a.top();
		a.pop();
	}
	cout << ans << endl;

	

}

Measured memory_bytes: 1400
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            var s = S.ToCharArray();
            var ans = s.Distinct().ToArray();
            if(S.Length == ans.Length)
            {
                WriteLine("yes");
            }
            else
            {
                WriteLine("no");
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;

  vector <int> pri(N);

  for(int i=0;i<N;i++){
    cin >> pri[i];
  }

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

  int sum=0;
  for(int i=0;i<K;i++){
    sum+=pri[i];
  }
cout << sum << endl;
}


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

using namespace std;

struct dsu {
  vector<int> p;
  int n;

  dsu(int n): n(n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  int find(int x) {
    while (x != p[x]) {
      x = p[x] = p[p[x]];
    }
    return x;
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    } else {
      p[x] = y;
      return true;
    }
  }
};

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (m % 2 == 1) {
    cout << -1 << "\n";
    return 0;
  }
  vector<vector<int>> g(n);
  vector<int> w(n);
  dsu d(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    if (d.unite(--x, --y)) {
      g[x].push_back(y);
      g[y].push_back(x);
    } else {
      w[x] ^= 1;
      cout << x + 1 << " " << y + 1 << "\n";
    }
  }
  function<void(int, int)> dfs = [&](int x, int p) {
    for (auto y : g[x]) {
      if (y == p) {
        continue;
      }
      dfs(y, x);
      if (w[y]) {
        cout << y + 1 << " " << x + 1 << "\n";
      } else {
        cout << x + 1 << " " << y + 1 << "\n";
        w[x] ^= 1;
      }
    }
  };
  dfs(0, -1);
  return 0;
}


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

using namespace std;

typedef long long int lli;

lli i,j,k,l,m,n,t,a,b,c,d,x,y,p,q,sum=0,total=0;

#define read(in) freopen("Input.txt","r",stdin)

int main()
{
    //read(in);
    cin>>t;
    sum=0;
    for(i=1 ; i<=t ; i++)
    {
        if(i%3==0 && i%5==0 || i%3==0 || i%5==0)
            a=1;
        else    sum+=i;
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 3624
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<ll,ll>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };


string s;
int n;

bool p(int a, int b) {
	a--;
	b--;
	string x = "", y = "";
	for (int i = a; i <= b; i++) {
		x += s[i];
	}
	for (int i = b; i >= a; i--) {
		y += s[i];
	}
	return x == y;
}
int main() {
	cin >> s;
	n = s.size();

	if (p(1, n) && p(1, (n - 1) / 2) && p((n + 3) / 2, n))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B,C,D;
ll mo=1000000007;
const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll memo[1010][1010];

ll combi(ll N_, ll C_) {
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

ll dfs(int a,int l) {
	int i;
	
	ll& ret=memo[a][l];
	if(ret>=0) return ret;
	
	ret=0;
	if(l==0) {
		ret = 1;
	}
	else {
		if(a>B) return 0;
		ret += dfs(a+1,l);
		ll v=1;
		for(i=1;i<=D && a<=l;i++) {
			(v *= combi(l,a) * inv[i] % mo)%=mo;
			l -= a;
			
			if(i>=C && i<=D) ret += v*dfs(a+1,l)%mo;
		}
	}
	ret%=mo;
	return ret;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B>>C>>D;
	
	MINUS(memo);
	combi(1,1);
	
	cout<<dfs(A,N)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 17664