akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
 
int main(){
  int n,m;
  int sum=0;
  int count=0;
  scanf("%d%d",&n,&m);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d ",&a[i]);
    sum+=a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]*4*m>=sum)
      count++;
  }
  if(count>=m){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1628
package main

import "fmt"

func main() {
	var n, a, b, blue, rem int
	fmt.Scan(&n, &a, &b)
	blue = n / (a + b) * a
	rem = n % (a + b)
	if rem >= a {
		blue += a
	} else {
		blue += rem
	}
	fmt.Println(blue)
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int x, n, m;
	cin>>n>>m;
	ll sum = 0;
	for(int i = 0; i < m; i++){
		cin>>x;
		sum += x;
	}
	if(sum <= n){
		cout<<n - sum<<endl;
	}else{
		cout<<-1<<endl;
	}

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;


int main(){
	int N;
	cin >> N;
	int tos[3];
	vector<int> L(N);
	rep(i,3)cin >> tos[i];
	rep(i,N)cin >> L[i];
	sort(tos, tos+3);
	int ans = inf;
	do{
		//cout << line << endl;
		//cout << "tos -> ";
		//show(tos);
		vector<int> tl = L;
		int e_ans = 0;
		rep(i,3){
			int to = tos[i];
			int mp_for_one = inf;
			vector<int> e_tl;
			int rest = tl.size();
			
			//残っている中で最適な組み合わせを探す
			for(int bit = 1; bit < (1 << rest); ++bit){
				vector<int> use;
				vector<int> not_use;
				rep(j, rest){
					if(bit & (1 << j)){
						use.push_back(tl[j]);
					}else{
						not_use.push_back(tl[j]);
					}
				}
				int e_mp = 0;
				int now_long = 0;
				e_mp += 10*(use.size()-1);
				for(auto x:use){
					now_long += x;
				}
				e_mp += abs(to - now_long);

				//最小コストのとき入れ替え
				if(e_mp < mp_for_one){
					e_tl = not_use;
					mp_for_one = e_mp;
				}
			}
			e_ans += mp_for_one;
			tl = e_tl;
			//show(tl);
			//printf("|-->[e_ans = %d]\n", e_ans);
		}
		//cout << e_ans << endl << line << endl;
		ans = min(ans, e_ans);
	}while(next_permutation(tos, tos+3));
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vector<char> s(n);
	rep(i, n) cin >> s[i];

	set<char> cs;
	rep(i, n) cs.insert(s[i]);

	if(cs.size() == 3)
		cout << "Three" << endl;
	if(cs.size() == 4)
		cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
rl = [] # RとLの個数
idxes = [] # RとLが切り替わる場所
cnt = 1 # 同じ文字の続く長さ

for i, (a, b) in enumerate(zip(S, S[1:])):
    if a == b: # 隣り合う文字が同じ
        cnt += 1
    else:
        rl.append(cnt)
        cnt = 1
        idxes.append(i)

rl.append(cnt) # 最後の連続する文字数

ans = [0] * len(S)

for i, (r, l) in enumerate(zip(rl[0::2], rl[1::2])):
    j = idxes[i*2] # 一セットのRRRLLLLLの間
    s = (l+r) // 2 # 偶奇が同じかどうかで半分か否かが変わる
    if r % 2 == l % 2:
        ans[j] = ans[j+1] = s # LRの偶奇が同じなので半分ずつ集まる
    elif r % 2 == 1:
        ans[j] = s+1
        ans[j+1] = s
    else:
        ans[j] = s
        ans[j+1] = s+1


print(*ans)


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

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

int N;
int ret;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i+=2) {
		x=0;
		for(y=1;y<=i;y++) if(i%y==0) x++;
		if(x==8) ret++;
	}
	cout<<ret<<endl;
}


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


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);   
	    
	    float A = sc.nextFloat();
	    float B = sc.nextFloat();
	    
	    System.out.println(Math.round((A + B) / 2));
	}    
}

Measured memory_bytes: 22996
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	string s;
	cin >> s;
	ll n = s.size();

	ll ans = n;
	rep(i, n-1){
		if(s[i] != s[i+1]){
			chmin(ans, max(i+1, n-i-1));
		}
	}
	co(ans);

	return 0;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

