akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)

ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int mod=998244353;
int k,n;
ll C[4444][4444];

int main(){
	C[0][0]=1;
	for(int i=1;i<=4000;i++){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	int k=read(),n=read();
	for(int i=2;i<=2*k;i++){
		ll ans=0,cur=1;
		int cnt=max(min(i/2,k)-max(i-k,1)+1,0);
		int x=k-cnt*2;
		for(int j=0;j<=cnt;j++){
			ans+=C[cnt][j]*1ll*cur%mod*C[n+x-1][x+j-1];
			ans%=mod;cur=cur*2%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 137728
N,K = map(int,input().split())
# ln = []
# for n in range(N + 1):
#     ln.append(n)
s = 0
f = N * (N + 1) / 2
for k in range(K,N + 2):
    # mx = sum(ln[N - k + 1:N + 1])
    # mn = sum(ln[0:k]) - 1
    mx = int(f - (N - k) * (N - k + 1) / 2)
    mn = int((k - 1) * k / 2) - 1
    m = mx - mn
    s += m
    s = s % (10 ** 9 + 7)
print(s)


Measured memory_bytes: 64860
import sys
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]
mod = 10**9+7
half = mod // 2 + 1
G = [[] for _ in range(N+1)]
for a, b in AB:
    G[a].append(b)
    G[b].append(a)
P = [0] * (N+1)
Size = [0] * (N+1)
def dfs(v):
    siz = 1
    p = P[v]
    for u in G[v]:
        if u != p:
            P[u] = v
            dfs(u)
            siz += Size[u]
    Size[v] = siz
dfs(1)
ans = 0
Prob = [0]
h = 1
for i in range(202020):
    h = h * half % mod
    Prob.append(1-h)
for v, (siz_v, Gv) in enumerate(zip(Size[1:], G[1:]), 1):
    if v == 1:
        ps = []
    else:
        ps = [Prob[N-siz_v]]
    par = P[v]
    for u in Gv:
        if par != u:
            siz_u = Size[u]
            ps.append(Prob[siz_u])
    if len(ps)<=1:
        continue
    cumprod1_ps = [1, 1]
    cumprod2_ps = [1, 1]
    cp = 1
    for p in ps:
        cp = cp * (1-p) % mod
        cumprod1_ps.append(cp)
    cp = 1
    for p in ps[::-1]:
        cp = cp * (1-p) % mod
        cumprod2_ps.append(cp)
    cumprod2_ps.reverse()
    an = 1 - cumprod1_ps[-1]
    for cp1, cp2, p in zip(cumprod1_ps[1:-1], cumprod2_ps[1:-1], ps):
        an -= cp1 * cp2 % mod * p
    ans += an
ans = ans % mod * half % mod
print(ans)


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

#define int 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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
    int n; cin >> n;
    vint a(n); rep(i,n) cin >> a[i];

    int res=0;
    rep(i,60){
        int zero=0,one=0;
        rep(j,n){
            if(a[j]&(1LL<<i)) one++;
            else zero++;
        }
        //cout<<one<<' '<<zero<<endl;
        int add=(one*zero)%MOD*modpow(2,i,MOD)%MOD;
        res=(res+add)%MOD;
        res%=MOD;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
	int a, b;
	while(1){
		cin>>a>>b;
		if (cin.eof())
			break;
		a+=b;
		b=0;
		while(a){
			a/=10;
			b++;
		}
		cout<<b<<endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(x-r<0||x+r>w||y-r<0||y+r>h){
        cout << "No" << endl;
    }else{
        cout << "Yes" <<endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;

double Main(int N)
{
    if(N%2) {
        return double(N/2+1)/double(N);
    }
    else {
        return 0.5;
    }
}

int main(void){
    int N;
    cin >> N;
    printf("%.10f\n", Main(N));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n+1);
    for (int i = 0; i < k; ++i) {
        int x;
        cin >> x;
        for (int j = 0; j < x; ++j) {
            int y;
            cin >> y;
            cnt[y]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += !(cnt[i+1]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3628
n,*L=map(int,open(0).read().split())
A,q,Q=L[:n],L[n],L[n+1:]
s,*l=[0]*100002
for i in A: s+=i; l[i]+=1
for b,c in zip(*[iter(Q)]*2): s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s)

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
vvi id();
int num(int &);
vvi seq(int &);
vvi rep(int &);
vvi operation(int &);
string s;
int n, l;
int num(int &i) {
	int ret = 0;
	while (i < l&&isdigit(s[i])) {
		ret *= 10;
		ret += s[i] - '0';
		++i;
	}
	return ret;
}

vvi operation(int &i) {
	char c = s[i];
	++i;
	int a = num(i);
	vvi ret(n, vi(n));
	REP(k, n) {
		REP(j, n) {
			ret[k][j] = k*n + j;
		}
	}
	if (c == 'R') {
		REP(k, n - 1) {
			ret[a - 1][k + 1] = (a - 1)*n + k;
		}
		ret[a - 1][0] = (a - 1)*n + n - 1;
	}
	else if (c == 'L') {
		REP(k, n - 1) {
			ret[a - 1][k] = (a - 1)*n + k + 1;
		}
		ret[a - 1][n - 1] = (a - 1)*n;
	}
	else if (c == 'D') {
		REP(k, n - 1) {
			ret[k + 1][a - 1] = k*n + a - 1;
		}
		ret[0][a - 1] = (n-1)*n+a-1;
	}
	else if (c == 'U') {
		REP(k, n - 1) {
			ret[k][a - 1] = (k + 1)*n + a - 1;
		}
		ret[n - 1][a - 1] = a-1;
	}
	return ret;
}

vvi con(vvi b, vvi a) {
	vvi ret(n, vi(n));
	REP(i, n) {
		REP(j, n) {
			int c = a[i][j];
			int e = c%n, d = c / n;
			int f = b[d][e];
			ret[i][j] = f;
		}
	}
	return ret;
}

vvi rep(int &i) {
	++i;
	vvi ret = seq(i);
	++i;
	int a = num(i);
	int c = ceil(log2(a));
	vector<vvi> x(c+1);
	x[0] = ret;
	int j = 0;
	REP(k, c) {
		x[k + 1] = con(x[k], x[k]);
	}
	vvi ans = id();
	//cout << a <<" "<<c<< endl;
	REP(k, c+1) {
		if (a&(1 << k)) {
			ans = con(ans, x[k]);
			j += (1 << k);
		}
		
	}
	//cout << j << endl;
	return ans;
}
vvi seq(int &i) {
	if (i == l || s[i] == ')') {
		return id();
	}
	vvi a;
	if (s[i] == '(') {
		a = rep(i);
	}
	else {
		a = operation(i);
	}
	vvi ret = con(a, seq(i));
	return ret;
}
vvi id() {
	vvi a(n, vi(n));
	REP(i, n) {
		REP(j, n) {
			a[i][j] = i*n + j;
		}
	}
	return a;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n >> l;
	cin >> s;
	int i = 0;
	vvi a = seq(i);
	REP(k, n) {
		REP(j, n) {
			cout << a[k][j] + 1;
			if (j != n - 1)cout << " ";
			else cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
int main(){
int r,q,a,b,c;
while(cin>>r,r){
cin>>r>>r;
vector<int>t(r),m(r),s(r);
for(int i=0;i<r;++i){
cin>>t[i]>>m[i]>>m[i]>>s[i];
}cin>>q;
for(int i=0;i<q;++i){
cin>>a>>b>>c;
int ans=0,cnt=0,p=a;
for(int i=0;i<t.size();++i){
int u=min(t[i],b);
if(cnt)ans+=max(u-p,0);
if(m[i] == c){
if(s[i])cnt++;
else cnt--;
}
p=max(p,u);
}
printf("%d\n", ans);
}
}
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;

main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)    cin>>a[i];
    ll suffixsum[n];suffixsum[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        suffixsum[i]=(suffixsum[i+1]+a[i])%MOD;
    }
    ll ans=0;
    for(int i=0;i+1<n;i++){
        ans+=a[i]*suffixsum[i+1]%MOD;
        ans%=MOD;
    }
    cout<<ans<<"\n";

}

Measured memory_bytes: 6776
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main () {
    int n;
    cin >> n;
    vector <int> b(n-1);
    rep(i,n-1) {
        cin >> b[i];
    }
    int sum =b[0];
    for(int i =1;i<n-1;i++) {
        sum += min(b[i-1],b[i]);
    }
    sum += b[n-2];
    cout << sum << endl;

}

Measured memory_bytes: 888
S = list(input())
T = list(input())

s = len(S)
t = len(T)

if t > s:
    print('UNRESTORABLE')
    exit()

for i in range(s-t,-1,-1):
    for j in range(t):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
        else:
            continue
    else:
        A = []
        for j in range(s):
            if i <= j < i+t:
                A.append(T[j-i])
            elif S[j] == '?':
                A.append('a')
            else:
                A.append(S[j])
        ans = A[0]
        for j in range(1,s):
            ans = ans + A[j]
        print(ans)
        break
else:
    print('UNRESTORABLE')

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

int main(){
	string S,T,U;
  	int A,B;
  	cin >> S >> T >> A >> B >> U;
  	
  	if(S == U){
    	cout << A-1 << " " << B << endl;
    }else{
    	cout << A << " " << B-1 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main() {
    int n;
    scanf("%d", &n);
    
    long long int r = 100000;
    for (int i = 0; i < n; ++i) {
        r += r * 0.05;
        int s = r % 1000 ? 1000 : 0; 
        r = r / 1000 * 1000;
        r += s;
    }
    printf("%lld\n", r);
}

Measured memory_bytes: 1004
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
 
int main() {
  string S;
  vector<int> v;
  cin >> S;
  int N = S.size();
  int key = 0;
  char k[2] = {'R', 'L'};
  rep(i, N) {
    if(S[i] == k[key]) continue;
    else {
      v.push_back(i-1);
      key = key ^ 1;
    }
  }
  v.push_back(N-1);
  int ans[100000] = {0};
  rep(i, v.size()) {
    if(i % 2 == 1) continue;
    if(i == 0) {
      ans[v[i]] = (v[i] + 2) / 2 + (v[i+1]-v[i]) / 2;
      ans[v[i]+1] = (v[i] + 1) / 2 + (v[i+1]-v[i]+1) / 2;
    } else {
      ans[v[i]] = (v[i]-v[i-1]+1) / 2 + (v[i+1]-v[i]) / 2;
      ans[v[i]+1] = (v[i]-v[i-1]) / 2 + (v[i+1]-v[i]+1) / 2;
    }
  }
  rep(i, N) {
    cout << ans[i];
    if(i != N-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

Measured memory_bytes: 4236
#include <iostream>

using namespace std;

int main(void)
{
    int K = 0;
    int S = 0;

    cin >> K >> S;

    int count = 0;
    for (int x = 0; x <= K; x++)
    {
        if (x + K + K < S)
            continue;

        for (int y = 0; y <= K; y++)
        {
            if (x + y <= S && x + y + K >= S)
                count++;
        }
    }

    cout << count << "\n";

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] t = new long[n];
		for(int i=0;i<n;i++) {
			t[i] = in.nextLong();
		}
		Arrays.sort(t);
		long ans = t[n-1];
		for(int i=n-2;i>=0;i--) {
			long g = gcd(ans,t[i]);
			ans = ans/g*t[i];
		}
		System.out.println(ans);
		in.close();
	}
	
	public static long gcd(long a,long b) {
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}

}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    
    vector<int> a(n), b(n),c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    
    long long ans = 0;
    for(int i = 0; i < n; i++){
        long long number_of_lower_parts = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        long long number_of_upper_parts = c.end() - upper_bound(c.begin(),c.end(),b[i]);
        ans += number_of_lower_parts * number_of_upper_parts;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1536
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, Y = lr()
bl = Y % 2 == 0
if Y < 2 * X or Y > 4 * X:
    bl = False
print('Yes' if bl else 'No')


Measured memory_bytes: 9172
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, L;

struct Elem {
    int time, pos, idx;
};

bool operator<(const Elem &a, const Elem &b) {
    if(a.time != b.time) return a.time > b.time;
    else if(a.pos != b.pos) return a.pos < b.pos;
    else return a.idx < b.idx;
}

signed main() {
    while(cin >> N >> L, N || L) {
        vector<int> dir, pos;
        rep(i,0,N) {
            char c; int p; cin >> c >> p;
            if(c == 'R') dir.push_back(1);
            else dir.push_back(-1);
            pos.push_back(p);
        }

        Elem ans = Elem{-1, -1, -1};
        rep(i,0,110) {
            rep(j,0,N) {
                if(pos[j] == 0 || pos[j] == L) continue;
                if(dir[j] > 0) pos[j]++;
                else pos[j]--;

                if(pos[j] == L || pos[j] == 0) {
                    chmin(ans, Elem{i+1, pos[j], j+1});
                }
            }

            rep(i,0,N) rep(j,i+1,N) {
                if(pos[i] == pos[j]) {
                    dir[i] *= -1;
                    dir[j] *= -1;
                }
            }
        }
        printf("%lld %lld\n", ans.time, ans.idx);
    }
    return 0;
}

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

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/09/30  Problem: Tenka1_programmer D  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N,K;

ll ans = 0LL;
ll ansdown = 0LL;
ll up;
ll down;
string to_binString(unsigned int val) //二進数表示
{
	if (!val)
		return std::string("0");
	std::string str;
	while (val != 0) {
		if ((val & 1) == 0)  // val は偶数か？
			str.insert(str.begin(), '0');  //  偶数の場合
		else
			str.insert(str.begin(), '1');  //  奇数の場合
		val >>= 1;
	}
	return str;
}
void print_bin(int a) {
	cout << to_binString(a) << endl;
}

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

	cin >> N>>K;
	
	int n = 1;
	while (2 * n < K)n *= 2;
	n--;
	down = n;
	up = K;
	vector<pll>p(N);

	FOR(i, 0, N) {
		cin >> p[i].first >> p[i].second;
	}

	FOR(i, 0, N) {//K以下の最大の11111...11
		if (down >=  p[i].first) {
			ansdown += p[i].second;
		}
	}
	ans = max(ans, ansdown);
	FOR(i,0,31){
		ll num = 0;
		ll ret = 0;

		if (K&(i << 1) == 0)continue;
		FOR(j, 0, i) {
			num |= 1 << j;
		}
		FOR(j, i + 1, 31) {
			if (K&(1 << j))num |= 1 << j;
		}
		FOR(i, 0, N) {
			if ((num | p[i].first) <= K)ret += p[i].second;
		}

		ans = max(ans, ret);
	}

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


Measured memory_bytes: 1792
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>
#include<cstdio>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)


using namespace std;

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




const int INF = 1e9 + 7;


/******************************************************************************************/


//繋げる方向を一方向にする
typedef struct union_find {

	vector<ll> pa;//親
	vector<ll> ra;//木の深さ
	vector<ll> siz;
	//n要素で初期化
	void init(ll n) {
		pa.resize(n);
		ra.resize(n);
		siz.resize(n);
		for (ll i = 0; i < n; i++) {
			pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
			ra[i] = 0LL;/*各ノード自体の高さは0*/
			siz[i] = 1LL;
		}
	}
	//木の根を求める
	ll find(ll x) {
		if (pa[x] == x) {
			return x;/*根ならそのノードの番号を返す*/
		}
		else {
			return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
		}
	}

	//xとyの属する集合を併合する
	void unite(ll x, ll y) {
		x = find(x);//xの根の番号を探す
		y = find(y);//yの根の番号を探す
		if (x == y) {//一致すればつながっている
			return;
		}
		pa[y] = x;
		siz[x] += siz[y];
	}

	//xとyが同じ集合に属するか判定
	bool same(ll x, ll y) {
		return find(x) == find(y);//同じ集合なら1、違うなら0が返る
	}
}UF;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	
	int n, m, q;

	cin >> n >> m;

	UF tree;
	tree.init(n+10);

	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		if (a > b) {
			swap(a, b);
		}
		//b→a
		tree.unite(a, b);

	}

	cin >> q;

	for (int i = 0; i < q; i++)
	{
		int a, b;
		cin >> a >> b;
		if (tree.same(a, b)) {
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}


	return 0;
}



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

int main(){
  int N, M, ans = 0;
  cin >> N >> M;
  vector<set <int>> v(M, set<int>());
  rep(i, M){
    int in;
    cin >> in;
    rep(j, in){
      int input;
      cin >> input;
      v.at(i).insert(input);
    }
  }
  vector<int> vp(M);
  rep(i, M) cin >> vp.at(i);
  
  int count;
  for(int i = 0; i < pow(2, N); i++){
    rep(j, M){
      count = 0;
      for(auto itr = v.at(j).begin(); itr != v.at(j).end(); itr++){
        int ad = pow(2, (*itr-1));
        if((i & ad) == ad)count++;
      }
      if(count % 2 != vp.at(j)){
        ans--;
        break;
      }
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int N,K,X,Y;
scanf("%d %d %d %d",&N,&K,&X,&Y);
int l=1,sum=0;
if(N>K){
while(l<=K){
sum=sum+X;
l++;
}
}
else{
        while(l<=N){
sum=sum+X;
l++;
}
}
while(l<=N){
sum=sum+Y;
l++;
}
printf("%d\n",sum);
}


Measured memory_bytes: 128
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let a: Vec<usize> = parse!(it, n);
    let mut asum: Vec<usize> = vec![];
    for i in 0..n {
        for j in (i + 1)..(n + 1) {
            asum.push(a[i..j].iter().sum());
        }
    }
    let mut ret = 0;
    for i in (0..40).rev() {
        let cur = 1 << i;
        let mut count = 0;
        let mut ok = vec![false; asum.len()];
        for i in 0..asum.len() {
            let a = asum[i];
            if cur & a != 0 {
                count += 1;
                ok[i] = true;
            }
        }
        if count < k {
            continue;
        }
        ret += cur;
        let mut newasum = vec![];
        for i in 0..asum.len() {
            if ok[i] {
                newasum.push(asum[i]);
            }
        }
        asum = newasum;
    }
    println!("{}", ret);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, m;
   while (cin >> n >> m, n) {
      vector<pair<int, int>> vp;
      for (int i = 0; i < n; i++) {
         int d, p;
         cin >> d >> p;
         vp.push_back(make_pair(p, d));
      }
      sort(vp.begin(), vp.end());
      reverse(vp.begin(), vp.end());
      int ans = 0;
      for (int i = 0; i < n; i++) {
         if (vp[i].second <= m) { // 金があれば
            m -= vp[i].second;
         } else { // 金が少ないなら
            int t = vp[i].second - m;
            ans += vp[i].first * t;
            m = 0;
         }
      }
      cout << ans << endl;
   }

   return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
struct node
{
	int u,v,w;
	bool mark,del,use;
	node(int x = 0,int y = 0,int z = 0)
	{
		u = x;
		v = y;
		w = z;
		mark = del = use = false;
	}
	friend bool operator < (const node &a,const node &b)
	{
		return a.w < b.w;
	}
}e[maxn];

int uf[510],n,m,cnt;
bool flag[maxn];

int find(int x)
{
	return uf[x] = uf[x] == x?uf[x]:find(uf[x]);
}
void init()
{
	for(int i = 0;i <= n;i++) uf[i] = i;
}

int kruscal(bool first)
{
	init();
	int ans,x,y;
	ans = 0;
	cnt = 0;
	for(int i = 0;i < m;i++)
	{
		if(!first && e[i].del) continue;
		x = find(e[i].u);
		y = find(e[i].v);
		if(x != y)
		{
			uf[x] = y;
			ans += e[i].w;
			if(first) 
		    {
			e[i].use = 1;
		    }
		    if(++cnt == n-1) return ans;
		}
		
		
	}
	return ans;
}


int main()
{
	//freopen("data.in","r",stdin);
	while(~scanf("%d %d",&n,&m))
	{
	int u,v,w,res1,res2;
	memset(flag,0,sizeof(flag));
	for(int i = 0;i < m;i++)
	{
		scanf("%d %d %d",&u,&v,&w);
		e[i] = node(u,v,w);
	}
	sort(e,e+m);
	for(int i = 1;i < m;i++)
	{
		if(e[i].w == e[i-1].w) e[i].mark = e[i-1].mark = 1;
	}
	int MST = kruscal(true);
//	if(Unique) printf("%d %d\n",cnt,MST);

	res1 = 0,res2 = 0;
	for(int i = 0;i < m;i++)
	{
		if(e[i].mark && e[i].use)
		{
			e[i].del = 1;
	    	int mst = kruscal(false);
	    	if(mst == MST && cnt == n-1)
			flag[i] = 1;
	    	e[i].del = 0;
		}
	
		if(!flag[i] && e[i].use)
		{
			res1 ++;
			res2 += e[i].w;
		}
   } 
	printf("%d %d\n",res1,res2);	
}
}

Measured memory_bytes: 2020
// Code for A - Task Scheduling Problem
#include <iostream>
using namespace std;

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  int mina = min(a1, a2);
  mina = min(a3, mina);
  int maxa = max(a1, a2);
  maxa = max(a3, maxa);

  cout << maxa - mina << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
N,x=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=sorted(data)
ans=0
if data[0] > x:
    print(0)
else:
    for i in data:
        x=x-i
        if x < 0:
            break
        ans+=1
    if x > 0 and x!=0 and ans !=1:
        ans-=1
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[84];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll m = 1000, k = 0;
    for(int i = 0; i < n; i++){
        if(a[i + 1] < a[i] || i == n - 1){
            m += a[i] * k;
            k = 0;
        }
        else if(a[i + 1] > a[i]){
            k += m / a[i];
            m %= a[i];
        }
    }
    cout << m << endl;
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

int main()
{
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;

    A--;B--;
    C--;D--;

    if(A>B){
        swap(A,B);
        swap(C,D);
    }

    for (int i = A;i<C;i++){
        if(S[i] == '#' && S[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = B;i<D;i++){
        if(S[i] == '#' && S[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    if(C>D){
        for (int i = B;i<=D;i++){
            if(S[i-1] == '.' && S[i]=='.' && S[i+1]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

int main() {
  string s;
  cin>>s;

  map<char, int> m;
  for (char c: s) {
    ++m[c];
  }
  int min_cnt = min(m['a'], min(m['b'], m['c']));
  int max_cnt = max(m['a'], max(m['b'], m['c']));
  if (max_cnt - min_cnt >= 0 && max_cnt - min_cnt <= 1) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;


vector<long long int >v;

int main()
{
    FastIO;

    int n=0;
    cin>>n;

	 n %= 10;
	if (n == 3) puts("bon");
	else if (n <= 1 || n == 6 || n == 8) puts("pon");
	else puts("hon");
	
	return 0;



}


Measured memory_bytes: 3604
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

static int w[100000+1];

static int Allocate(int P, int w[], int n) {
    int i;
    int k = 0;
    int t = 0;

    k = 1;
    for ( i = 0; i < n; i++ ) {
        if ( w[i] > P ) {
            return -1;
        }
        t += w[i];
        if ( t <= P ) {
            continue;
        }

        k++;
        t = w[i];
    }

    return k;
}



int main(int argc, char* argv[]) {
    int n, k, i;
    int total_w = 0;

    scanf("%d %d\n", &n, &k);

    for ( i = 0; i < n; i++ ) {
        int t;
        scanf("%d\n", &t);
        w[i] = t;
        total_w += t;
    }

      /* binary search */
    int left = total_w / k;
    int right = total_w + 1;
    int min_p = total_w;
    while ( 1 ) {
        int center = (left + right) / 2;
        int t;

        t = Allocate(center, w, n);
        if ( (t < 0) || (t > k) ) {
            left = center + 1;
        } else /* t <= k*/ {
            if ( center < min_p ) {
                min_p = center;
                right = center - 1;
            } else {
                break;
            }
        }
        if ( left > right ) {
            break;
        }
    }

    printf("%d\n", min_p);

    return 0;
}



Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	int t=1;
	int x=(a+d-1)/d;
	int y=(b+c-1)/b;
	if(x>=y)
	cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<stdlib.h>
using namespace std;
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer n;
  for(n=nil->next;n!=nil;n=n->next){
    if(n->key==key)return n;
  }
  return NULL;
}

void init(){
  nil =(node *)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( isf == 0)printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
    if ( cur == nil ) break;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  // cout<<n<<" "<<n->key<<" "<<n->next->key<<" "<<t->key<<" "<<t->next->key<<endl;
  if(t->next==nil){
    t->prev->next=nil;
    nil->prev=t->prev;
  }else if(t->prev==nil){
    nil->next=t->next;
    t->next->prev=nil;
  }else{
    t->prev->next=t->next;
    t->next->prev=t->prev;
  }
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer n=nil->prev;
  if(n==nil)return;
  deleteNode(n);
}

void delete_(int key){
  NodePointer n=listSearch(key);
  //cout<<"deleted "<<n<<" "<<n->key<<endl;
  if(n==nil)return;
  if(n!=NULL)deleteNode(n);
}


void insert(int key){
  NodePointer x;
  x = (node *)malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    	if ( com[6] == 'F' )deleteFirst();
    	else if ( com[6] == 'L' )deleteLast();
      } else {
    	delete_(key); nd++; 
      }
      size--;
    }
    // printList();
  }
  printList();
  return 0;
}



Measured memory_bytes: 34384
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {
    SS(ll,n,m);
    vector<bool>one(n);
    vector<bool>two(n);
    rep(i,m){
        SS(ll,v1,v2);
        v1--;v2--;
        if(v1==0)one[v2]=true;
        else if(v2==n-1)two[v1]=true;
    }
    rep(i,n){
        if(one[i]&&two[i]){
            p("POSSIBLE");
            return 0;
        }
    }
    p("IMPOSSIBLE");
}

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

using namespace std;

typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;

int main()
{
	ios::sync_with_stdio(0);
    ll a,b;
    cin >> a >> b;
    ll cnt=0;
    while (a<=b)
    {
        a*=2;
        cnt++;
    }
    cout << cnt;    
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m;
string a[50], b[50];

bool solve() {
	inc(i, n - m + 1) {
	inc(j, n - m + 1) {
		bool flag = true;
		inc(k, m) {
		inc(l, m) {
			if(b[k][l] != a[k + i][l + j]) { flag = false; }
		}
		}
		if(flag) { return true; }
	}
	}
	
	return false;
}

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i]; }
	inc(i, m) { cin >> b[i]; }
	
	cout << (solve() ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N, M; cin>>N>>M;
  priority_queue<int, vector<int> > q;
  REP(i,N) {
    int A; cin>>A;
    q.push(A);
  }
  REP(i,M) {
    int T = q.top();
    q.pop();
    q.push(T/2);
  }
  ll ans = 0;
  REP(i,N) {
    int T = q.top();
    ans += (ll) T;
    q.pop();
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 892
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	seg := newSegment(n)
	for i := 0; i < n; i++ {
		seg.update(i, 1<<uint(s[i]-'a'))
	}
	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		switch getNextInt(scanner) {
		case 1:
			seg.update(getNextInt(scanner)-1, 1<<uint(getNextString(scanner)[0]-'a'))
		case 2:
			fmt.Fprintln(writer, pcount(seg.get(getNextInt(scanner)-1, getNextInt(scanner))))
		}
	}
}
func pcount(x uint32) int {
	ans := 0
	for x > 0 {
		ans += int(x % 2)
		x >>= 1
	}
	return ans
}

type segment [][]uint32

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]uint32, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]uint32, 1))
	return seg
}
func (seg segment) choosemin(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func (seg segment) update(i int, x uint32) {
	seg[0][i] = x
	for h := 1; h < len(seg); h++ {
		i >>= 1
		seg[h][i] = seg[h-1][i<<1] | seg[h-1][seg.choosemin(i<<1+1, len(seg[h-1])-1)]
	}
}
func (seg segment) get(l, r int) uint32 {
	s := seg[0][l]
	for h := 0; h < len(seg) && l < r; h++ {
		if l%2 == 1 {
			s = s | seg[h][l]
			l++
		}
		l >>= 1
		if r%2 == 1 {
			s = s | seg[h][r-1]
		}
		r >>= 1
	}
	return s
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n , q;
int arr[N];
int freq[N];
int val[N + N];
int ans;
int main(){
	scanf("%d %d" , &n , &q);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
		++freq[arr[i]];
	}
	for(int i = 1 ; i <= n ; ++i){
		++val[i - freq[i] + N];
		--val[i + N];
	}
	for(int i = 1 ; i < N + N ; ++i){
		val[i] += val[i - 1];
	}
	for(int i = 0 ; i < n ; ++i){
		ans += !val[i + N];
	}
	for(int i = 1 ; i <= q ; ++i){
		int idx , now;
		scanf("%d %d" , &idx , &now);
		--val[arr[idx] - freq[arr[idx]] + N];
		if(arr[idx] >= freq[arr[idx]]){
			ans += !val[arr[idx] - freq[arr[idx]] + N];
		}
		--freq[arr[idx]];
		arr[idx] = now;
		++freq[now];
		if(now >= freq[now]){
			ans -= !val[now - freq[now] + N];
		}
		++val[now - freq[now] + N];
		printf("%d\n" , ans);
	}
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=2005;
const ll INF=1LL<<60;
ll dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<ll,int>> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i].fi;
        A[i].se=i+1;
    }
    sort(all(A),[](auto a,auto b){
        return a.fi>b.fi;
    });
    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) dp[i][j]=-INF;
    dp[0][0]=0;
    
    for(int i=0;i<N;i++){
        for(int l=0;l<=i;l++){
            int r=N-(i-l);
            chmax(dp[i+1][l+1],dp[i][l]+A[i].fi*abs(A[i].se-(l+1)));
            chmax(dp[i+1][l],dp[i][l]+A[i].fi*abs(A[i].se-r));
        }
    }
    
    ll ans=-INF;
    for(int j=0;j<=N;j++) chmax(ans,dp[N][j]);
    
    cout<<ans<<endl;
}



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

//ABC167D
//ABC167C
int main(void) {
  int n, m, x, k, i, p, cou=0, tmp, min=1e9, price=0;
  scanf(" %d %d %d", &n, &m, &x);
  int c[n], a[n][m], unst[m];
  for(i=0; i<n; i++){
    scanf(" %d", &c[i]);
    for(k=0; k<m; k++)
      scanf(" %d", &a[i][k]);
  }

  for(i=1; i<pow(2, n); i++){
    tmp=i;
    price=0;
    for(k=0; k<m; k++)
      unst[k]=0;

    for(p=0; p<n; p++){
      if(tmp%2==1){
        price+=c[p];
        for(k=0; k<m; k++)
          unst[k]+=a[p][k];
      }
      tmp/=2;
    }
    for(k=0; k<m; k++){
      if(unst[k]>=x){
        if(k==m-1&&min>price) min=price;
      }else break;
    }
  }
  //for(i=0; i<n; i++)
    //printf("c[%d]=%d\n", i, c[i]);
  if(min==1e9)printf("-1");
  else printf("%d", min);
}

Measured memory_bytes: 2432
#include <cstdio>
using namespace std;

int main(){
	int a, b, n;
	int res;
	
	while(scanf("%d%d%d", &a, &b, &n) != EOF){
		res = 0;
		
		a = (a % b) * 10;
		for(int i = 0; i < n; i++){
			res += a / b;
			
			a = (a % b) * 10;
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	int r = 0;
	for (int i = a; i <= b; i++)
	{
		int s = i % 10, t = i / 10000 % 10;
		int u = i / 10 % 10, v = i / 1000 % 10;
		if (s == t&&u == v)r++;
	}
	printf("%d\n", r);
}


Measured memory_bytes: 128
import heapq
n, m, s, t = map(int, input().split())
INF = 10**20
data = []
for _ in range(m):
    data.append(list(map(int, input().split())))

check = [False] * (n+1)
graph = [[] for i in range(n+1)]

for i in range(m):
    graph[data[i][0]].append([data[i][1], data[i][2], data[i][3]])
    graph[data[i][1]].append([data[i][0], data[i][2], data[i][3]])
city_yen_cost = [INF] * (n+1)
city_yen_cost[s] = 0
queue = []
#[cost, vertex]
heapq.heappush(queue, [0, s])
count = 0
while count != n:
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        count += 1
        check[now[1]] = True
        for path in graph[now[1]]:
            if not check[path[0]]:
                if city_yen_cost[now[1]]+path[1] < city_yen_cost[path[0]]:
                    city_yen_cost[path[0]] = city_yen_cost[now[1]]+path[1]
                    heapq.heappush(queue, [city_yen_cost[now[1]]+path[1], path[0]])




check = [False] * (n+1)
city_snuke_cost = [INF] * (n+1)
city_snuke_cost[t] = 0
queue = []
heapq.heappush(queue, [0, t])
count = 0
while count != n:
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        count += 1
        check[now[1]] = True
        for path in graph[now[1]]:
            if not check[path[0]]:
                if city_snuke_cost[now[1]]+path[2] < city_snuke_cost[path[0]]:
                    city_snuke_cost[path[0]] = city_snuke_cost[now[1]]+path[2]
                    heapq.heappush(queue, [city_snuke_cost[now[1]]+path[2], path[0]])


for i in range(n+1):
    city_yen_cost[i] += city_snuke_cost[i]
for i in range(n):
    city_yen_cost[-i-2] = min(city_yen_cost[-i-2], city_yen_cost[-i-1])
for i in range(n):
    print(10**15-city_yen_cost[i+1])


Measured memory_bytes: 126680
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;

int main()
{
    string s,t;
    cin >> s >> t;
    int replace = -1;
    for(int i = s.size()-1; i >= 0; --i){
        bool equal = true;
        for(int j = t.size()-1, cnt = 0; j >= 0; --j){
            if(s[i-cnt] != '?' && s[i-cnt] != t[j]){
                equal = false;
                break;
            }
            cnt++;
        }
        if(equal){
            replace = i-t.size()+1;
            break;
        }
    }

    if(replace == -1)
        cout << "UNRESTORABLE";
    else{
        for(int i = 0; i < s.size(); ++i){
            if(i == replace){
                cout << t;
                i += t.size()-1;
            }
            else if(s[i] == '?')
                cout << 'a';
            else
                cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256