akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(1000000)
def FF(E, s, t):
    NN = 2*N+2
    G = [[] for _ in range(NN)]
    for a, b, f in E:
        G[a].append([b, f, len(G[b])])
        G[b].append([a, 0, len(G[a])-1])
    
    def dfs(s, t, f):
        if s == t:
            return f
        used[s] = 1
        for i, (b, _f, r) in enumerate(G[s]):
            if used[b] or _f == 0: continue
            d = dfs(b, t, min(f, _f))
            if d > 0:
                G[s][i][1] -= d
                G[b][r][1] += d
                return d
        return 0
    
    flow = 0
    while 1:
        used = [0] * NN
        f = dfs(s, t, 10**100)
        if f == 0:
            return flow
        flow += f

N = int(input())
R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a, b))
B = []
for _ in range(N):
    c, d = map(int, input().split())
    B.append((c, d))

E = []
for i in range(N):
    E.append((2*N, i, 1))
for i in range(N):
    E.append((N+i, 2*N+1, 1))

for i in range(N):
    for j in range(N):
        if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
            E.append((i, N+j, 1))

print(FF(E, 2*N, 2*N+1))


Measured memory_bytes: 47196
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = intList()
    val m = (1e9 + 7).toLong()
    val map = hashMapOf<Int, Int>()
    val odd = n % 2 == 1

    a.forEach {
        map[it] = map.getOrDefault(it, 0) + 1
    }
    if (n % 2 == 1) {
        if (map.getOrDefault(0, 0) != 1) {
            println("0")
            return
        }
    } else {
        if (map.getOrDefault(0, 0) != 0) {
            println("0")
            return
        }
    }
    map.remove(0)
    var t = 1L
    map.values.forEach {
        if (it != 2) {
            println("0")
            return
        } else {
            t = t * 2 % m
        }
    }
    println(t.toString())
}


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

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

	string c[3];
	cin >> c[0] >> c[1] >> c[2];
	cout << c[0][0] << c[1][1] << c[2][2] << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
c = sorted(a)
d = sorted(b)