struct Mo {
    const int width;
    vector<int> ls, rs, ord;
    Mo(int n) : width((int)sqrt(n)) {}

    inline void insert(int l, int r) {
        ls.emplace_back(l);
        rs.emplace_back(r);
    }

    inline void build() {
        ord.resize(ls.size());
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](const int a, const int b) {
            int ablock = ls[a] / width, bblock = ls[b] / width;
            if (ablock != bblock) return ablock < bblock;
            return ablock & 1 ? rs[a] < rs[b] : rs[a] > rs[b];
        });
    }

    // void add(int idx): idx番目の要素を追加
    // void del(int idx): idx番目の要素を削除
    // void calc(int idx); クエリidxを処理
    template<class Add, class Del, class Calc>
    inline void run(const Add& add, const Del& del, const Calc& calc) {
        int nl = 0, nr = 0;
        for (const int idx : ord) {
            while (nl > ls[idx]) add(--nl);
            while (nr < rs[idx]) add(nr++);
            while (nl < ls[idx]) del(nl++);
            while (nr > rs[idx]) del(--nr);
            calc(idx);
        }
    }
};

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

    int n, q;
    cin >> n >> q;

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

    Mo mo(n);

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        --l;
        mo.insert(l, r);
    }
    mo.build();

    vector<int> ans(q);
    vector<int> cnt(n, 0);
    int color = 0;

    auto add = [&](int idx) {
        color += (cnt[c[idx]] == 0);
        ++cnt[c[idx]];
    };

    auto del = [&](int idx) {
        --cnt[c[idx]];
        color -= (cnt[c[idx]] == 0);
    };

    auto calc = [&](int idx) {
        ans[idx] = color;
    };

    mo.run(add, del, calc);

    for (int i = 0; i < q; i++) {
        cout << ans[i] << newl;
    }

    return 0;
}

Measured memory_bytes: 15716
using System;
using System.Text;

namespace _081_ASymmetricPoint
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (10 * 2 * 50);

			while ((inputStr = Console.ReadLine ()) != null)
			{
				decimal[] inputNum = Array.ConvertAll (inputStr.Split (','), decimal.Parse);

				Vector2 p1 = new Vector2 (inputNum[0], inputNum[1]);
				Vector2 p2 = new Vector2 (inputNum[2], inputNum[3]);
				Vector2 q = new Vector2 (inputNum[4], inputNum[5]);

				Vector2 result = Vector2.Reflection (p1, p2, q);

				output.Append (result.X);
				output.Append (" ");
				output.Append (result.Y);
				output.AppendLine ();
			}

			Console.Write (output);
		}
	}

	class Vector2
	{
		public Vector2 ( decimal x, decimal y )
		{
			this.X = x;
			this.Y = y;
		}

		public decimal X { private set; get; }
		public decimal Y { private set; get; }

		public static Vector2 operator + ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X + ob2.X, ob1.Y + ob2.Y);
		}
		public static Vector2 operator - ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X - ob2.X, ob1.Y - ob2.Y);
		}
		public static Vector2 operator * ( Vector2 ob, decimal scalar )
		{
			return new Vector2 (ob.X * scalar, ob.Y * scalar);
		}
		public decimal Length ()
		{
			return X * X + Y * Y;
		}
		public static decimal DotProduct ( Vector2 line1, Vector2 line2 )
		{
			return line1.X * line2.X + line1.Y * line2.Y;
		}
		public static Vector2 Reflection ( Vector2 beginPoint, Vector2 endPoint, Vector2 point )
		{
			Vector2 segment = endPoint - beginPoint;
			decimal ratio = Vector2.DotProduct (point - beginPoint, segment) / segment.Length ();
			Vector2 projectionPoint = beginPoint + segment * ratio;

			return point + (projectionPoint - point) * 2;
		}
	}
}

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n) ans += a[i]-1;
    cout << ans << endl;
}    

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

