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

using namespace std;
typedef pair<int, int> Pii;

const int N = 2010;

int n, k, dep[N], ans = 0;
Pii A[N];
vector<int> G[N];

int BFS(int a, int b, int k) {
    int res = 0;
    memset(dep, 0, sizeof(dep));
    queue<int> Q; Q.push(a); if(a^b) Q.push(b);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        if(dep[x] <= k) res++;
        int sz = G[x].size();
        for(int i = 0;i < sz; ++i) {
            int u = G[x][i]; if(u == a || u == b) continue;
            if(!dep[u]) {
                dep[u] = dep[x] + 1;
                if(dep[u] <= k) {
                    Q.push(u);
                }
            }
        }
    }
    return res;
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1, u, v;i < n; ++i) {
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
        A[i] = make_pair(u, v);
    }
    for(int i = 1;i <= n; ++i) {
        ans = max(ans, BFS(i, i, k / 2));
        ans = max(ans, BFS(A[i].first, A[i].second, (k - 1) / 2));
    }
    cout << n - ans << endl;
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    int n;
    int sum=0;
    int flag =0;
    cin >>n;
    vector<int> a(n),b(n);
    rep(i,n) cin >>a[i]>>b[i];
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;

    rep(i,n){
        q.push(make_pair(b[i],a[i]));
    }
    while(!q.empty()&&flag==0){
        sum += q.top().second;
        if (sum <=q.top().first) q.pop();
        else flag++;
    }
    if (flag) cout << "No";
    else cout <<"Yes";
}

Measured memory_bytes: 4980
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

sys.setrecursionlimit(10000000)

N = int(input())
AB = []
CD = []

for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))

for i in range(N):
    C, D = map(int, input().split())
    CD.append((C, D))

AB.sort()
CD.sort()

used = [False] * N
cnt = 0

for i in range(N):
    m = -1
    for j in range(N):
        if not used[j] and CD[i][0] > AB[j][0] and CD[i][1] > AB[j][1]:
            if m < 0 or AB[m][1] < AB[j][1]:
                m = j

    if m >= 0:
        used[m] = True
        cnt += 1

print(cnt)

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

int main(){
    string a, b, c;
    cin >> a >> b >> c; 
    transform(begin(a), end(a), std::begin(a), ::toupper);
    transform(begin(b), end(b), std::begin(b), ::toupper);
    transform(begin(c), end(c), std::begin(c), ::toupper);
    cout << a[0] << b[0] << c[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  std::cin >> x>>y;
  if(x>y)std::cout << "safe" << '\n';
  else std::cout << "unsafe" << '\n';  
}


Measured memory_bytes: 3624
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var X = input[2];

        var CA = new int[N][];
        for (int i = 0; i < N; i++)
        {
            CA[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
        }

        var result = int.MaxValue;
        for (int i = 0; i < Math.Pow(2, N); i++)
        {
            var b = Convert.ToString(i, 2).PadLeft(N, '0').ToCharArray();
            var c = 0;
            var a = new int[M];
            for (int j = 0; j < N; j++)
            {
                if (b[j] == '1')
                {
                    c += CA[j][0];
                    for (int k = 0; k < M; k++)
                    {
                        a[k] += CA[j][k + 1];
                    }
                }
            }
            if (a.Min() >= X && c < result)
            {
                result = c;
            }
        }
        Console.WriteLine(result == int.MaxValue ? -1 : result);
    }
}


Measured memory_bytes: 29660
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

int main()
{

  double t, x;
  cin >> t >> x;

  cout << t / x << endl;

  return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
if s[::-1]==s and s[:(n-1)//2][::-1]==s[:(n-1)//2] and s[(n+3)//2 -1  :][::-1]==s[(n+3)//2 -1 :]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>
int add(int x, int y) {
	return x + y;
}
int jian(int x, int y) {
	return x - y;
}
int main() {
	int a[10], i, j, k;
	char sign[2] = { '+','-' };
	int(*p[2])(int, int) = { add,jian };
	for (i = 0; i < 4; i++) scanf("%1d", a + i);
    int sum=a[0];
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 2; k++) {
				sum = p[k](p[j](p[i](sum,a[1]),a[2]),a[3]);
				if (sum == 7) goto label;
				else sum = a[0];
			}
		}
	}
