akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;
using ll = int64_t;

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

    vector<int> A(N);

    REP (i, N) cin >> A[i];

    vector<int> B(N);

    REP (i, N) cin >> B[i];

    int amax = *ALL (max_element, A);

    int bmax = *ALL (max_element, B);

    int abmax = amax + bmax;

    int t = 1 << 1;

    int ans = 0;

    vector<int> digit[2];

    while ((t >> 1) <= abmax)
    {
        digit[0].clear();
        digit[1].clear();

        int log2t = (int)log2(t >> 1);

        // 自分のビットが 0 か 1 かで振り分け
        REP (ix, N) digit[(A[ix] >> log2t) & 1].push_back(A[ix]);

        int tix = 0;

        // 自分のビット以下は昇順になる
        REP (ix, (signed)digit[0].size()) A[tix++] = digit[0][ix];
        REP (ix, (signed)digit[1].size()) A[tix++] = digit[1][ix];

        digit[0].clear();
        digit[1].clear();

        REP (ix, N) digit[(B[ix] >> log2t) & 1].push_back(B[ix]);

        tix = 0;

        REP (ix, (signed)digit[0].size()) B[tix++] = digit[0][ix];
        REP (ix, (signed)digit[1].size()) B[tix++] = digit[1][ix];

        int mask = t - 1;

        ll cntsum = 0;

        int K1 = t >> 1;

        int K2 = t;

        int K3 = K1 + K2;

        // 0-indexed
        int N1 = N - 1;

        int x1 = 0;
        int x2 = 0;
        int x3 = 0;

        // A 降順 B 昇順で見ていく
        // A が小さくなるたびに B は前よりも大きくなる

        // 0-indexed
        for (int i = N1; 0 <= i; i--)
        {
            while ((x1 <= N1) && (((A[i] & mask) + (B[x1] & mask)) < K1)) x1++;
            while ((x2 <= N1) && (((A[i] & mask) + (B[x2] & mask)) < K2)) x2++;
            while ((x3 <= N1) && (((A[i] & mask) + (B[x3] & mask)) < K3)) x3++;

            // 区間1 と 区間 2 を足す
            // 区間 1 [K1, K2)  … x2 - x1
            // 区間 2 [K3, K4) … N - x3;
            cntsum += N - x1 + x2 - x3;
        }

        // 排他的論理和
        if (cntsum % 2 == 1) ans += K1;

        t <<= 1;
    }

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


Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef enum {
    FALSE = 0,
    TRUE = 1
} BOOL;

BOOL IsPrimeNumber(int no) {
    if (no == 1) {
        return FALSE;
    }
    
    if (no == 2 || no == 3) {
        return TRUE;
    }

    if (!(no & 1)) {
        return FALSE;
    }

    int max = (int)sqrt(no) + 1;
    for (int i = 1; i < max / 2; ++i) {
        if (no % (i * 2 + 1) == 0) {
            return FALSE;
        }
    }
    
    return TRUE;
}

int main(void) {
    int num;
    int count = 0;
    
    fscanf(stdin, "%d", &num);
    
    for (int i = 0; i < num; ++i) {
        int no;
        
        fscanf(stdin, "%d", &no);
        
        if (IsPrimeNumber(no)) {
            count += 1;
        }
    }
    
    printf("%d\n", count);
}


Measured memory_bytes: 2040
#include<map>
#include<set>
#include<queue>
#include<ctime>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN (10+50)
#define LL long long

using namespace std;
inline LL read(){
    LL x=0,f=1; char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=ch-'0'+x*10;
    return x*f;
}

LL a,b;