int main(void)
{
    int i;
    int n; scanf("%d", &n);
    int ac = 0, wa = 0, tle = 0, re = 0;
    char s[n][5]; for (i=0; i<n; i++) scanf("%s", &s[i]);

    for (i=0; i<n; i++)
    {
        if (s[i][0] == 'A') ac++;
        else if (s[i][0] == 'W') wa++;
        else if (s[i][0] == 'T') tle++;
        else re++;
    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);

    return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll R , C , N;
class curv
{
public:
        ll x , y , z , w , id;
        curv()
        {

        }
        curv(ll a , ll b , ll c , ll d , ll u)
        {
                x = a;
                y = b;
                z = c;
                w = d;
                id = u;
        }
};
vector<curv> pts;
bool corner(ll a , ll b)
{
        if(a == 0 || a == R) return true;
        if(b == 0 || b == C) return true;
        return false;
}
bool special(ll a , ll b , ll c , ll d)
{
        return (corner(a , b) && corner(c , d));
}
vector< pair< ll, ll> > XX;
int main()
{
        cin >> R >> C >> N;
        for(ll i = 1 ; i<=N;i++)
        {
                ll a , b , c , d;
                cin >> a>> b >> c >> d;
                if(special(a ,b,c,d)) {
                        curv X(a,b,c,d , i);
                        pts.pb(X);
                }
        }
        ll off = (R+C)*3;
        for(auto i : pts)
        {
                if(i.y == 0 || i.x == R) {
                        XX.pb(make_pair(i.x+i.y , i.id));
                }else{
                        XX.pb(make_pair(off - i.x - i.y , i.id));
                }

                if(i.w == 0 || i.z == R) {
                        XX.pb(make_pair(i.z+i.w , i.id));
                }else{
                        XX.pb(make_pair(off - i.z - i.w , i.id));
                }
        }
        sort(XX.begin() , XX.end());
        stack< ll> S;
        for(auto i : XX)
        {
                if(S.empty())
                {
                        S.push(i.second); continue;
                }else{
                        ll u = S.top();
                        if(u == i.second) {
                                S.pop();
                        }else{
                                S.push(i.second);
                        }
                }
        }
        S.empty() ? cout << "YES\n" : cout << "NO\n";
        return 0;
}


Measured memory_bytes: 12396
#import sys
#input = sys.stdin.readline

n=int(input())
s=input()
if n%2:
    print("No")
    exit()

s1=s[:n//2]
s2=s[n//2:]
if s1==s2:
#if s==(s1+s1):
    print("Yes")
else:
    print("No")


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

int main(){
char bad[101];
cin>>bad;
int a,b;
while(bad[0]!=0&&bad[1]!='\0'){
a=0;
b=0;
for(int i=1;i<101;i++){
	if(bad[i]=='A'){
	a++;
	}else if(bad[i]=='B'){
		b++;
		}
	}
	if(a>b){
		a++;
	}else if(b>a){
		b++;
	}
cout << a << ' ' << b << endl;
for(int k=0;k<101;k++){
		bad[k]='\0';
		}
	cin >> bad;
	}
return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

const int MAXN = 1e5 + 10;
int dp[MAXN][2];
vector<int> gr[MAXN];

int dfs(int u, int prev) {
    dp[u][0] = 1;
    dp[u][1] = 1;
    for (auto x : gr[u]) {
        if (x == prev) {
            continue;
        }
        dfs(x, u);
        (dp[u][0] *= dp[x][0] + dp[x][1]) %= mod;
        (dp[u][1] *= dp[x][0]) %= mod;
    }
    //cout << u << ":" << dp[u][1] << " " << dp[u][0] << '\n';
    return 0;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0;i < n - 1;i++) {
        int x, y;
        cin >> x >> y;
        gr[x].pb(y);
        gr[y].pb(x);
    }
    dfs(1, -1);
    int ans = dp[1][0] + dp[1][1];
    ans %= mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 14208
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int[] x = new int[3];
     x[0] = scan.nextInt();
     x[1] = scan.nextInt();
     x[2] = scan.nextInt();
     java.util.Arrays.sort(x);
     System.out.println(x[0]+" "+x[1]+" "+x[2]);
    }
}

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

const int NOT_FOUND=-1;

int linerSearch(int key, int A[],int n){
	int i=0;
	A[n]=key;
	while(A[i]!=key)
		i++;

	if(i==n)
		return NOT_FOUND;
	else
		return i;

}

int main(){
	int n,q;

	cin >>n;
	int S[n+1];
	for(int i=0; i<n; i++)
		cin>>S[i];

	cin >>q;
	int T[q+1];
	for(int i=0; i<q; i++)
		cin>>T[i];

	int C=0;
	for(int i=0; i<q; i++){
		if(linerSearch(T[i], S,n)!=NOT_FOUND)
			C++;
	}

	cout<<C<<endl;

	return 0;
}

		

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


bool dp[100005];
int a[105];
int main()
{
    int n, K;
    cin >> n >> K;
    for (int i = 0; i < n; i++) cin >> a[i];


    dp[0] = 0;

    for (int k = 1; k <= K; k++)
    {
        for (int i = 0; i < n; i++)
        {
            int r = k - a[i];
            if (r < 0) break;
            dp[k] = dp[k] | (dp[r] == 0);
        }
    }

    cout << (dp[K] ? "First":"Second");
    return 0;
}


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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  REP(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ++ans;
  }

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int ans=0;
    while(N>10){
        if(N%10==2)ans++;
        N/=10;
        if(N<10){
            if(N==2)ans++;
            break;
        }
    }
    cout<<ans<<endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		if(N < 1 || N > 86){
			return;
		}
		if(N == 0){
			System.out.println(2);
			return;
		}
		
		if(N == 1){
			System.out.println(1);
			return;
		}
		if(N == 2){
			System.out.println(3);
			return;
		}
		
		if(N >= 3){
			long i = 0;
			long sum = 0;
			long current = 3;
			long before = 1;
			
			while(i < N-2){
				sum = before + current;
				before = current;
				current = sum;
				i++;
			}
			
			System.out.println(sum);
			return;
		}	
		
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n;
  cin >> n;
  vi a(n);
  int all=0;
  rep(i,n){
    cin >> a[i];
    all=all ^ a[i];
  }
  rep(i,n){
    int x = all^a[i];
    if(i<n) cout << x << " ";
    else cout << x;
  }
}

Measured memory_bytes: 4044
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);


        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFindTree uf = new UnionFindTree(n);