label:
	printf("%d%c%d%c%d%c%d=7", a[0], sign[i], a[1], sign[j], a[2], sign[k], a[3]);
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;

    bool flg=true;
    REP(i,N){
        int a;
        cin>>a;
        if(a%2==0){
            if(a%3==0||a%5==0) continue;
            else flg=false;
        }
    }
    if(flg) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # 初期状態の合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_にします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())
    
    # 和を計算します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]
    
    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0
    
    print(sum_res)

Measured memory_bytes: 24016
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
check = [0] * (n + 1)
for i in range(m):
    a, b = map(int, readline().split())
    check[a] += 1
    check[b] += 1
for v in check:
    if v % 2 == 1:
        print('NO')
        break
else:
    print('YES')


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

int main() {
int N,K;
cin>>N>>K;
vector<int> vec(N);
for(int i=0; i<N ; i++){

cin>>vec.at(i);

}
int sum=0;
for(int i=0 ; i<N ; i++){

if(K<vec.at(i)){
sum+=(vec.at(i)-K)*2;
}
else{
sum+=min(K-vec.at(i) , vec.at(i))*2;
}


}
cout<<sum<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Multiplication2 | diff Multiplication2.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Multiplication2.cpp && ./a.out

/*

 5/31/2020

 5:01-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

const __uint128_t inf=1e18;
void solve() {
  LL res=1;
  REP(i,N) {
    __uint128_t a=A[i];
    if(a*res>inf) res=inf+10;
    else res=(LL)(a*res);
  }
  cout<<(res>inf?-1:res)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

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

  return 0;
}


Measured memory_bytes: 4440
A,B,C,D,E,F = map(int,input().split())

M = 0
S = 0
N = 30
ansp = 0
tmpM = 0
tmpS = 0
SUGAR = [0]*3001
SUGAR[0] = 1
for i in range(1,3001):
    if i - C >= 0:
        if SUGAR[i-C] == 1:
            SUGAR[i] = 1
    if i - D >= 0:
        if SUGAR[i-D] == 1:
            SUGAR[i] = 1

for i in range(31):
    for j in range(31-i):
        tmpM = 100*A*i+100*B*j
        maxS = E*(A*i+B*j)
        if tmpM != 0 and tmpM <= F:
            for k in range(E*(A*i+B*j)+1):
                l = E*(A*i+B*j) - k
                #print(l)
                if SUGAR[l] == 1 and l+tmpM <= F:
                    tmpS = l
                    break
            if tmpS/(tmpM+tmpS) > ansp:
                ansp = tmpS/(tmpM+tmpS)
                M = tmpM
                S = tmpS
if M != 0:
    print(*[M+S,S])
else:
    print(*[100*A,0])

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

int main() {
  int N, sum = 0;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  for(int i = 0; i < N; i++) {
    for(int j = N - 1; j > i; j--) {
      sum += d.at(i) * d.at(j);
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef vector<int> vi;

string plus_string(string a,string b)
{
  string c;
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  while(a.size()!=b.size())
    {
      if(a.size()<b.size())
	{
	  a.push_back('0');
	}
      else
	{
	  b.push_back('0');
	}
    }
  for(int i=0;i<(int)a.size();i++)
    {
      c.push_back('0');
    }
  int n=0;
  for(int i=0;i<a.size();i++)
    {
      if(n+(a[i]-'0')+(b[i]-'0')<=9)
	{
	  c[i]=a[i]+b[i]-'0'+n;
	  n=0;
	}
      else
	{
	  c[i]=a[i]+b[i]-'0'-10+n;
	  n=1;
	}
    }
  if(n==1)
    {
      c.push_back('1');
    }
  reverse(c.begin(),c.end());
  return c;
}

string change_x(string s,char c)
{
  for(int i=0;i<(int)s.size();i++)
    {
      if(s[i]=='X') s[i]=c;
    }
  return s;
}

int main()
{
  string s;
  string num1="",num2="";
  string ans="";
  string a,b,c;
  int plus,equal;
  bool clear;
  while(cin >> s)
    {
      clear=false;
      for(int i=0;i<(int)s.size();i++)
	{
	  if(s[i]=='+') plus=i;
	  else if(s[i]=='=') equal=i;
	}
      num1=s.substr(0,plus);
      num2=s.substr(plus+1,equal-plus-1);
      ans=s.substr(equal+1);
      for(int i=0;i<=9;i++)
	{
	  a=change_x(num1,i+'0');
	  b=change_x(num2,i+'0');
	  c=change_x(ans,i+'0');
	  if(plus_string(a,b)==c)
	    {
	      cout << i << endl;
	      clear=true;
	    }
	}
      if(!clear)cout << "NA" << endl;
    }
  return 0;
}



Measured memory_bytes: 3132
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	int n, k;
	cin >> n >> k;
	int tab[100005];
	int licznik = 0;
	
	for(int i = 0; i < n; i++){
		cin >> tab[i];
		if(tab[i] >= k)
			licznik++;
	}

	cout << licznik << endl;


	
	
	
	
	
	
	
	
	
	return 0;
}


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> x(n);
    for(i = 0;i < n;i++) cin >> x[i];
    long long ans = LLONG_MAX;
    for(i = 1;i <= 100;i++){
        int ca = 0;
        for(j = 0;j < n;j++){
            ca += (x[j]-i)*(x[j]-i);
        }
        if(ca < ans) ans = ca;
    }
    cout << ans << endl;
}

int main(){
    solve();
}


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

int main() {

    string S;
    cin >> S;

    char last = S[S.length()-1];

    if (last == '3')  cout << "bon" << endl;
    else if (last == '0' || last == '1' || last == '6' || last == '8') cout << "pon" << endl;
    else cout << "hon" << endl;

    return 0;
}


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



int main(){
	string S; cin >> S;
	int zero = 0;
	int iti = 0;
	rep(i,S.size()){
		if(S[i] == '0'){
			zero++;
		}
		else{
			iti++;
		}
	}
	if(zero > iti){
		cout << iti * 2 << endl;
	}
	else{
		cout << zero * 2 << endl;
	}
}


Measured memory_bytes: 512
/*
・座標の出力
n==0のとき、再起毎に両端（p1,p2）を出力すると、両端以外の点は二回出力されてしまう。
よって、ｐ１を再起前に出力して、再起内では右端（ｐ２）のみ出力にする。


*/

#include <iostream>
#include <cmath>
#include <cstdio>

const static double PI = 4*atan(1.0);

using namespace std;


int count=0;


 
void Koch_curve(int n, double p1x, double p1y, double p2x, double p2y){
    double sx, sy, tx, ty, ux, uy;
    
	if(n == 0){
		//cout << p2x << ' ' << p2y << endl;
		printf("%.8lf %.8lf\n", p2x, p2y);
		count++;
	}
	else{
		n--;
		sx = p1x + (p2x-p1x)*(1.0/3.0);
		sy = p1y + (p2y-p1y)*(1.0/3.0);
		tx = p1x + (p2x-p1x)*(2.0/3.0);
		ty = p1y + (p2y-p1y)*(2.0/3.0);

		//求め方は http://www.infra.kochi-tech.ac.jp/takagi/Survey2/3PolarRect.pdf　
		// 極座標の回転　（二次元回転行列）
		ux= sx + (tx-sx)*cos(PI/3.0) - (ty-sy)*sin(PI/3.0);
		uy= sy + (tx-sx)*sin(PI/3.0) + (ty-sy)*cos(PI/3.0);

		Koch_curve(n, p1x, p1y, sx, sy);
		Koch_curve(n, sx, sy, ux, uy);
		Koch_curve(n, ux, uy,tx, ty);
		Koch_curve(n, tx, ty, p2x, p2y);
	}
    
}
 
int main() {
    int n;
    
    cin >> n;
	//cout.setf(ios::fixed, ios::floatfield); //固定小数表記 
	//cout << 0.0 << ' ' << 0.0 << endl;
	printf("%.8lf %.8lf\n", 0.0, 0.0);
    Koch_curve(n, 0.0, 0.0, 100.0, 0.0);
        
        return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
#include <map>
using namespace std;

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

typedef long long ll;

int main()
{
    string s, t;

    cin >> s >> t;

    cout << t << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

int main() {
  ll cur, target;
  cin >> cur >> target;
  ll ans = 0;
  if (cur >= 0 && target >= 0) {
    if (cur <= target) ans = target - cur;
    else if (target == 0) ans = 1 + (cur - target);
    else ans = 2 + (cur - target);
  }
  else if (cur >= 0 && target < 0) {
    ans = 1 + abs(-target - cur);
  }
  else if (cur < 0 && target >= 0) {
    ans = min(target - cur, 1 + abs(target + cur));
  }
  else if (cur < 0 && target < 0) {
    if (cur <= target)  ans = abs(target - cur);
    else ans = 2 + abs(target - cur);
  }
  cout << ans << endl;
  return 0;
}

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

namespace aaaaa
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            string s = Console.ReadLine();
            for (int i = 0; i < 3; i++)
            {
                if (s[i] == '1')
                {
                    sum += 1;
                }
            }
            Console.WriteLine(sum);
          
            
        }
    }
}