ans = 0
if n % 2 == 1:
    ans = d[(n-1)//2] - c[(n-1)//2] + 1
else:
    ans = d[n//2] + d[n//2 - 1] - c[n//2] - c[n//2 - 1] + 1

print(ans)

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

int main() {
  
  int a, b, c, d;;
  cin >> a >> b >> c >> d;
  int A, B;
  A = a + b;
  B = c + d;
  
  if (A > B) {
    cout << "Left" << endl;
  }
  
  if (A == B) {
    cout << "Balanced" << endl;
  }
  
  if (A < B) {
    cout << "Right" << endl;
  }
}
  

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
  if ( A + B > C + D ) cout << "Left" << endl;
  else if ( A + B < C + D ) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

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

int main() {
    int h,w,ch, cw, dh, dw; cin >> h >> w >>ch >> cw >> dh >> dw;
    --ch, --cw, --dh, --dw;
    deque<Pii> q;
    vector<string> da(h);
    rip(i,h,0) cin >> da[i];
    vector<vector<int>> score(h, vector<int>(w, -1));
    score[ch][cw] = 0;
    q.push_back({ch, cw});
    auto in_table = [&](int x, int y) {return 0 <= x && x < h && 0 <= y && y < w;};
    while(!q.empty()) {
        Pii now = q.front(); q.pop_front();
        // cout << now.first MM now.second << '\n';
        rip(i,4,0) {
            int nx = now.first + dx[i], ny = now.second + dy[i];
            // cout << "   " << nx MM ny << endl;
            if(in_table(nx, ny)  && (score[nx][ny] == -1 || score[nx][ny] > score[now.first][now.second]) && da[nx][ny] == '.'){
                score[nx][ny] = score[now.first][now.second];
                q.push_front({nx, ny});
            }
        }
        rip(i,5,0) {
            rip(j, 5,0) {
                int nx = now.first + i - 2, ny = now.second + j - 2;
                if(in_table(nx, ny)  && score[nx][ny] == -1 && da[nx][ny] == '.'){
                    score[nx][ny] = score[now.first][now.second] + 1;
                    q.push_back({nx, ny});
                }
            }
        }
    }
    // vdeb(score);
    cout << score[dh][dw] << '\n';
}

Measured memory_bytes: 9528
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define print(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int n;
	cin>>n;
	vec(int) dp(1<<n,0),a[n];
	loop(i,0,n) loop(j,0,n) 
	{
		int x;
		cin>>x;
		if(x==1) a[i].pb(j);
	}
	dp[0] = 1;
	loop(mask,0,(1<<n) - 1)
	{
		int i = __builtin_popcount(mask);
		for(auto j:a[i])
			if((mask & (1<<j))==0)
				dp[mask + (1<<j)] = (dp[mask + (1<<j)] + dp[mask])%mod;
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;		
}

Measured memory_bytes: 16640
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]

def check(w,h):
    if w+M>N or h+M>N:
        return False
    List=[A[j][w:w+M] for j in range(h,h+M)]
    return (List==B)

ans=0
for i in range(N):
    for k in range(N):
        ans+=check(i,k)

print(['No','Yes'][ans>=1])

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int T, D, ta, tb, da, db;
    cin >> T >> D >> ta >> tb >> da >> db;

    double ans = INF;
    REP( i, 1001 ){
        REP( j, 1001 ){
            double va = da * i;
            double vb = db * j;
            if( va + vb > D || va + vb == 0 ) continue;
            chmin( ans, abs( T - abs( ta * va + tb * vb ) / ( va + vb ) ) );
        }
    }
    printf( "%.10f\n", ans );
}



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

int main(){
	int A = 0;
	string S;
	cin >> S;
	for(int i = 0; i < S.size(); i++){
		if(S.at(i) == '+') A++;
		if(S.at(i) == '-') A--;
	}
	cout << A << endl;
}

Measured memory_bytes: 256
// AOJ 323 ruins
// 2018.2.25 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define LIM		30
#define MAX		1000002
#define EPS		1e-8
 
typedef struct { int x, r; long long r2; } T;
T tbl[100002];
int n;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check(double d)
{
	int i;
	double xmin, xmax, xx, d2;

	d2 = d*d;
	xmin = -MAX, xmax = MAX;
	for (i = 0; i < n; i++) {
		if (tbl[i].r < d) return 0;
		xx = sqrt(tbl[i].r2 - d2);
		if (tbl[i].x - xx > xmin) xmin = tbl[i].x - xx;
		if (tbl[i].x + xx < xmax) xmax = tbl[i].x + xx;
		if (xmin > xmax) return 0;
	}
	return 1;
}

//int cmp(T *a, T *b) { if (a->r - b->r) return a->r - b->r; return a->x - b->x; }

int main()
{
	int i;
	double hi, lo, mi;

	n = in();
	for (i = 0; i < n; i++) {
		tbl[i].x = in(), tbl[i].r = in();
		tbl[i].r2 = (long long)tbl[i].r * tbl[i].r;
	}
	if (i == 1) { printf("%.6lf\n", (double)tbl[0].r); return 0; }

//	qsort(tbl, n, sizeof(T), cmp);
	lo = 0, hi = MAX;
	for (i = 0; i < LIM; i++) {
		mi = 0.5*(lo + hi);
		if (check(mi)) lo = mi; else hi = mi;
	}
	printf("%.6lf\n", lo);
	return 0;
}


Measured memory_bytes: 3336
N, K = gets.chomp.split
Ds = gets.chomp.split
Es = [*'0'..'9'] - Ds
tbl = {}
Es.each { |d| tbl[d] = true }

ms = ''
carry = false
N.reverse.chars do |c|
  c2 = c.dup
  c2.next! if carry
  c2.next! until tbl[c2] || c2.size > 1
  if c2.size == 1
    carry = false
  else
    c2 = Es[0]
    carry = true
  end
  ms = Es[0] * ms.size if c2 != c
  ms += c2
end
if carry
  ms += (Es[0] == '0' ? Es[1] : Es[0])
end

puts ms.reverse


Measured memory_bytes: 1788
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int mo = 1e+9+7;
const int N = 2e+6+3;

LL js[N],inv[N];
int x1,x2,x3,x4,x5,x6,Y1,y2,y3,y4,y5,y6;
int ad[4]={1,1,-1,-1};
struct point{
	int x,y;
	point(const int x_=0,const int y_=0){x=x_;y=y_;}
}a[4],b[4];

LL calc(int x,int y){
	return js[x+y]*inv[x]%mo*inv[y]%mo;
}

LL solve(point a,point b){
	LL cnt=0;
	fo(x,x3,x4)cnt=(cnt+mo-1ll*(x+y3)*calc(x-a.x,y3-1-a.y)%mo*calc(b.x-x,b.y-y3)%mo)%mo;
	fo(y,y3,y4)cnt=(cnt+mo-1ll*(x3+y)*calc(x3-1-a.x,y-a.y)%mo*calc(b.x-x3,b.y-y)%mo)%mo;
	fo(x,x3,x4)cnt=(cnt+1ll*(x+y4+1)*calc(b.x-x,b.y-y4-1)%mo*calc(x-a.x,y4-a.y)%mo)%mo;
	fo(y,y3,y4)cnt=(cnt+1ll*(x4+y+1)*calc(b.x-x4-1,b.y-y)%mo*calc(x4-a.x,y-a.y)%mo)%mo;
	return cnt;
}

int main(){
	x1=get();x2=get();x3=get();x4=get();x5=get();x6=get();
	Y1=get();y2=get();y3=get();y4=get();y5=get();y6=get();
	inv[0]=inv[1]=1;
	fo(i,2,2000000)inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	fo(i,1,2000000)inv[i]=inv[i-1]*inv[i]%mo;
	js[0]=1;
	fo(i,1,2000000)js[i]=js[i-1]*i%mo;
	a[0]=point(x1-1,Y1-1);a[1]=point(x2,y2);a[2]=point(x1-1,y2);a[3]=point(x2,Y1-1);
	b[0]=point(x6+1,y6+1);b[1]=point(x5,y5);b[2]=point(x6+1,y5);b[3]=point(x5,y6+1);
	LL ans=0;
	fo(x,0,3)
		fo(y,0,3)
		ans=(ans+mo+solve(a[x],b[y])*ad[x]*ad[y]%mo)%mo;
	printf("%lld\n",ans);
	return 0;
}

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

string S;
int K;
vector<string> T;

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

    for(int i = 1; i <= K; i++) {
        for(int j = 0; j <= (int)S.size() - i; j++) {
            string tmp;
            for(int k = 0; k < i; k++) tmp.push_back(S[j + k]);
            T.push_back(tmp);
        }
    }
    sort(T.begin(), T.end());
    T.resize(unique(T.begin(), T.end()) - T.begin());
    cout << T[K - 1];
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 110000, inf = 2e9;

int n, f[N];
struct node {
    int x, y;
    node(int y = 0) : y(y) {}
    inline bool operator < (const node &a) const {
        return y < a.y;
    }
} seg[N];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    int x, y;
    read(n);
    for (R int i = 1; i <= n; ++i)
        read(x), read(y), seg[i].x = x - y, seg[i].y = x + y;
    seg[0].y = -inf;
    sort(seg + 1, seg + 1 + n);
    for (R int i = 1; i <= n; ++i) {
        int k = upper_bound(seg, seg + 1 + n, node(seg[i].x)) - seg - 1;
        f[i] = max(f[i - 1], f[k] + 1);
    }
    printf("%d\n", f[n]);
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
int main(){
	int a,b,c;
	while(1){
		scanf("%d %d %d",&a,&b,&c);
		if(a==-1&&b==-1&&c==-1)	break;
		else if(a==-1||b==-1)	printf("F\n");
		else if((a+b)>=80)	printf("A\n");
		else if((a+b)>=65)	printf("B\n");
		else if((a+b)>=50)	printf("C\n");
		else if((a+b)>=30){
			if(c>=50){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		else{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2564
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        long N;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextLong();
        }
        long E = 1000_000_007;
        long result = 1;
        for (int i = 1; i <= N; i++) {
            result = (result * i) % E;
        }

        System.out.println(result);

    }

}


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

int n;
int a[100000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
}

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

int main() {
  int n, x, l;
  cin >> n;
  vector<P> xl;
  rep(i, n) {
    cin >> x >> l;
    xl.emplace_back(x + l, x - l);
  }
  sort(xl.begin(), xl.end());

  int cnt = 0, p = -1001001001;
  for (auto a : xl) {
    if (p <= a.second) {
      cnt++;
      p = a.first;
    }
  }
  cout << cnt << endl;

  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n;
int c[maxn];
vector<int> g[maxn];
int siz[maxn];


ll ans[maxn];

void dfs(int at, int p, map<ll,ll>& mp) {
    siz[at]=1;
    int C = c[at];
    for (int to: g[at]) {
	if (to == p) continue;
	map<ll,ll> mp_to;
	dfs(to, at, mp_to);
	siz[at]+=siz[to];
	ll middle = siz[to]-mp_to[C];
	ans[C] -= (middle*(middle+1)/2);
	if (mp.size() < mp_to.size()) {
	    swap(mp, mp_to);
	}
	for (auto pr: mp_to) {
	    mp[pr.first] += pr.second;
	}
    }
    
    mp[C] = siz[at];
}

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

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

    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    for (int i=1; i<=n; i++) {
	ans[i]=1ll*n*(n+1)/2;
    }

    map<ll,ll> mp;
    dfs(1,0,mp);

    for (int i=1; i<=n; i++) {
	ll top = n-mp[i];
	ans[i] -= (top*(top+1)/2);
    }

    for (int i=1; i<=n; i++) {
	cout<<ans[i]<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 92584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define test int t; cin>>t; while(t--)


int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
        if(n%i==0)
        {
            int d=n/i;
            if(d<=9)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3596
import sys

readline = sys.stdin.readline
h, w, k = map(int, readline().split())
s = [readline().rstrip() for _ in range(h)]
ans = [[0] * w for _ in range(h)]
peace = 1
not_strawberry = []
for i in range(h):
    strawberry = 0
    for j in range(w):
        if s[i][j] == '#':
            if strawberry == 1:
                peace += 1
                strawberry = 1
            else:
                strawberry = 1
        ans[i][j] = str(peace)
    if not strawberry:
        not_strawberry.append(i)
    else:
        for j in not_strawberry:
            ans[j] = ans[i]
        not_strawberry = []
        peace += 1
if not_strawberry:
    i = min(not_strawberry) - 1
    for j in not_strawberry:
        ans[j] = ans[i]

print('\n'.join(' '.join(i) for i in ans))


Measured memory_bytes: 10476
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.TreeMap;

public class Main {

    private int n;
    private TreeMap<Integer,Integer> a;
    
    public static void main(String[] args) {
	Main m = new Main();
	m.solve();
    }

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    n = Integer.parseInt(br.readLine());
	    a = new TreeMap<>();
	    for (String str : br.readLine().split(" ")) {
		int ai = Integer.parseInt(str);
		int num = a.getOrDefault(ai,0) + 1;
		a.put(ai,num);
	    }
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    private void solve() {
	set();
	int pair = 0;
	while (!a.isEmpty()) {
	    int ai = a.lastKey();
	    int complement = 2*Integer.highestOneBit(ai) - ai;
	    if (ai == complement) {
		int num = a.get(ai);
		pair += num/2;
		a.remove(ai);
		continue;
	    }
	    if (a.containsKey(complement)) {
		int numA = a.get(ai);
		int numC = a.get(complement);
		if (numA < numC) {
		    pair += numA;
		    a.remove(ai);
		    a.put(complement,numC-numA);
		} else {
		    pair += numC;
		    a.remove(ai);
		    a.remove(complement);
		}
		continue;
	    }
	    a.remove(ai);
	}
	System.out.println(pair);
    }
}

Measured memory_bytes: 63056
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll t; cin >> t;
	vector<ll> v;
	vector<ll> vv;
	v.push_back(1);
	ll a=1;
	for(int i=0;;i++){
		vv.push_back(a);
		a*=3;
		ll k=0;
		for(ll p:vv){
			k+=p*2;
		}
		k+=a;
		if(k<=t){
			v.push_back(k);
		}
		else{
			break;
		}
	}
	ll ans=1e18;
	for(int i=0;i<v.size();i++){
		ll cnt=2*(i+1)-1;
		ll cp=t;
		cp-=v[i];
		for(int j=i;j>=0;j--){
			cnt+=cp/vv[j];
			cp%=vv[j];
		}
		ans=min(ans,cnt);
	}
	vector<ll> f;
	vector<ll> ff;
	f.push_back(0);
	a=1;
	for(int i=0;;i++){
		ff.push_back(a);
		a*=3;
		ll k=0;
		for(ll p:ff){
			k+=p*2;
		}
		k+=a;
		k--;
		if(k<=t){
			f.push_back(k);
		}
		else{
			break;
		}
	}
	for(int i=0;i<f.size();i++){
		ll cnt=2*(i+1)-2;
		ll cp=t;
		cp-=f[i];
		for(int j=i;j>=0;j--){
			cnt+=cp/ff[j];
			cp%=ff[j];
		}
		ans=min(ans,cnt);
	}
	cout << ans << endl;
} 


Measured memory_bytes: 3204
(defun p4 (a) ( if (= a 22 )  "Christmas Eve Eve Eve" a))
(defun p3 (a) ( if (= a 23 )  "Christmas Eve Eve" (p4 a) ))
(defun p2 (a) ( if (= a 24 )  "Christmas Eve" (p3 a) ))
(defun p (a) ( if (= a 25 )  "Christmas" (p2 a) ))
(
   format t "~A~%" ( p(read) ) 
        ) 

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

int H ;
int A[250];

//node 1: key = 7, left key = 8, right key = 1,
void print(int i) {
    int l, r, p;
    l = 2 * i;
    r = 2 * i + 1;
    p = i / 2;
    cout << "node " << i << ": key = " << A[i];
    if (p) {
        cout << ", parent key = " << A[p];
    }
    if (l <= H) {
       cout  << ", left key = "  << A[l];
    }
    if (r <= H) {
        cout << ", right key = " << A[r];
    }
    cout << ", " << endl;
}

int main() {
    cin >> H;
    for (int i = 1; i <= H; ++i) {
        cin >> A[i];
    }

    for (int j = 1; j <= H; ++j) {
        print(j);
    }

    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
 
int main(){
    long long N, K;

    cin >> N >> K;

    if( N % K == 0){
        cout << 0 << endl;
    }
    else if( abs(K - N) < N){
        cout << min( K - abs(N % K), abs(N%K) ) << endl;
    }
    else {
        cout << N << endl;
    }
}

Measured memory_bytes: 256
#include <string>
#include <iostream>

using namespace std;

int main(void) {
	int k; cin >> k;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		string s = to_string(i);
		if (s.size() % 2 != 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(H)]

L = [[] for i in range(H * W + 1)]
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i + 1, j + 1]
        
d = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
    d[i] = d[i - D] + abs(L[i][0] - L[i - D][0]) + abs(L[i][1] - L[i - D][1])

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(d[r] - d[l])

Measured memory_bytes: 21084
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
    chutiyaap;
    ll n;cin>>n;
    ll res=0;
    for(ll i=1;i<=n;i++)
    {
    	if(i%3&&i%5)res+=i;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std ;
typedef long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)

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

	string S;
	cin >> S;

	if (S.size() == 2)
	{
		cout << S << endl;
	}
	else if (S.size() == 3)
	{
		reverse(S.begin(), S.end());
		cout << S << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;

typedef db T;
const db eps = 1e-9 , pi = acosl(-1.);
int sgn(T x){return (x>eps)-(x<-eps);}
struct P{
  T x,y; P(){} P(T x,T y):x(x),y(y){}
  P operator - (const P&b) const {return P(x-b.x,y-b.y);}
  P operator + (const P&b) const {return P(x+b.x,y+b.y);}
  T operator * (const P&b) const {return x*b.x+y*b.y;}
  T operator / (const P&b) const {return x*b.y-y*b.x;}
  P operator * (const T&k) const {return P(x*k,y*k);}
  P operator / (const T&k) const {return P(x/k,y/k);}
};
T norm(P a){return a*a;}
T abs(P a) {return sqrtl(norm(a));}
P proj(P p,P a,P b){return (b-a)*((p-a)*(b-a)/norm(b-a))+a;}
P reflect(P p,P a,P b){return proj(p,a,b)*2-p;}
T cross(P o,P a,P b){return (a-o)/(b-o);}
int crossOp(P o,P a,P b){return sgn(cross(o,a,b));}
bool onPS(P p,P s,P t){return sgn((t-s)/(p-s))==0&&sgn((p-s)*(p-t))<=0;}
struct L{ P s,t;L(){} L(P s,P t):s(s),t(t){}};
P insLL(L a,L b){ // line x line
  P s = a.s - b.s , v = a.t - a.s , w = b.t - b.s;
  db k1 = s / w , k2 = w / v;
  if(sgn(k2) == 0) return abs(b.s - a.s) < abs(b.t - a.s) ? b.s : b.t;
  return a.s + v * (k1 / k2);
}
bool isSS(L a,L b){ // seg x seg , replace x->y to accelerate
  T c1=(a.t-a.s)/(b.s-a.s),c2=(a.t-a.s)/(b.t-a.s);
  T c3=(b.t-b.s)/(a.s-b.s),c4=(b.t-b.s)/(a.t-b.s);
  return sgn(c1) * sgn(c2) <= 0 && sgn(c3) * sgn(c4) <= 0 &&
    sgn(max(a.s.x,a.t.x) - min(b.s.x,b.t.x)) >= 0 &&
    sgn(max(b.s.x,b.t.x) - min(a.s.x,a.t.x)) >= 0 &&
    sgn(max(a.s.y,a.t.y) - min(b.s.y,b.t.y)) >= 0 &&
    sgn(max(b.s.y,b.t.y) - min(a.s.y,a.t.y)) >= 0;
}
db disPL(P p,L a){return fabs((a.t-a.s)/(p-a.s)) / abs(a.t-a.s);}
db disPS(P p,L a){ // p x seg dis
  if(sgn((a.t-a.s)*(p-a.s)) == -1) return abs(p-a.s);
  if(sgn((a.s-a.t)*(p-a.t)) == -1) return abs(p-a.t);
  return disPL(p,a);
}
db disSS(L a,L b){ // seg x seg dis
  if(isSS(a,b)) return 0;
  return min(min(disPS(a.s,b),disPS(a.t,b)),min(disPS(b.s,a),disPS(b.t,a)));
}

P a, b, c, d;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	int q;
	cin >> q;
	cout << setiosflags(ios::fixed);
	cout << setprecision(10);
	while(q--) {
		cin >> a.x >> a.y >> b.x >> b.y;
		cin >> c.x >> c.y >> d.x >> d.y;
		L x = L(a, b), y = L(c, d);
		cout << disSS(x, y) << endl;
	}
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct data{
	int a,b;
};
int n,m;
data s[100010];
bool cmp(data x,data y)
{
	if(x.a<y.a)
		return true;
	else
		return false;	
}
priority_queue<int> pq;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i].a>>s[i].b;
	sort(s,s+n,cmp);	
	long long k=0,ans=0;
	for(int i=1;i<=m;i++)
	{
		while(s[k].a==i)
		{
			pq.push(s[k].b);
			k++;
		}
		if(pq.size()!=0)
		{
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,m,x,a,i;
  cin >> n >> m >> x;
  for (i=0;i<m;i++){
    cin >> a;
    if (a>x) break;
  }
  cout << min(i,m-i) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 1e6 + 100;

int n, a[N], m;
string s, t;
int divisors[N];
int in[N];

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}


int32_t main(){_
   
   cin >> n;

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

   for (int i = 1; i <= 1e6+10; ++i)
   {
      for (int j = i; j <= 1e6 + 10; j+=i)
      {
         divisors[j] += in[i];
      }
   }

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      if (divisors[a[i]] == 1){
         ans++;
      }
   }

   cout<<ans;
   

   return 0;
}

Measured memory_bytes: 12256
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100 + 5, MAX_W = 100 * 1000 + 10;
long long n, total_w, w[MAX_N], v[MAX_N], dp[MAX_N][MAX_W];

void read_input() {
	cin >> n >> total_w;
	for (int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];
}

void solve() {
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= total_w; j++) {
			dp[i][j] = dp[i - 1][j];
			if (w[i] <= j)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
		}
}

void print_output() {
	cout << dp[n][total_w];
}

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


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l.at(i);
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      ans += lower_bound(l.begin() + j + 1, l.end(), l.at(i) + l.at(j))
        - l.begin() - j - 1;
    }
  }
  cout << ans << endl;
}


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

/* define const */
const int M = 10000;
/* finish defineing const */

int n, ma, mb;
int a[50];
int b[50];
int c[50];

int dp[50][500][500];

int main()
{
    for (int i = 0; i < 50; i++)
    {
        for (int j = 0; j < 500; j++)
        {
            for (int k = 0; k < 500; k++)
            {
                if (j == 0 && k == 0)
                    dp[i][j][k] = 0;
                else
                    dp[i][j][k] = M;
            }
        }
    }
    dp[0][0][0] = 0;
    // make table

    cin >> n >> ma >> mb;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i] >> c[i];
    // input

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 500; j++)
        {
            for (int k = 0; k < 500; k++)
            {
                // i番目を加えることができる
                if (j >= a[i] && k >= b[i])
                {
                    int t1 = dp[i - 1][j][k];
                    int t2 = dp[i - 1][j - a[i]][k - b[i]] + c[i];
                    // if (t2 < t1)
                    // cout << t2 << j << k << endl;
                    dp[i][j][k] = min(t1, t2);
                }
                else
                {
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }

    int mn = M;
    for (int i = 1; ma * i < 500 && mb * i < 500; i++)
    {
        mn = min(dp[n][ma * i][mb * i], mn);
    }
    if (mn == M)
        cout << "-1" << endl;
    else
        cout << mn << endl;
}


Measured memory_bytes: 49024
/*****************************************************

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

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ip pair<int, int>

#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 2e5+7;
const ll inf = 1e17;

int pwr(int x, int y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r % MOD;
}

int inv(int x)
{
    return pow(x, MOD-2);
}

void solve()
{
    int n, l; cin>>n>>l;
    int a[n+1];
    for(int i=1;i<=n;i++)
        a[i] = l+i-1;
    int s = accumulate(a+1, a+n+1, 0);
    int ans = s-a[1];
    int dif = abs(s-ans);
    for(int i=2;i<=n;i++)
    {
        int x = s-a[i];
        if(abs(s-x)<dif)
        {
            dif = abs(s-x);
            ans =x;
        }
    }
    cout<<ans;
}

signed main()
{
    fast;

    int t=1;
    // cin >>t;
    while(t--){
        solve();
    }
    return 0;
}

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


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

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

class MainClass
{
    static void Main()
    {
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        int N = NK[0];
        int K = NK[1];
        var H = ReadLine().Split().Select(long.Parse).ToArray();

        Array.Sort(H);
        Array.Reverse(H);
        for (int i = 0; i < Min(N,K); i++)
        {
            H[i] = 0;
        }
        WriteLine(H.Sum());
    }
}


Measured memory_bytes: 47760
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // purple_bro
    int n;

    scanf("%d", &n);

    int mi = inf;
    int sum = 0;

    for (int i = 1; i <= n; i++) {
        int u;
        scanf("%d", &u);
        sum += u;
        if (u % 10)
            mi = min(mi, u);
    }

    if (sum % 10)
        printf("%d\n", sum);
    else {
        if (mi == inf)
            puts("0");
        else
            printf("%d\n", sum - mi);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << "0.50000000" << endl;
	}
	else {
		int num = n / 2 + 1;
		printf("%lf\n", (double)num / n);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a[5];
    
    int x;
    
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>x;
    
    int ct=0;
    for(int i=0;i<4;i++){
        for(int j=i+1;j<5;j++){
            if(abs(a[i] - a[j]) > x){
                ct++;
                break;
            }
        }
    }
    
    if(ct > 0) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    
    return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define acpy(y, x) memcpy(y, x, sizeof(y))
#define y1 adjf
#define tm afhdhn

int n;
int a[55];
int p;

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	scanf("%d%d", &n, &p);
	int cnt[2] = {0, 0};
	F(i, 0, n){
		scanf("%d", &a[i]);
		cnt[a[i]%2]++;
	}
	if(p == 0){
		lint pw2 = 1ll;
		F(i, 0, cnt[0])pw2<<=1;
		lint dp[55];
		fi0(dp);
		dp[0] = 1;
		lint tmp[55];
		F(i, 0, cnt[1]){
			fi0(tmp);
			F(j, 0, 55){
				tmp[j] = dp[j] + ((j==0) ? 0 : dp[j - 1]);
			}
			acpy(dp, tmp);
		}
		lint kek = 0;
		F(i, 0, 55)if(i%2==0)kek += dp[i];
		printf("%lld", pw2 * kek);
	}
	else{
		lint pw2 = 1ll;
		F(i, 0, cnt[0])pw2<<=1;	
		lint dp[55];
		fi0(dp);
		dp[0] = 1;
		lint tmp[55];
		F(i, 0, cnt[1]){
			fi0(tmp);
			F(j, 0, 55){
				tmp[j] = dp[j] + ((j==0) ? 0 : dp[j - 1]);
			}
			acpy(dp, tmp);
		}
		lint kek = 0;
		F(i, 0, 55)if(i%2==1)kek += dp[i];
		printf("%lld", kek * pw2);
	}
	ret 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();

        while (input > 1000) {
            input -= 1000;
        }
      
        if (input == 0)
            System.out.println(0);
        else {
            int res = 1000-input;
            System.out.println(res);
        }
    }
}


Measured memory_bytes: 26772
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef long long ll;
struct edge { int to; int cost;};
int dgt(int a) {
	if (!a)return 0;
	return 1 + dgt(a / 10);
}
signed main() {
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (dgt(i) & 1)cnt++;
	}cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double X = long.Parse(Console.ReadLine());
            double deposit = 100;
            int cnt = 0;
            while(Math.Floor(deposit * 1.01) < X)
            {
                deposit = Math.Floor(deposit* 1.01);
                cnt++;
            }
            Console.WriteLine(cnt +1);
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


Measured memory_bytes: 27552
#include <stdio.h>
#include <math.h>

typedef struct {
	double x;
	double y;
} Point;

void InputPoint(Point* p);
double Distance(Point p1, Point p2);

int main(void) {
	Point p1;
	Point p2;
	double res;

	InputPoint(&p1);
	InputPoint(&p2);

	res = Distance(p1, p2);

	printf("%lf\n", res);
}

void InputPoint(Point* p) {
	double px;
	double py;
	scanf("%lf %lf", &px, &py);

	p->x = px;
	p->y = py;
}

double Distance(Point p1, Point p2) {
	double res;

	double xCal = p2.x - p1.x;
	double yCal = p2.y - p1.y;

	xCal *= xCal;
	yCal *= yCal;

	res = sqrt(xCal + yCal);

	return res;
}


Measured memory_bytes: 2052
#!/usr/bin/env python3

X, Y = [int(s) for s in input().split()]

if Y % 2 != 0:
    print('No')
    exit()

low = Y // 4 + (Y % 4 != 0)
high = Y // 2

if low <= X <= high:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n; ll k;
    cin >> n >> k;
    vector<ll> a;
    rep(i, n){ ll tmp; cin >> tmp; a.push_back(tmp);}

    const int maxbit = 42;
    vector<int> bit(maxbit);
    vector<int> biton(maxbit, 0);
    rep(i, n){
        ll tmp = a[i];
        int itr = 0;
        while(tmp != 0 && itr < maxbit){
            bit[itr] += tmp&1ll;
            tmp >>= 1;
            itr++;
        }
    }

    
    rep(i, maxbit){
        if (bit[i] <= ((n+1)/2) - 1){
            biton[i] = 1;
        } 
    }

    ll ans = 0;
    for (int i = maxbit-1; i >= 0; i--)
    {
        if (biton[i] == 1 && ans+(1ll<<i) <= k) ans += 1ll<<i;
    }
    
    //cout << ans << endl;

    ll sum = 0;
    rep(i, n) sum += ans^a[i];
    cout << sum << endl;

}



Measured memory_bytes: 4300
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
struct _pair{
	lint x,y;
};

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

_pair solve(int n,int m){
	if((n&1)==0||(m&1)==0){
		lint res=(lint)n*m>>1;
		return (_pair){res,res};
	}
	if(n>m) std::swap(n,m);
	return (_pair){(lint)n*(m>>1),(lint)n*((m+1)>>1)};
}

int solve3(const int n,const int m){
	lint ans=std::min(n,m);
	for(int i=1; i<=std::max(1,n/3*2); ++i){
		_pair res1=solve(n-i,m);
		apn(ans,std::max((lint)i*m,res1.y)-std::min((lint)i*m,res1.x));
	}
	return ans;
}

int main(){
	int n=nxi(),m=nxi();
	if(n%3==0||m%3==0){
		puts("0");
		return 0;
	}
	int ans=std::min(n,m);
	apn(ans,solve3(n,m));
	apn(ans,solve3(m,n));
	printf("%d\n",ans);
}


Measured memory_bytes: 256
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

import sys
from collections import deque

moves = ((1, 0), (0, 1), (-1, 0), (0, -1))
H, W = fetch_int_input()
maze = [list(fetch_one_line()) for _ in range(H)]
X, Y = 0, 1
STARTS = (0, 0)
GOALS = (H - 1, W - 1)


def count_wall(maze, wall="#"):
    wall_num = 0
    for one_line in maze:
        wall_num += "".join(one_line).count(wall)
    return wall_num

def bfs():
    que = deque()
    d = [[sys.maxsize for _ in range(W)] for _ in range(H)]
    que.append(STARTS)
    d[STARTS[X]][STARTS[Y]] = 0

    while que:
        now_pos = que.popleft()
        if now_pos == GOALS:
            break
        for move in moves:
            np = (now_pos[X] + move[X], now_pos[Y] + move[Y])
            if np[X] >= 0 and np[Y] >= 0 and np[X] < H and np[Y] < W and maze[np[X]][np[Y]] == '.' and d[np[X]][np[Y]] == sys.maxsize:
                que.append(np)
                d[np[X]][np[Y]] = d[now_pos[X]][now_pos[Y]] + 1

    return d[GOALS[X]][GOALS[Y]]

min_distance = bfs()
if min_distance == sys.maxsize:
    changable_num = -1
else:
    wall_num = count_wall(maze, "#")
    changable_num = H * W - 2 - (min_distance - 1) - wall_num
print(changable_num)


Measured memory_bytes: 40816
s = input()
t = input()

d = {}
ans = True
for i, v in enumerate(s):
    if v not in d:
        if t[i] in d.values():
            ans = False
            break
        else:
            d[v] = t[i]
    else:
        if d[v] != t[i]:
            ans = False
            break
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9384
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()
A = [MAP() for _ in range(M)]

A.sort(reverse=True)

B = [0] * N
B[0] = 1

for a in A:
	f = a[0]-1
	t = a[1]-1
	if f == 0:
		B[t] = 1

for a in A:
	f = a[0]-1
	t = a[1]-1
	if B[f] == 1:
		B[t] = 2

#print(B)
print("POSSIBLE" if B[-1] else "IMPOSSIBLE")

Measured memory_bytes: 76508
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;

int main()
{
    int i, n, l, sum=0;
    scanf("%d%d",&n,&l);
    int min=MOD;
    for(i=0; i<n; i++) {
        sum += (l+i);
        if(abs(min) > abs(l+i)) {
            min = l+i;
        }
    }
    printf("%d",sum-min);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;
	double C;
	C = (double)B / (double)A;
	if(C == int(C)){
		cout<<A+B<<endl;
	}else{
		cout<<B-A<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

string s,t;
void solve(){
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < (int)s.length(); i++){
        if(s[i] != t[i]) ans++;
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    string s;
    int n;
    cin >> n >> s;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] + n > 'z' || s[i] + n > 'Z')cout << char(s[i] - 26 + n);
        else cout << char(s[i] + n);

    }
    cout << endl;

}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> d(N + 1, 0);
    int l;
    for (int i = 0; i < N; i++) {
        cin >> l;
        d[i + 1] = d[i] + l;
    }
    int ans = 0;
    for (int i = 0; i < N + 1; i++) {
        if (d[i] > X) break;
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256