//        debug(uf.parent);
        for (int i = 0; i < m; i++) {
            uf.union(sc.nextInt() - 1, sc.nextInt() - 1);
        }

//        debug(uf.parent);
        int[] size = new int[n];
        for (int i = 0; i < n; i++) {
            int p = uf.find(uf.parent[i]);
            size[p]++;
        }
//        debug(size);
        int max = -1;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, size[i]);
        }

        System.out.println(max);

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


class UnionFindTree {

    int[] parent; //インデックスにとノードを対応させ、そのルートノードのインデックスを格納
    int[] rank; //parentと同様に、木の高さを格納

    public UnionFindTree(int size) {
        this.parent = new int[size];
        this.rank = new int[size];

        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    public void makeSet(int i) {
        parent[i] = i;
        rank[i] = 0; //集合の高さ
    }

    public void union(int x, int y) {
        int xRoot = find(x);
        int yRoot = find(y);

        //xが属する木の方が大きい場合
        if (rank[xRoot] > rank[yRoot]) {
            parent[yRoot] = xRoot; //yの親をxに更新

        } else if(rank[xRoot] < rank[yRoot]) {
            parent[xRoot] = yRoot;

        } else if (xRoot != yRoot){
            parent[yRoot] = xRoot;
            rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
        }
    }

    //引数の属する木のルートのidを返す
    public int find(int i) {
        if (i != parent[i]) {
            parent[i] = find(parent[i]);
        }
        return parent[i];
    }

    //同じ木に属しているか
    public boolean same(int x, int y) {
        return find(x) == find(y);
    }
}


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

int main() {
  int N;
  cin >> N;
  
	for (int i = 0; i < N; i++) {
      string s;      
      cin >> s;
      
      if (s == "Y") {
        cout << "Four" << endl;
      break;
      }
      
      if (i == N-1 && s != "Y")
        cout << "Three" << endl;
        
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int k[202];
int s[202][22],h[202][22];
double c[202][202];
int ma[202];
double memo[202][202];
double dfs(int p,int x){
  if(memo[p][x]>=0) return memo[p][x];
  if(p==n) return 0; 
  double res=0;
  for(int i=0;i<=min(x,ma[p]);i++){
    res=max(res,dfs(p+1,x-i)+c[p][i]);
  }
  //cout<<p<<" "<<x<<" "<<res<<endl;
  return memo[p][x]=res;
}
signed main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j]>>h[i][j];
    }
  }
  for(int i=0;i<n;i++){
    ma[i]=0;
    for(int j=0;j<k[i];j++) ma[i]+=s[i][j]*h[i][j];
    for(int j=0;j<=ma[i];j++){
      queue<int> q;
      for(int r=0;r<k[i];r++)
	for(int l=0;l<h[i][r];l++) 
	  q.push(s[i][r]);
      double tmp=0;
      int x=0;
      while(!q.empty()){
	int p=q.front();q.pop();
	if(x+p>j){
	  tmp+=(double)(j-x)/p;
	  break;
	}
	x+=p;
	tmp+=1;
      }
      //cout<<i<<" "<<j<<" "<<ma[i]<<" "<<tmp<<endl;
      c[i][j]=tmp;
    }
  }
  for(int i=0;i<202;i++)
    for(int j=0;j<202;j++)
      memo[i][j]=-1;
  printf("%.12f\n",dfs(0,m));
  return 0;
}

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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int k, n, m;
string s;