int main(){
    a=read(),b=read();
    if(a<b)printf("%lld",a);
    else if(a%b==0)printf("-1");
    else printf("%lld",a*b-a);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int aa, bb;
int rd() {
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
int n, m, s[4], c[6];
inline void work() {
  n = rd();
  m = rd();
  for(reg int i = 1; i <= m; ++i) {
    s[i] = rd();
    c[i] = rd();
  }
  for(reg int i = 0; i <= 1000; ++i) {
    string ss = to_string(i);
    if(SZ(ss) != n)
      continue;
    bool ok = 1;
    for(reg int i = 1; i <= m; ++i)
      if(ss[s[i] - 1] != c[i] + '0') {
        ok = 0;
        break;
      }
    if(ok) {
      printf("%d\n", i);
      return;
    }
  }
  printf("-1\n");
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 256
def sieve(N):
    global table,prime
    table = [True]*(N+1)
    table[0] = False
    table[1] = False
    prime = []
    for i in range(2,N+1):
        if table[i]:
            prime.append(i)
            for j in range(2*i,N+1,i):
                table[j] = False

def accmulate(array):
    global cs
    cs = [0]*(len(array)+1)
    for i in range(len(array)):
        cs[i+1] = cs[i] + array[i]

def query(l,r):
    return cs[r+1] - cs[l]

Q = int(input())

sieve(10**5)

def judge(x):
    return x % 2 and table[x] and table[(x+1)//2]

flag = [judge(x) for x in range(0,10**5+1)]

accmulate(flag)

ans_list = []

for _ in range(Q):
    l,r = map(int,input().split())
    ans = query(l,r+1)
    ans_list.append(ans)

print(*ans_list, sep="\n")

Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
const int INF = 1e9;
//a1+a2+.....+an = M,d = GCD(a1,a2,...,an)とするとdはMの約数
//ai>=dなのでN*d<=Mを満たす
vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}

int main(){
    ll N,M;
    cin >> N >> M;
    ll res = 0;
    vector<ll> div = divisor(M);  
    for(auto d:div){
        if(d*N <= M)res = max(res,d);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int a=sc.nextInt();
		double p=3.141592653589793;
		System.out.println(2*a*p);
		//String S=sc.next();
		//int v[]=new int[a];
		
		
		 
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct EdmondsKarp{
    struct edge{
        int to,cap,rev;
        edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
    };

    const int INF=1001001001;
    vector<vector<edge>>G;
    vector<int>used,prevv,preve;
    EdmondsKarp(int v):G(v),used(v),prevv(v),preve(v){}

    void addEdge(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        G[to].push_back(edge(from,0,G[from].size()-1));
    }

    int maxFlow(int s,int t){
        int flow=0;
        while(true){
            fill(used.begin(),used.end(),0);

            queue<int>que;
            que.push(s);
            used[s]=true;

            while(que.size()){
                int v=que.front();
                que.pop();

                for(int i=0;i<G[v].size();i++){
                    edge &e=G[v][i];
                    if(used[e.to]||e.cap==0)continue;
                    used[e.to]=true;
                    prevv[e.to]=v;
                    preve[e.to]=i;
                    que.push(e.to);
                }
            }


            if(!used[t])return flow;
            int f=INF;

            for(int v=t;v!=s;v=prevv[v])f=min(f,G[prevv[v]][preve[v]].cap);

            flow+=f;
            for(int v=t;v!=s;v=prevv[v]){
                edge &e=G[prevv[v]][preve[v]];
                e.cap-=f;
                G[e.to][e.rev].cap+=f;
            }
        }
    }
};

int H,W;
char fld[111][111];

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    EdmondsKarp latte(500);
    int S=498,T=499;

    int beet=100000;
    rep(i,H)rep(j,W){
        if(fld[i][j]=='.')continue;
        if(fld[i][j]=='o'){
            latte.addEdge(i,j+H,1);
            latte.addEdge(j+H,i,1);
        }
        if(fld[i][j]=='S'){
            latte.addEdge(i,j+H,beet);
            latte.addEdge(j+H,i,beet);
            latte.addEdge(S,i,beet);
        }
        if(fld[i][j]=='T'){
            latte.addEdge(i,j+H,beet);
            latte.addEdge(j+H,i,beet);
            latte.addEdge(i,T,beet);
        }
    }

    int ei=latte.maxFlow(S,T);
    if(ei>=beet){
        cout<<-1<<endl;
    }
    else{
        cout<<ei<<endl;
    }
    return 0;
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector < set<int> > a(n);
 int d, e;
for (int i = 0; i < m; ++i){
	cin >> d >> e;
	a[d-1].insert(e);
}
if (n == 1 && m == 0){
	cout << 0 << "\n";
	return 0;
}
vector<int> b;
for (int i = 0; i < n; ++i){
	if (i==0){
		if (a[i].empty()){
			b.push_back(1);
		}else if (a[i].size() > 1){
			cout << -1 << "\n";
			return 0;
		}else{
			if(n!= 1 && *a[i].begin() == 0){
				cout << -1 << "\n";
				return 0;
			}else{
			b.push_back(*a[i].begin());
			}
		}
	}else{
		if (a[i].size() > 1){
			cout << -1 << "\n";
			return 0;
		}else if (a[i].empty()){
			b.push_back(0);
		}else{
			b.push_back(*a[i].begin());
		}
	}
}
for (int i : b){
	cout << i;
}
cout << "\n";
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))

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

    int n,k;
    cin>>n>>k;
    ll a[n],dp[n];
    mem(dp);
    f0(n) cin>>a[i];
    for(int t,i=1;i<n;i++)
    {
        ll val=1000000001;
        t=i-1;
        for(int j=0;j<k;j++)
        {
           if(t<0)  break;
           ll tmp=dp[t]+abs(a[i]-a[t]);t--;
           val=min(tmp,val);
        }
        dp[i]=val;
    }
    cout<<dp[n-1];
    return 0;
}



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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 1e5;

int n, k;

int p[MAXN + 5], q[MAXN + 5];

inline void input()
{
	n = read<int>(), k = read<int>();
	for(int i = 1; i <= n; ++i) p[i] = read<int>();
	for(int i = 1; i <= n; ++i) q[i] = read<int>();
}

inline void inv(int *f, int *s)
{
	static int S[MAXN + 5];

	for(int i = 1; i <= n; ++i) S[f[i]] = i;
	for(int i = 1; i <= n; ++i) s[i] = S[i];
}

inline void mul(int *f, int *g, int *s)
{
	static int S[MAXN + 5];

	for(int i = 1; i <= n; ++i) S[i] = f[g[i]];
	for(int i = 1; i <= n; ++i) s[i] = S[i];
}

inline void fpm(int *f, int y, int *s)
{
	if(y == 0) { for(int i = 1; i <= n; ++i) s[i] = i; return; }

	static int S[MAXN + 5], vis[MAXN + 5];
	for(int i = 1; i <= n; ++i) vis[i] = 0;

	for(int i = 1; i <= n; ++i) if(!vis[i])
	{
		static int cir[MAXN + 5], len;
		len = 0;

		for(int j = i; !vis[j]; j = f[j]) vis[j] = 1, cir[len++] = j;
		for(int j = 0; j < len; ++j) S[cir[j]] = cir[(j + y) % len];
	}
	for(int i = 1; i <= n; ++i) s[i] = S[i];
}

inline void solve()
{
	static int A[MAXN + 5], iA[MAXN + 5], ip[MAXN + 5], iq[MAXN + 5], M[7][MAXN + 5];

	inv(p, ip);
	inv(q, iq);
	mul(q, ip, A);
	mul(A, iq, A);
	mul(A, p, A);
	inv(A, iA);

	int m = k % 6 == 0 ? k / 6 - 1 : k / 6, t = k % 6 == 0 ? 6 : k % 6;
	fpm(A, m, A);
	for(int i = 1; i <= n; ++i) M[1][i] = p[i];
	for(int i = 1; i <= n; ++i) M[2][i] = q[i];
	for(int i = 3; i <= 6; ++i)
	{
		static int f[MAXN + 5];

		inv(M[i - 2], f);
		mul(M[i - 1], f, M[i]);
	}
	fpm(iA, m, iA);

	mul(A, M[t], A);
	mul(A, iA, A);

	for(int i = 1; i <= n; ++i) printf("%d ", A[i]);
	puts("");
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
	int n;
	scanf("%d", &n);
	unordered_map<int, int> c;
	for (int i = 1; i <= n; ++ i) {
		int x;
		scanf("%d", &x);
		c[x] ++;
	}
	int remain = n, ans = 0;
	for (int i = n - 1; i >= 0; i -= 2) {
		if (c[i] != min(remain, 2)) {
			ans = -1;
			break;
		}
		if (c[i] > 1) ans ++;
		remain -= 2;
	}
	int A = 0;
	if (ans != -1) {
		A = 1;
		for (int i = 0; i < ans; ++ i) A = (A + A) % MOD;
	}
	cout << A << endl;
}



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

void fun(int A1, int A2, int A3)
{
      if((A1+A2+A3)>=22)
      {
           cout<<"bust";
      }
      else
       cout<<"win";
}
int main()
{
     int A1,A2,A3;
     cin>>A1>>A2>>A3;
    fun(A1,A2,A3);
}

Measured memory_bytes: 3580
n,k = map(int,input().split())
ans = 0

for i in range(n):
    cnt = 0
    dice = i+1
    if(dice>=k):
        res = (n-dice+1)/n
        ans += res
        break
    for j in range(k):
        dice *= 2
        if(dice >= k):
            cnt += 1
            break
        elif(dice < k):
            cnt += 1        
    tmp  = 1/n * (1/2)**cnt

    ans += tmp

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d,m,t;
	map<int,int>dmap,tmap;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>d,dmap[d]++;
	cin>>m;
	while(cin>>t)
		tmap[t]++;
	for(auto x:tmap)
		if(dmap[x.first]<x.second)
			cout<<"NO"<<endl,exit(0);
	cout<<"YES"<<endl;
}


Measured memory_bytes: 18944
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int p, q;
	
	while (cin >> p >> q)
	{
		string str = "";
		vector<int> his;
		his.push_back(p % q);
		
		rep(i, 100)
		{
			p *= 10;
			str += '0' + p / q;
			p %= q;
			
			if (p == 0)
			{
				cout << str << endl;
				break;
			}
			
			if (find(his.begin(), his.end(), p) != his.end())
			{
				int pos = find(his.begin(), his.end(), p) - his.begin();
				cout << str << endl;
				rep(j, pos) cout << " ";
				rep(j, his.size() - pos) cout << "^";
				cout << endl;
				break;
			}
			his.push_back(p);
		}
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1228
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    alice_sum = 0
    bob_sum = 0
    A.sort()
    A.reverse()
    for i in range(N):
        if i % 2 == 0:
            alice_sum += A[i]
        else:
            bob_sum += A[i]
    print(alice_sum - bob_sum)

Measured memory_bytes: 3060
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <cmath>
#include <climits>
#include <queue>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; ++i){
        int a; cin >>vec[i];
        vec[i] -= (i + 1);
    }
    sort(vec.begin(), vec.end());

    int median = vec[n/2];
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        ans += abs(vec[i] - median);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
    int n; cin >> n;
    vector<int>v(n);
    rep(i,n)cin>>v[i];
    sort(v.begin(),v.end());
    double ans =v[0];
    for(int i=1; i<n; i++){
        ans = (ans+v[i])/2;
    }
    printf("%.10f\n",ans);
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  int i=1;
  for(;;){
    if(i>=n) break;
    i*=2;
  }
  if(i>n){cout << i/2 << endl;return 0;}
  cout << i << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << (st.size() == n ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 9600
import collections
s = input()
ss = set(s)
# print(ss)
ans = float('inf')
# cs = collections.Counter(s)
for c in ss:
    cnt = 0
    back = 0
    # print(c)
    for si in s:
        if c != si:
            cnt += 1
        else:
            back = max(back, cnt)
            cnt = 0
    back = max(back, cnt)
    ans = min(ans, back)
    # print(ans, back)
print(ans)
# for i in cs:
#     print(i)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

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

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  ll d, n;
  cin >> d >> n;
  
  ll ans = 0;
  if (d == 0)
  {
      /* code */
      ans = (n != 100) ? n : n+1;
      cout << ans << endl;
      return 0;
  }
  else
  {
      /* code */
      if (d == 1)
      {
          rep(i, n) {
            ans += 100;
          }
          if (n == 100) ans += 100;
      }
      else
      {
          /* code */
          rep(i, n) {
            ans += 10000;
          }
          if (n == 100) ans += 10000;
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>	// require printf
#include <cstring>	// require memset
#include <algorithm>	// require sort next_permutation count max min etc.

using namespace std;

const int INF = 100;
int h,w;
int path[55][55];
int dp[55][55];

int calc (void )
{
	memset (dp, 0, sizeof(dp) );

	dp[0][0] = path[0][0];
	for (int i = 1; i < h; ++i )
		dp[i][0] = dp[i-1][0] + path[i][0];
	
	for (int j = 1; j < w; ++j )
		dp[0][j] = dp[0][j-1] + path[0][j];

	for (int i = 1; i < h; ++i )
	for (int j = 1; j < w; ++j )
		dp[i][j] = min (dp[i-1][j], dp[i][j-1] ) + path[i][j];

	return dp[h-1][w-1];
}

int main(void)
{
	char in[10];
	scanf ("%d %d", &h, &w );

	for (int i = 0; i < 55; ++i )
		for (int j = 0; j < 55; ++j )
			path[i][j] = INF;

	for (int i = 0; i < h; ++i ){
		char str[55];
		scanf ("%s", str );
		for (int j = 0; j < w; ++j )
			path[i][j] = str[j] - '0';
	} // end for

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

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a,b,c;cin>>a>>b>>c;
    if(a==b) cout << c;
    else if(b==c) cout << a;
    else cout << b;
    cout << endl;
    return 0;
}

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

int main(){
  int p = 0;
  int q = 0;
  string S;
  cin >> S;
  bool can = false;
  if(S[0] == 'A'){
    for(int i = 2; i < S.size() - 1; ++i){
      if(S[i] == 'C') ++p;
    }
    if(p == 1){
      for(int i = 0; i < S.size(); ++i){
      if(islower(S[i])) ++q; 
      }
      if(q + 2 == S.size()) cout << "AC" << endl;
      else cout << "WA" << endl;
    }
    else cout << "WA" << endl;
  }
  else cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

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

    int cnt = 0;
    int max_cnt = 0;
    for ( int i = 0; i < s.length(); i++ ) {
        if ( s.substr(i, 1) == "A" )      cnt++;
        else if ( s.substr(i, 1) == "C" ) cnt++;
        else if ( s.substr(i, 1) == "G" ) cnt++;
        else if ( s.substr(i, 1) == "T" ) cnt++;
        else {
            max_cnt = max(max_cnt, cnt);
            cnt = 0;
        }
        if ( i == s.length() - 1 ) {
            max_cnt = max(max_cnt, cnt);
        }
    }

    cout << max_cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#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);
	}

	int sum = 0;
	int maxedge = 0;

	for (int i = 0; i < N; i++) {
		sum = sum + L.at(i);
		if (L.at(i) > maxedge) {
			maxedge = L.at(i);
		}
	}

	int ans = false;
	if (maxedge < (sum - maxedge)) {
		ans = true;
	}

	if (ans) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n =inp[0]
t = []
n.times do
  t.push(inp[0])
end
max2,max = t.sort()[-2,2]
t.each do |d|
  puts (d==max)? max2:max
end


Measured memory_bytes: 7900
a=[list(map(int,input().split())) for _ in range(3)]
if not a[0][0]-a[1][0]==a[0][1]-a[1][1]==a[0][2]-a[1][2]:print("No");exit()
if not a[0][0]-a[2][0]==a[0][1]-a[2][1]==a[0][2]-a[2][2]:print("No");exit()
if not a[0][0]-a[0][1]==a[1][0]-a[1][1]==a[2][0]-a[2][1]:print("No");exit()
if not a[0][0]-a[0][2]==a[1][0]-a[1][2]==a[2][0]-a[2][2]:print("No");exit()
print("Yes")

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

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long ans = -1;
    for(int i = 0; i < (1 << n); i++) {
        long long cost = 0;
        long long hmax = 0;
        int color = 0;
        for(int j = 0; j < n; j++) {
            if(1 & (i >> j)) {
                color++;
                if(a[j] <= hmax) {
                    hmax++;
                    cost += hmax - a[j];
                } else {
                    hmax = a[j];
                }
            } else {
                if(a[j] > hmax) {
                    color++;
                    hmax = a[j];
                }
            }
        }
        if(color >= k) {
            if(ans == -1) {
                ans = cost;
            } else {
                ans = min(ans, cost);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a = list(input())
b = list(input())

ans = []
for i in range(len(a)-1):
  ans.append(a[i])
  ans.append(b[i])
  
if len(a) > len(b):
  ans.append(a[-1])
else:
  ans.append(a[-1])
  ans.append(b[-1])
  
print(''.join(ans))

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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int H, W, N;
int a[10000];
int c[100][100];

int main(int argc, char* argv[])
{
	scanf("%d%d", &H, &W);
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	//for(int i = 0; i < N; i++) printf("%d\n", a[i]);

	int color = 0, cnt = 0;
	for(int i = 0; i < H; i++)
	{
		for(int j_ = 0; j_ < W; j_++)
		{
			int j = j_;
			if(i % 2 != 0) j = W - j_ - 1;
			c[i][j] = color;
			cnt++;
			if(cnt == a[color])
			{
				color++;
				cnt = 0;
			}
		}
	}
	for(int i = 0; i < H; i++)
	{
		for(int j = 0; j < W; j++)
		{
			printf("%d ", c[i][j] + 1);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    VI S(4);
    rep(i,4)cin>>S[i];
    sort(S.begin(),S.end());
    if(S[0]==S[1]&&S[2]==S[3]){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}




Measured memory_bytes: 3104
import heapq
def main():
    k= int(input())
    brdict = {}
    for i in range(1,k):
        if i==k-1:
            if (10*(k-1))%k==0:
                brdict[i]= [(0,0)]
            else:
                brdict[i] = [(0,1)]
        else:
            if i!=(i*10)%k:
                brdict[i] = [((i*10)%k,0)]
            if (i*10)%k!=i+1:
                brdict[i] = brdict.get(i,[])+[(i+1,1)]
    start=1
    cost=[i for i in range(k)]
    cost[0]=k
    fixed=[False]*k
    fixed[start]=True
    akouho = [(1,start)]
    heapq.heapify(akouho)
    while not all(fixed):
        (fcost,fnode) = heapq.heappop(akouho)
        if fnode==0:break
        fixed[fnode]=True
        for br in brdict[fnode]:
            if not fixed[br[0]]:
                if cost[br[0]] > fcost + br[1]:
                    cost[br[0]] = fcost + br[1]
                    heapq.heappush(akouho,(cost[br[0]],br[0]))
        if akouho==[]:break
    print(cost[0])
if __name__ == '__main__':
    main()

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

#define Pi acos(-1.)
#define pb push_back
#define all(x) (x).begin(), x.end()
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 322;
const ll LINF = 2e18 + 474;
const int MAXN  = 2e5 + 228;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll n, H, ans = 0;

vector<pair<ll, ll> > a;

void solve() {
    cin >> n >> H;
    for(int i = 0; i < n; i++) {
        ll x, y; cin >> x >> y;
        a.pb(mp(x, 1LL));
        a.pb(mp(y, 2LL));
    }
    sort(a.rbegin(), a.rend());
    for(int i = 0; i < 2 * n; i++) {
        if(a[i].se == 2) {
            H -= a[i].fi;
            ans++;
        }
        else if(a[i].se == 1) {
            ll x = (H + a[i].fi - 1) / a[i].fi;
            ans += x;
            break;
        }
        if(H <= 0) {
            break;
        }
    }
    cout << ans;
}



int main() {
    if(!standart) {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    while(T--)
        solve();

    return 0;
}


Measured memory_bytes: 6512
// High above the clouds there is a rainbow...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=2010,mod=1e9+7;
const ll inf=1e18;

string s;
vector<int>v[maxn];
int cnt[maxn];
ll dp[maxn],sig[maxn];

void dfs(int u,int par=-1){
    cnt[u]= s[u-1]=='1';
    sig[u]=0;
    for(int y:v[u]){
	if(y!=par){
	    dfs(y,u);
	    cnt[u]+=cnt[y];
	    sig[u]+=sig[y]+cnt[y];
	}
    }
}

void calc(int u,int par=-1){
    int mxy=-1;
    for(int y:v[u]){
	if(y!=par){
	    calc(y,u);
	    if(mxy==-1 || (mxy!=-1 && sig[y]+cnt[y]>sig[mxy]+cnt[y])) mxy=y;
	}
    }
    if(mxy==-1){
	dp[u]=0;
	return;
    }
    ll sm=sig[u]-sig[mxy]-cnt[mxy];////
    if(sm>=dp[mxy]+cnt[mxy]){
	dp[u]=sig[u] & 1;
    }
    else{
	dp[u]=dp[mxy]+cnt[mxy]-sm;
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n>>s;
    for(int i=0;i<n-1;i++){
	int a,b;cin>>a>>b;
	v[a].PB(b);
	v[b].PB(a);
    }
    ll ans=inf;
    for(int i=1;i<=n;i++){
	dfs(i);
	if(sig[i] & 1) continue;
	calc(i);
	if(dp[i]==0) ans=min(ans,sig[i]/2);
    }
    if(ans==inf) ans=-1;
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.


Measured memory_bytes: 512
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
py = [inpl() for i in range(m)]
p = [[] for i in range(n+5)]
res = defaultdict(lambda : defaultdict(int))
for i,j in enumerate(py):
    p[j[0]].append(j[1])
for k,i in enumerate(p):
    i.sort()
    for j,_ in enumerate(i):
        res[k][i[j]] = j+1
for i in py:
    print('{0}{1}'.format(str(i[0]).zfill(6),str(res[i[0]][i[1]]).zfill(6)))

Measured memory_bytes: 125400
s = list(str(input()))

n = len(s)-1
ans = 0
for i in range(2**n):
    temp = ['']*n
    for j in range(n):
        if (i >> j)&1:
            temp[j] = '+'
    t = []
    for k in range(n):
        t.append(s[k])
        t.append(temp[k])
    else:
        t.append(s[-1])
    t = ''.join(t)
    ans += eval(t)
print(ans)


Measured memory_bytes: 73824
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
using namespace std;
int dp[100004][14];
int MOD=1e9+7;
string s;
int main(){
	cin>>s;
	s="0"+s;
	dp[0][0]=1;
	for (int i=1;i<s.size();i++){
		if (s[i]=='?'){
			for (int j=0;j<13;j++)
				for (int k=0;k<10;k++) dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%MOD;
		}else{
			s[i]-='0';
			for (int j=0;j<13;j++)
				dp[i][(j*10+s[i])%13]=(dp[i][(j*10+s[i])%13]+dp[i-1][j])%MOD;
		}
	}
	cout<<dp[s.size()-1][5];
}

Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int n;
int a[100100];

int partition(int p, int r){
  int x = a[r];
  int i = p-1;
  REP(j, p, r){
    if(a[j] <= x) swap(a[++i], a[j]);
  }
  return i;
}


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

  int q = partition(0, n-1);

  rep(i, n){
    if(i) cout << " ";
    if(i == q) cout << "[";
    cout << a[i];
    if(i == q) cout << "]";
  }
  cout << endl;

  return 0;
}






Measured memory_bytes: 3432
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

dp = [[0]*3 for i in range(n+1)]
# dp[i][今回の手]

for i in range(n):
    if t[i] == "r":
        dp[i+1][0] = max(dp[max(i+1-k, 0)][1] + p, dp[i+1][0])
        dp[i+1][0] = max(dp[max(i+1-k, 0)][2] + p, dp[i+1][0])
    if t[i] == "s":
        dp[i+1][1] = max(dp[max(i+1-k, 0)][0] + r, dp[i+1][1])
        dp[i+1][1] = max(dp[max(i+1-k, 0)][2] + r, dp[i+1][1])
    if t[i] == "p":
        dp[i+1][2] = max(dp[max(i+1-k, 0)][0] + s, dp[i+1][2])
        dp[i+1][2] = max(dp[max(i+1-k, 0)][1] + s, dp[i+1][2])
    dp[i+1][0] = max(dp[max(i+1-k, 0)][1], dp[i+1][0])
    dp[i+1][0] = max(dp[max(i+1-k, 0)][2], dp[i+1][0])
    dp[i+1][1] = max(dp[max(i+1-k, 0)][0], dp[i+1][1])
    dp[i+1][1] = max(dp[max(i+1-k, 0)][2], dp[i+1][1])
    dp[i+1][2] = max(dp[max(i+1-k, 0)][0], dp[i+1][2])
    dp[i+1][2] = max(dp[max(i+1-k, 0)][1], dp[i+1][2])

ans = 0
for i in range(k):
    ans += max(dp[n-i])
print(ans)

Measured memory_bytes: 75116
import java.io.*
import java.util.*

fun solve(N: Long, a: LongArray){
    val n = N.toInt()
    val cumSum = a.toList().scanLeft(0L){ a,b -> a+b }.toList()
    (0 until n - 1).map{ Math.abs(2 * cumSum[it] - cumSum.last()) }.min().let{ println(it) }
    return
}

fun <T, R> Iterable<T>.scanLeft(initial: R, operation: (acc: R, T) -> R): Sequence<R> {
    var last = initial
    return this.asSequence().map { last = operation(last, it); last }
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val a = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        a[i] = sc.next().toLong()
    }
    solve(N, a)
}



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

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define pb push_back
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;

using std::cerr;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2005;

int n,ecnt,head[MAXN];
char s[MAXN];

struct Edge{
	int to,nxt;
}e[MAXN<<1];

inline void add_edge(int bg,int ed){
	++ecnt;
	e[ecnt].to=ed;
	e[ecnt].nxt=head[bg];
	head[bg]=ecnt;
}

int f[MAXN],g[MAXN],h[MAXN];

void dfs(int x,int pre){
	f[x]=g[x]=0;
	h[x]=s[x]=='1';
	int maxf=-1,maxpos=0;
	trav(i,x){
		int ver=e[i].to;
		if(ver==pre)continue;
		dfs(ver,x);
		f[ver]+=h[ver];
		if(f[ver]>maxf){
			maxf=f[ver];
			maxpos=ver;
		}
		g[ver]+=h[ver];
		g[x]+=g[ver];
		h[x]+=h[ver];
	}
	int totg=0;
	trav(i,x){
		int ver=e[i].to;
		if(ver==pre||ver==maxpos)continue;
		totg+=g[ver];
	}
	if(totg<maxf)f[x]=maxf-totg;
	else f[x]=(g[x]&1);
}

int main(){
	n=read();
	scanf("%s",s+1);
	rin(i,2,n){
		int u=read(),v=read();
		add_edge(u,v);
		add_edge(v,u);
	}
	int ans=1e9;
	rin(i,1,n){
		dfs(i,0);
		if(!f[i])ans=std::min(ans,g[i]>>1);
	}
	printf("%d\n",ans<1e9?ans:-1);
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(b + c > a) {
        cout << c - (a - b) << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long ll;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = 2*(int)1e5 + 10;

int n, c, h[N], dp[N];

struct Line {
  mutable ll k, m, p;
  bool operator<(const Line& o) const { return k < o.k; }
  bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
  // (for doubles, use inf = 1/.0, div(a,b) = a/b)
  const ll inf = LLONG_MAX;
  ll div(ll a, ll b) { // floored division
    return a / b - ((a ^ b) < 0 && a % b); }
  bool isect(iterator x, iterator y) {
    if (y == end()) { x->p = inf; return false; }
    if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
    else x->p = div(y->m - x->m, x->k - y->k);
    return x->p >= y->p;
  }
  void add(ll k, ll m) {
    auto z = insert({k, m, 0}), y = z++, x = y;
    while (isect(y, z)) z = erase(z);
    if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
    while ((y = x) != begin() && (--x)->p >= y->p)
      isect(x, erase(y));
  }
  ll query(ll x) {
    assert(!empty());
    auto l = *lower_bound(x);
    return l.k * x + l.m;
  }
} bla;

signed main() {
  init_ios();
  cin >> n >> c;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    if (i == 1) {
      bla.add(2*h[i], -h[i]*h[i]);
      continue;
    }
    dp[i] = c+h[i]*h[i]-bla.query(h[i]);
    bla.add(2*h[i], -h[i]*h[i]-dp[i]);
  }
  cout<<dp[n]<<"\n";
}

Measured memory_bytes: 15872
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 string s;
 cin>>s;
 int n = s.size();

 cout<<(s[n-1] != 's'? s+"s":s+"es")<<endl;



 return 0;
}


Measured memory_bytes: 3652
import itertools

N = int(input())
S =[0]*N
for i in range(N):
    S[i] = input()

member = {}
for m in ['M', 'A', 'R', 'C', 'H']:
    member[m] = len(list(filter(lambda x: x[0] == m, S)))

#print(member)

ans = 0
for i, j, k in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans += member[i] * member[j] * member[k]

print(ans)

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

const int N=1e5+5;
int n;
double x;
char s[N];

void init()
{
	int i;double ans=0.0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%lf",&x);
		scanf("%s",s+1);
		if(s[1]=='J') ans+=x;
		else ans+=x*380000;
	}
	printf("%lf\n",ans);
}

int main()
{
	init();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;
int main(void)
{
    int n,num;
    int sum = 0,dig;
    cin >> n;
    num = n;
    while(num){
        dig = num%10;
        sum = sum + dig;
        num = num/10;
    }
    if(n % sum == 0)cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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/gcd(a,b)*b;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll h,n,sum=0;
    cin>>h>>n;
    rep(i,n){
        ll a;
        cin>>a;
        sum+=a;
    }
    cout<<(sum>=h ? "Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <functional>
#include <tuple>
using namespace std;

int digitsum(int pos) {
	string S = to_string(pos);

	int sum = 0;
	for (int i = 0; i < S.size(); i++) {
		sum += (S[i] - '0');
	}
	return sum;
}

int N, maxn = 100000;

int main() {
	cin >> N;
	for (int i = 1; i < N; i++) {
		int v1 = digitsum(i) + digitsum(N - i);
		maxn = min(maxn, v1);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (K, X) = readLine()!!.split(" ").map(String::toInt)
    val min = -1000000
    val max = 1000000

    (Math.max(min, X - (K-1))..Math.min(max, X + (K-1))).joinToString(" ").let(::println)
}

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

int main() {
	int l, r;
	cin >> l >> r;
	if (l / 2019 < r / 2019) {
		cout << 0 << endl;
		return 0;
	}
	int min = 2018;
	for (int i = l % 2019; i < r % 2019; i++) {
		for (int j = i + 1; j <= r % 2019; j++) {
			if (i * j % 2019 < min)
				min = i * j % 2019;
		}
	}
	cout << min << endl;
}


Measured memory_bytes: 256
from fractions import gcd

N,M = map(int,input().split())

A = set(map(int,input().split()))
D = [None,2,5,5,4,5,6,3,7,6]

B = set(D[i] for i in range(1,10) if i in A)


dp = [-1]*(N+1) # dp[i] = # of digits using i matches
dp[0] = 0

for i in range(N+1):
  for d in B:
    if i-d >= 0 and dp[i-d] >= 0:
      dp[i] = max(dp[i],1 + dp[i-d])


res = []

digits = dp[N]
C = sorted(((i,D[i]) for i in range(1,10) if i in A), reverse=True)

i = N

for remaining in reversed(range(digits)):
  for v,d in C:
    if i-d >= 0 and dp[i-d] == remaining:
      res.append(v)
      i -= d
      break

print(*res,sep='')

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

u_int64_t attack(u_int64_t H) {
    if (H == 1) {
        return 1;
    } else {
        return 1 + 2 * attack(H / 2);
    }
}

void Main() {
    // input
    u_int64_t H;
    cin >> H;



    // output
    cout << attack(H) << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3624