Measured memory_bytes: 25920
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x,a,b;
    cin >> x >> a >> b;
    if(b-a<=0){
        cout << "delicious" << endl;
    }else if(b-a<=x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 入力を受け取る
    int N = sc.nextInt();
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    for (int i = 0; i < N; i++) {
      String S = sc.next();
      if (S.equals("AC")) {
        ac++;
      } else if (S.equals("WA")) {
        wa++;
      } else if (S.equals("TLE")) {
        tle++;
      } else {
        re++;
      }
    }
    System.out.println("AC x " + ac);
    System.out.println("WA x " + wa);
    System.out.println("TLE x " + tle);
    System.out.println("RE x " + re);
  }
}

Measured memory_bytes: 59244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long[] A = new long[N];
		int NN = 1000001;
		int[] num = new int[NN];

		for(int i = 0;i < N ;i++) {
			A[i] = scn.nextLong();
		}
		long MOD = 1000000007;
		long ans = 0;
		for(int i = 0;i < N;i++) {
			int a = (int)A[i];
			for(int j = 2;j < Math.sqrt(a)+1;j++) {
				int c = 0;
				while(a%j==0) {
					c++;
					a/=j;
				}
				num[j] = Math.max(num[j], c);
			}
			if(a>1) {
				num[a] = Math.max(num[a], 1);
			}
		}
		long Aa = 1;
		for(int i = 0;i < NN;i++) {
			if(num[i]!=0) {
				Aa *= Math.pow(i, num[i])%MOD;
				Aa %= MOD;
			}
		}

		for(int i = 0;i < N;i++) {
			long buf = Aa;
			buf *= MyMath.modinv(A[i],MOD);

			ans += buf % MOD;
			ans %= MOD;
		}
		System.out.println(ans);
	}

}