using namespace std;

int ce(int a, int b){
	return (a+b-1)/b;
}

int main(){
	cin >> n >> s >> k;

	for (int i = 0; i < n; ++i){
		if(s[i] != s[k-1])printf("*");
		else printf("%c", s[i]);
	}
	printf("\n");

	
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    d = list(map(int, input().split()))
    total = 0
    while len(d) > 1:
        c = d[0]
        for i in range(len(d) - 1):
            total = total + (c * d[1 + i])
        d.pop(0)
    print(total)
main()

Measured memory_bytes: 9108
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (N == 1)
            {
                Console.WriteLine(1);
                return;
            }

            var total = 0;
            var up = 0;
            for (var i = 1; i < N; i++)
            {
                if (A[i] == A[i - 1]) continue;
                else if (A[i] > A[i - 1])
                {
                    if (up == 0) up = 1;
                    else if (up == 2)
                    {
                        up = 0;
                        total++;
                    }
                }
                else
                {
                    if (up == 0) up = 2;
                    else if (up == 1)
                    {
                        up = 0;
                        total++;
                    }
                }
            }

            Console.WriteLine(total + 1);
        }
    }
}


Measured memory_bytes: 21728
// comment
#include <iostream>
using namespace std;
 
int isFinish(int *human, int N) {
    int count = 0;
    int id = -1;
    for (int i = 0; i < N; i++) {
        if (human[i] > 0) {
            id = i; count++;
        }
    }
    if (count == 1) return id;
    else return -1;
}
int main() {
    while (true) {
        int N, P;
        int ans;
        cin >> N >> P;
        if (N == 0 && P == 0) break;
        int human[50] = {0};
        int i = 0;
        while (true) {
            if (P != 0) {
                human[i] += 1;
                P--;
                if (P == 0) {
                    ans = isFinish(human, N);
                    if (ans >= 0) break;
                }
            }
            else {
                P += human[i];
                human[i] = 0;
            }
            i = (i + 1) % N;
        }
        cout << ans << endl;
    }
    return 0;
}
 

Measured memory_bytes: 864
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
int main(){
    int n,z=0;
    cin>>n;
    vector<pair<int,int>> ans;
    priority_queue<int> neg;
    priority_queue<int,vector<int>,greater<int>> pos;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        if(t<0) neg.push(t);
        else if(t>0)    pos.push(t);
        else    z++;
    }
    if(n==2&&z>0){
        if(z==2){
            cout<<0<<endl;
            cout<<0<<' '<<0<<endl;return 0;
        }
        else if(neg.empty()){
            cout<<pos.top()<<endl;
            cout<<pos.top()<<' '<<0<<endl;return 0;
        }
        else{
            cout<<-neg.top()<<endl;
            cout<<0<<' '<<neg.top()<<endl;return 0;
        }
    }
    /*準備段階
    positive queueとnegative queueに
    最低でも一つは数があるようにする。
    0があるならlossなしでそのような状況を作れる。
    ない場合はlossがでるが、トップの数を使えばロスを|その数+1|で
    抑えられる。
     */
    if(neg.empty()){
        if(z>0){
            z--;
            ans.push_back(make_pair(0,pos.top()));
            neg.push(-pos.top());
            pos.pop();
        }
        else{
            int a1=pos.top();pos.pop();
            int a2=pos.top();pos.pop();
            ans.push_back(make_pair(a1,a2));
            neg.push(a1-a2);
        }
    }
    else if(pos.empty()){
        if(z>0){
            z--;
            ans.push_back(make_pair(0,neg.top()));
            pos.push(-neg.top());
            neg.pop();
        }
        else{
            int a1=neg.top();neg.pop();
            int a2=neg.top();neg.pop();
            ans.push_back(make_pair(a1,a2));
            pos.push(a1-a2);
        }
    }

    //解いていく。negとposiをマージして育てる
    while(neg.size()>1){
        int a=pos.top();pos.pop();
        int b=neg.top();neg.pop();
        ans.push_back(make_pair(a,b));
        pos.push(a-b);
    }
    while(pos.size()>1){
        int a=neg.top();neg.pop();
        int b=pos.top();pos.pop();
        ans.push_back(make_pair(a,b));
        neg.push(a-b);
    }
    ans.push_back(make_pair(pos.top(),neg.top()));
    while(z>0){
        z--;
        ans.push_back(make_pair((pos.top()-neg.top()),0));
    }
    cout<<(pos.top()-neg.top())<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string s, t;
    cin >> n >> s;
    s += s[0];
    for (int a = 0; a < 4; a++) {
        if (a == 0) t = "SS";
        else if (a == 1) t = "SW";
        else if (a == 2) t = "WS";
        else t = "WW";
        for (int i = 2; i <= n + 1; i++) {
            if (t[i - 1] == 'S') {
                if (s[i - 1] == 'o') {
                    if (t[i - 2] == 'S') t += 'S';
                    else t += 'W';
                } else {
                    if (t[i - 2] == 'S') t += 'W';
                    else t += 'S';
                }
            } else {
                if (s[i - 1] == 'o') {
                    if (t[i - 2] == 'S') t += 'W';
                    else t += 'S';
                } else {
                    if (t[i - 2] == 'S') t += 'S';
                    else t += 'W';
                }
            }
        }
        if (t[0] == t[n] && t[1] == t[n + 1]) {
            cout << t.substr(0, n);
            return 0;
        }
    }
    cout << -1;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  string S,T;
  cin>>S>>T;
  int A,B;
  cin>>A>>B;
  string U;
  cin>>U;

  if(S==U) A--;
  else if(T==U) B--;

  cout<<A<<" "<<B<<endl;

  return 0;
}


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