class Pair implements Comparable<Pair> {
	int first, second;

	public Pair(int f, int s) {
		this.first = f;
		this.second = s;
	}

	@Override
	public int compareTo(Pair o) {// Comparatorを自由記述せよ(これはfirstが小さい順, secondが小さい順)
		if (this.first < o.first) {
			return -1;
		}
		if (this.first > o.first) {
			return 1;
		}
		if (this.second < o.second) {
			return -1;
		}
		if (this.second > o.second) {
			return 1;
		}

		return 0;
	}
}
class MyMath {

	// --0.3.2--------------------------------------------------------------//
	// -- mod逆元-----------------------------------------------------------//
	public static long modinv(long a, long mod) {// x / a (mod MOD):=  x*= modinv(a,MOD)
		long b = mod, u = 1, v = 0;
		long buf = 0;
	    while (b>0) {
	        long t = a / b;
	        a -= t * b;
	        buf = a;
	        a = b;
	        b = buf;
	        u -= t * v;
	        buf = u;
	        u = v;
	        v = buf;
	    }
	    u %= mod;
	    if (u < 0) u += mod;
	    return u;

	}

}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define PI 3.141592653589793
ll N, M, A[10101];
ll i, j, k;
int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,M){
        scanf("%lld", &A[i]);
        j += A[i];
    }
    if(j<=N){
        printf("%lld\n", N - j);
    }else{
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 3824
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    string w;
    io.read(w);
    vector<int> v(26, 0);
    for(int i = 0; i < w.size(); i++){
        v[w[i] - 'a']++;
    }
    string ans = "Yes";
    for(int i = 0; i < v.size(); i++){
        if(v[i] % 2 != 0) ans = "No";
    }cout << ans;
    return 0;
}

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

    vector<tuple<string, int, int>> restaurant(n);
    string s;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> s >> x;
        restaurant.at(i) = make_tuple(s, 100 - x, i+1);
    }

    sort(restaurant.begin(), restaurant.end());
    
    rep(i, n)
        cout << get<2>(restaurant.at(i)) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int N;
  string S;
  cin>>N>>S;
  int stack=0,l=0;
  for(int i=0;i<N;i++){
    if(S[i]=='('){stack++;}
    else if(stack>0){stack--;}
    else{l++;}
  }
  int r=stack;
  string ans;
  for(int i=0;i<l;i++){
    ans+='(';
  }
  ans+=S;
  for(int i=0;i<r;i++){
    ans+=')';
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <sstream>

using namespace std;
int main()
{
    string str;
    cin >> str;
    vector<int> nums(str.size());
    int sum = 0;
    transform(str.begin(), str.end(), nums.begin(), [](char ch) { return ch - '0';});

    for (int n:nums)
        sum += n;

    if (sum % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 4376
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  d, _ := strconv.Atoi(sc.Text())

  fmt.Println((n + 2 * d) / (2 * d + 1))
}



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

long long N,eightpow,ninepow,tenpow,ans,mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>N;
	eightpow = 1;
	ninepow = 1;
	tenpow = 1;
	for(int i = 1;i <= N;i++){
		eightpow = 8 * eightpow;
		eightpow = eightpow % mod;
	}
	for(int i = 1;i <= N;i++){
		ninepow = 9 * ninepow;
		ninepow = ninepow % mod;
	}
	for(int i = 1;i <= N;i++){
		tenpow = 10 * tenpow;
		tenpow = tenpow % mod;
	}
	ans = (tenpow - ninepow - ninepow + eightpow) % mod;
	ans = (ans + mod) % mod;
	cout<<ans<<endl;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int M = max(max(a,b),c);
  cout << a+b+c-M << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>

using namespace std;

int main() {
    double sum = 0;
    double a[10];

    while (cin >> a[0]) {
        sum = 0;
        for (int i = 1; i < 10; i++) a[i] = 0;
        for (int i = 1; i < 10; i++) {
            if (i % 2 == 0) {
                a[i] = a[i-1] / 3.0;
            } else {
                a[i] = a[i-1] * 2.0;
            }
        }

        for (int i = 0; i < 10; i++) {
            sum += a[i];
        }

        printf("%.8f\n", sum);
//        cout << setw(2) << setprecision(10) << sum << endl;
    }
    return 0;
}

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

typedef long long int ll;
ll n, k, a[200007];
const ll MOD = 1000000007;

int main() {
    cin >> n >> k;
    ll ans = 0;

    for(ll i = 1; i <= n + 1; ++i) {
        a[i] = i;
        a[i] += a[i - 1];
    }

    for(ll m = k; m <= n + 1; ++m) {
        ll maxs = a[n] - a[max(0ll, n - m)], mins = a[m - 1];
        ans += maxs - mins + 1;
        ans %= MOD;
    }

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

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

namespace AtCoder {
    class Program {
        static void Main() {
            int n = int.Parse(Console.ReadLine());
            var list = new List<string>();
            for(int i = 0; i < n; i++) {
                list.Add(Console.ReadLine());
            }
            Console.WriteLine(list.Distinct().Count());
        }
    }
}

Measured memory_bytes: 47940
#include <bits/stdc++.h>
#define oo 1e18
using namespace std;

typedef long long ll;
const int N = 1e5 + 5;
int fax[N], fay[N], T, R, C, n;
ll mi1[N], mi2[N], wx[N], wy[N];
struct node {
	int x, y;
	ll val;
	void read( ) {
		scanf("%d%d%lld",& x,& y,& val);
	}
}P[N];

bool cmpx(const node & a, const node & b) {
	return a.x < b.x;
}

bool cmpy(const node & a, const node & b) {
	return a.y < b.y;
}

int find_x(int u) {
	
	if(fax[u] == u) return u;
	int rt = find_x(fax[u]);
	wx[u] += wx[fax[u]];
	return fax[u] = rt;
}

bool link_x(int u, int v, ll w) {
	
	int fu = find_x(u), fv = find_x(v);
	if(fu != fv) {
		fax[fu] = fv;
		wx[fu] = w + wx[v] - wx[u]; return true;
	}
	else return wx[u] == wx[v] + w;
}

int find_y(int u) {
	
	if(fay[u] == u) return u;
	int rt = find_y(fay[u]);
	wy[u] += wy[fay[u]];
	return fay[u] = rt;
}

bool link_y(int u, int v, ll w) {
	
	int fu = find_y(u), fv = find_y(v);
	if(fu != fv) {
		fay[fu] = fv;
		wy[fu] = w + wy[v] - wy[u]; return true;
	}
	else return wy[u] == wy[v] + w;
}

int main( ) {
	
	//freopen("then.in", "r", stdin);
	//freopen("then.out", "w", stdout);
	T = 1;
	while(T --) {
		bool tag = true;
		scanf("%d%d%d",& R,& C,& n);
		for(int i = 1;i <= R;i ++) {
			fax[i] = i; wx[i] = 0; 
		}
		for(int i = 1;i <= C;i ++) {
			fay[i] = i; wy[i] = 0;
		}
		for(int i = 1;i <= n;i ++) {
			P[i].read( );
			if(P[i].val < 0) tag = false;
		}
		sort(P + 1, P + n + 1, cmpx);
		for(int i = 1;i < n;i ++) {
			if(P[i].x == P[i + 1].x) 
				if(! link_y(P[i].y, P[i + 1].y, P[i + 1].val - P[i].val)) tag = false;
		}
		sort(P + 1, P + n + 1, cmpy);
		for(int i = 1;i < n;i ++) {
			if(P[i].y == P[i + 1].y)
				if(! link_x(P[i].x, P[i + 1].x, P[i + 1].val - P[i].val)) tag = false;
		}
		memset(mi1, 0x3f3f, sizeof(mi1));
		memset(mi2, 0x3f3f, sizeof(mi2));
		for(int i = 1;i <= n;i ++) {
			int rt = find_x(P[i].x);
			mi1[rt] = min(mi1[rt], P[i].val + wx[P[i].x]);
		}
		for(int i = 1;i <= R;i ++) {
			int rt = find_x(i);
			mi2[rt] = min(mi2[rt], -wx[i]);
		}
		ll cmp = oo;
		for(int i = 1;i <= R;i ++) cmp = min(cmp, mi1[i] + mi2[i]);
		if(cmp < 0) tag = false;
		if(tag) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

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

	int cnt = 0;
	while (true) {

		int be = -1;
		rep(i, n) {
			if (h[i] != 0) {
				be = i; break;
			}
		}
		if (be == -1)break;

		//cout << "begin:" << be << " -> ";

		//cnt++;
		for (int i = be; i < n; i++) {
			if (h[i] == 0)break;
			h[i]--;
		}

		//for (auto i : h)cout << i << " ";
		//puts("");

		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size
#define inf 1e9+5
 
 
int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> v(n + 1,0);
    ll a;
    for(ll i=0;i<q;i++){ cin>>a;
    
        v[a]++;
    }
    // cout<<"\n";
    for(ll i=1;i<=n;i++){
        // cout<<i<<" "<<k<<" "<<q<<" "<<v[i]<<"\n";
        if(k-(q-v[i])>0)cout<<"Yes\n";
        else
            cout<<"No\n";
    }

    return 0;  
}

Measured memory_bytes: 1408
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())
c = collections.Counter(prime_factorize(n))
# Counter({2: 3, 3: 1, 5: 1, 7: 1})

count = 0
for k, v in c.items():
    sum = 0
    for i in range(1, 10 ** 10):
        sum += i
        if sum > v:
            break
        count += 1
print(count)


Measured memory_bytes: 65860
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1000000007LL;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	}
	else if (a == 0 || b >= 0) {
		cout << "Zero" << endl;
	}
	else {
		if ((b - a + 1) % 2 == 0) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    
    vector<int> sum(n + 1, 0);
    REP(i, n) sum[i + 1] = (sum[i] + a[i]) % k;
    map<int, int> mp;
    ll ans = 0;
    REP(i, n + 1) {
        if (i >= k) {
            --mp[((sum[i - k] - (i - k)) % k + k) % k];
        }
        ans += mp[((sum[i] - i) % k + k) % k];
        ++mp[((sum[i] - i) % k + k) % k];
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 14352
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int dp[110][10010]={}; //[v][w]

int main() {
    int n,x;
    cin>>n>>x;
    VI l(n);
    rep(i,n) cin>>l[i];
    ll sum=0;
    int cnt=1;
    rep(i,n){
        sum+=l[i];
        if(x>=sum){
            cnt++;
        }
    }
    cout<<cnt<<endl;

}



Measured memory_bytes: 256
def Guidebook():
    n = int(input())
    rest = []
    for i in range(n):
        s, p = map(str, input().split())
        rest.append([i+1, s, int(p)])

    rest.sort(key=lambda x:x[2], reverse=True)
    rest.sort(key=lambda x:x[1])
    for i in range(n):
        print(rest[i][0])
if __name__ == "__main__":
    Guidebook()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(in.readLine());

      String line = in.readLine();
      int[] seq = new int[n];
      int[] ref = new int[n];
      char regex = ' ';
      boolean isContinue = true;
      for(int i=0, offset=0,next=0; isContinue; i++, offset = ++next) {
        if((next = line.indexOf(regex,offset)) == -1) {
          next = line.length();
          isContinue = false;
        }
        ref[i] = seq[i] = Integer.parseInt(line.substring(offset,next));
      }

      Arrays.parallelSort(ref);

      final int d = n>>1;
      StringBuilder buf = new StringBuilder();
      for(int i: seq) {
        if(i < ref[d] ) buf.append(ref[d]).append('\n');
        else buf.append(ref[d-1]).append('\n');
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

using namespace std;

const int md = 2019;

int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  return x;
}

int mul(int x, int y) {
  return (int)((long long)x * y % md);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  int dec = 1;
  int cur = 0;
  long long ans = 0;
  map<int, int> m;
  for (int i = n - 1; i >= 0; i--) {
    int dig = (s[i] - '0');
    cur = add(cur, mul(dec, dig));
    if (cur == 0) ans++;
    ans += m[cur];
    m[cur]++;
    dec = mul(dec, 10);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;

    int S = A[0] + A[1];
    int X = 0; FOR(i, 2, N) X ^= A[i];
    int C = (S - X) / 2;

    if(S < X || (S - X) % 2 != 0 || (X & C) != 0){
        Out(-1);
        return 0;
    }
    //debug(S); debug(X); debug(C);

    int ans = 0;
    REP(i, 60) if((C >> i) & 1) ans += bit(i);
    IREP(i, 60) if((X >> i) & 1){
        if(ans + bit(i) <= A[0]) ans += bit(i);
    }
    chOut(ans > 0 && ans <= A[0], A[0] - ans, -1);

    return 0;
}


Measured memory_bytes: 3660
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n=II()

	a=0
	b=0
	ab=0
	ans=0

	for _ in range(n):
		s=input().rstrip().decode()
		ans+=s.count("AB")
		if s[0]=="B" and s[-1]=="A":
			ab+=1
		elif s[0]=="B":
			b+=1
		elif s[-1]=="A":
			a+=1

	if ab==0:
		ans+=min(a,b)
	else:
		ans+=ab-1
		if not a==b==0:
			ans+=1+min(a,b)

	print(ans)







if __name__ == "__main__":
	main()


Measured memory_bytes: 9248
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  priority_queue<int, vector<int> > que;
  for (int i = 0; i < n; ++i) {
    que.push(a[i]);
  }
  for (int i = 0; i < m; ++i) {
    int v = que.top();
    que.pop();
    que.push(v / 2);
  }
  ll ans = 0;
  while (que.size()) {
    int v = que.top();
    que.pop();
    ans += v;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);

    rep(i, N) cin >> t[i];
    
    ll ans = T, now = T;
    repd(i, 1, N) {
        ans -= max(0LL, now - t[i]);
        ans += T;
        now = t[i] + T;
    }

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI  3.1415926535
#define rep(i, k, n) for(ll i = k; i < n; i++)

int main(){
  ll x; cin >> x;
  bool f = false;
  rep(i, -120, 121){
    rep(j, -120, 121){
      if(pow(i, 5) - pow(j, 5) == x){cout << i << " " << j << endl; f = true; break;}
    }
    if(f){break;}
  }
      
    
}






Measured memory_bytes: 4000
n = int(input())
li = list(map(int, input().split()))
ans = True
for i in li:
  if i % 2 == 1:
    continue
  else:
    if i % 3 != 0 and i % 5 != 0:
      ans = False
      break
if ans:
  print("APPROVED")
else:
  print("DENIED")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define INF 10000000
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
/*
struct unionfind{
    vector<int> par;

    unionfind(int N) : par(N){
        for(int i=0; i<N; i++) par[i]=i;
    }

    int root(int x){
        if(par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y){
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
};
*/
int main() {
    int N,Q;
    cin>>N>>Q;
    int a[N-1],b[N-1],p[Q],x[Q];
    rep(i,N-1) cin>>a[i]>>b[i];
    rep(i,Q) cin>>p[i]>>x[i];
    map<int,int> parent;
    rep(i,N-1) parent[b[i]]=a[i];
    ll counter[N+1]={};
    rep(i,Q) counter[p[i]]+=x[i];
    //幅優先で、親（一つ前の頂点の値を加算するようにする）
    for(int i=1; i<=N; i++){
        counter[i]+=counter[parent[i]];
    }
    for(int i=1;i<=N; i++) cout<<counter[i]<<" ";
    cout<<endl;
}


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

int main(){
    int n,c=0;
    cin >> n;

    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            for(int k=0; k<n; ++k){
                c++;
            }
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

const long d = 1000000007;
vector<int> a;

long checkReport(int n)
{
    long answer;
    int c;
    c = 0;
    sort(a.begin(), a.end());
    // n -> odd
    if(n % 2){
        for (int i=0; i<n; ++i){
            if(a[i] != c * 2){
                answer = 0;
                break;
            }
            if(i == n-1 && a[i] == c * 2){
                answer = 1;
                for (int j=0; j<(n-1)/2; ++j){
                    answer = (long)((long)(2 * answer) % (long)(d));
                }
            }
            if(i % 2 == 0){
                c++;
            }
        }
    }
    // n -> even
    else {
        for (int i=0; i<n; ++i){
            if(a[i] != c * 2 + 1){
                answer = 0;
                break;
            }
            if(i == n-1 && a[i] == c * 2 + 1){
                answer = 1;
                for (int j=0; j<n/2; ++j){
                    answer = (long)((long)(2 * answer) % (long)(d));
                }
            }
            if(i % 2 == 1){
                c++;
            }
        }
    }
    return answer;
}

int main()
{
    int n;
    cin >> n;
    a.resize(n);
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    cout << checkReport(n) << endl;
}


Measured memory_bytes: 640