int n;
ll a[200000], ans = (1L << 62), X, x;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%ld", &a[i]);
        X += a[i];
    }
    for (int i = 0; i < n - 1; i++) {
        x += a[i];
        ans = min(ans, abs(X - x - x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import math
def intersectionCC0(x1, y1, r1, r2):
    r = x1**2 + y1**2
    t = (r + r1**2 - r2**2) / (2*r)
    dd = r1**2/r - t**2
    if - (10**-8) < dd < 0: dd = 0
    if dd < 0: return []
    x, y = t * x1, t * y1
    if dd == 0: return [(x, y)]
    sq = math.sqrt(dd)
    dx, dy = y1 * sq, -x1 * sq
    return [(x+dx, y+dy), (x-dx, y-dy)]

def intersectionCC(x1, y1, x2, y2, r1, r2):
    return [(x1+x, y1+y) for x, y in intersectionCC0(x2-x1, y2-y1, r1, r2)]

def chk(t):
    L = [a for a in L0]
    for i, (x1, y1, c1) in enumerate(X):
        for x2, y2, c2 in X[:i]:
            L += intersectionCC(x1, y1, x2, y2, t/c1, t/c2)
    for x0, y0 in L:
        cnt = 0
        for x, y, c in X:
            if math.sqrt((x-x0) ** 2 + (y-y0) ** 2) * c <= t + 10**-8:
                cnt += 1
        if cnt >= K: return 1
    return 0

N, K = map(int, input().split())
X = []
L0 = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))
    L0.append((x, y))

l, r = 0, 150000
while (r-l) * (1<<20) > max(1, l):
    m = (l+r) / 2
    if chk(m):
        r = m
    else:
        l = m
    
print((l+r)/2)

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

int main()
{
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	cout << "A" << s2[0] << "C" << endl;
	return 0;
}

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

int main()
{
	string S;
	cin >> S;
	int ans = 0;
	rep(i,3)
	{
		if (S[i] == '1') ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++){
    string S;
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
break;    }     
      if(i==N-1){
          cout << "Three" << endl;
      }
  }
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cmath>

#define in std::cin
#define out std::cout

int64_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	int32_t min = 11;
	for (int64_t i = 1, end = sqrt(N)+1; i <= end; i++)
	{
		if (N%i == 0) {

			int32_t count = 0;
			int64_t tmp = N / i;
			while (tmp>0)
			{
				++count;
				tmp /= 10;
			}
			min = std::min(min, count);
		}
	}
	out << min << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include<iomanip>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll l[n];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; i ++)
    {
        l[i] = l[i - 1] + l[i - 2];
    }
    cout << l[n] << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace  std;
int main()
{
    int a,b,c,d,e;
    cin >> a >> b >> c;
    d = a - b;
    e = b - c;
    if(d < 0 && e < 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,num)for(int i=0;i<(num);++i)
#define ll long long
using namespace std;
unordered_map<int, string> mp;
ll N;

int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    if (N == 0) {
        cout<<"0";return 0;
    }
    string ans="";
    while(N!=1) {
        if(N%2!=0){
            if(N<0)N--;
            ans+="1";
        }else{
            ans+="0";
        }
        N/=-2;
    }
    ans+="1";
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	boolean flg = true;
		String words[] = new String[N];
      	for(int i=0;i<N;i++){
        	words[i] = sc.next();
        }
      	ArrayList<String> list = new ArrayList<String>();
      	list.add(words[0]);
      	for(int i=0;i<N-1;i++){
        	if(words[i].charAt(words[i].length()-1)!=words[i+1].charAt(0)||list.contains(words[i+1])){
                System.out.println("No");
                flg = false;
                break;
             }else{
                list.add(words[i+1]);
            }
        }
      	if(flg){
        	System.out.println("Yes");
        }
    }
}

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

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> matrix(H, "");
    string aux;
    getline(cin, aux);
    for(int i=0;i<H;i++){
        getline(cin, matrix[i]);
    }
    for(int i=0;i<2*H;i++){
        cout << matrix[i/2];
        cout << "\n";
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)1000000000000
//この設定だとn<10^7が限界。maxの０を一個増やせば100msかかるが一桁増やせる。
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll N,K;
  cin>>N>>K;
  ll g=(N-2ll)*(N-1ll)/2ll;
  queue<P>qu;
  if(g<K){cout<<-1;return 0;}
  else{
    
    ll memo=g-K;
    rep(i,N-1){
      qu.push(P(N,i+1));
    }
    int flag=0;
    for(int i=1;i<=N-1;i++){
      for(int j=i+1;j<=N-1;j++){
        if(memo==0){flag=1;}
        if(flag==1){continue;}
        qu.push(P(i,j));
        memo--;
      }
      if(flag==1){continue;}
    }
  }
  cout<<qu.size()<<endl;
  while(!qu.empty()){
    auto t=qu.front();
    qu.pop();
    cout<<t.first<<' '<<t.second<<endl;
  }
  
}


Measured memory_bytes: 3616
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys

class Node:
    def __init__(self):
        self.children = []
        self.color = -1
    
    def append(self,target,weight):
        self.children.append((target,weight))
        target.children.append((self,weight))
 
    def setColor(self,color):
        self.color = color
        for child in self.children:
            if child[0].color != -1:
                continue
            if child[1] % 2 == 0:
                child[0].setColor(self.color)
            else:
                child[0].setColor(0 if self.color == 1 else 1)

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    nodes = [Node() for i in range(N)]
    # print(u)
    for i in range(N-1):
        nodes[u[i]-1].append(nodes[v[i]-1],w[i])
    colorQueue = [(nodes[0],0)]
    while True:
        if len(colorQueue) == 0:
            break
        next = colorQueue.pop()
        next[0].color = next[1]
        for child in next[0].children:
            if child[0].color != -1:
                continue
            if child[1] % 2 == 0:
                colorQueue.append((child[0],next[0].color))
            else:
                colorQueue.append((child[0],0 if next[0].color == 1 else 1))

    for n in nodes:
        print(n.color)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56944
# ABC148a

import logging


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    def dump(*args):
        sys.stderr.write(str(args))
    # 再帰関数を使わない限りPypyで出すこと

    a = int(input())
    b = int(input())
    print(*set([1, 2, 3]).difference(set([a]), set([b])))
    dump('Error occurred!', 1, 136513, [2521.26262, 624652])


if __name__ == '__main__':
    main()


Measured memory_bytes: 43500
n,m = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i).sort.reverse

s = [nums.shift / 2] 
(m-1).times do |i|
  if nums == []
    nums = s
    s = [nums.shift / 2]
  elsif nums[0] > s[0]
    s << nums.shift / 2
  else
    s << s.shift / 2
  end
end

nums += s
puts nums.inject(:+)

Measured memory_bytes: 13808
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  LLI N, M;
  while(cin >> N >> M){
    vector<LLI> a(N); cin >> a;
    sort(ALL(a));

    auto ans = [&]() -> LLI{
      REP(i,N) a[i] /= 2;

      set<int> s;
      for(auto x : a){
        int c = 0;

        while(x % 2 == 0){
          x /= 2;
          ++c;
        }

        s.insert(c);
      }

      dump(s);
      
      if(s.size() != 1) return 0;

      LLI l = a[0];
      for(auto x : a){

        auto g = gcd(l, x);

        g = l / g;

        LLI k;
        if(__builtin_smulll_overflow(g, x, &k)){
          return 0;
        }

        l = k;
      }
    
      LLI k;
      if(__builtin_smulll_overflow(2LL, l, &k)){
        return M / l;
      }


      LLI ans = M / l - M / (2*l);

      return ans;
    }();
    

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    string s;
    for (int i = 1; i <= 9; i++) s += (i + '0'), sol(s), s.pop_back();
    sort(a.begin(), a.end(), cmp);
    int k;
    cin >> k;
    cout << a[k - 1];
}


Measured memory_bytes: 11548
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string a, b, c;
	cin >> a >> b >> c;
	int turn = 0;
	while (true) {
		if (turn == 0) {
			if (a.size() == 0) {
				cout << "A"; return 0;
			}
			turn = a[0] - 'a';
			a.erase(a.begin());
		}
		if (turn == 1) {
			if (b.size() == 0) {
				cout << "B"; return 0;
			}
			turn = b[0] - 'a';
			b.erase(b.begin());
		}
		if (turn == 2) {
			if (c.size() == 0) {
				cout << "C"; return 0;
			}
			turn = c[0] - 'a';
			c.erase(c.begin());
		}
	}
	return 0;
}
//Ctrl+Aを使わない

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

int main() {
  int N;

  cin >> N;

  vector<int> a(N);

  for(int i=0; i<N; i++) {
      cin >> a.at(i);
  }

  int count=0;
  int next=1;

  while(next!=2 && count!=100000) {
      next = a.at(next-1);
      count++;
  }

  if(count == 100000) {
      cout << -1 << endl;
  } else {
      cout << count << endl;
  }
}

Measured memory_bytes: 640
# coding: utf-8
s = input()
d = 0
d_min = abs(int(s[0:3]) - 753)
for i in range(len(s) - 2):
    d = abs(int(s[i:i+3]) - 753)
    if d < d_min:
        d_min = d
print(d_min)


Measured memory_bytes: 2940