akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

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

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    set<string> t;
    int n = s.length();
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k && i+j <= n; j++){
            t.insert(s.substr(i,j));
        }
    }
    auto it = t.begin();
    k--;
    while(k--){
        it++;
    }
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 4744
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=100+10;
int a[2][maxn];
int dp[2][maxn];
int main(){
	int n=read();
	REP(i,1,2)REP(j,1,n) a[i][j]=read();
	REP(i,1,2) REP(j,1,n){
		if(i==1 && j==1) dp[i][j]=a[i][j];
		else if(i==1) dp[i][j]=dp[i][j-1]+a[i][j];
		else if(j==1) dp[i][j]=dp[i-1][j]+a[i][j];
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
	}
	printf("%d\n",dp[2][n]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n-1];
    vector<int>boss(n,0);
    for(int i=0;i<n-1;i++){
        cin>>a[i];
        boss[a[i]-1]++;
    }
    for(int i=0;i<n;i++)cout<<boss[i]<<endl;
    return 0;
}

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

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

   int N, Y;
   cin >> N >> Y;
   Y /= 1000;
   int c10 = -1, c5 = -1, c1 = -1;
   for (int x = 0; x <= N; x++) {
      for (int y = 0; y <= N; y++) {
         if (Y - (10 * x + 5 * y) == (N - x - y) && Y - (10 * x + 5 * y) >= 0) {
            c10 = x;
            c5  = y;
            c1  = Y - (10 * x + 5 * y);
         }
      }
   }
   cout << c10 << " " << c5 << " " << c1 << endl;
}

Measured memory_bytes: 256
import numpy as np
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9+7
P = np.empty((404, 404), dtype=np.int64)
P[0, :] = 1
ar = np.arange(404, dtype=np.int64)
for i in range(1, 404):
    P[i] = P[i-1] * ar % mod
# この時点で  # P[i, c] = i**c % mod

P = P.cumsum(axis=1, dtype=np.int64) % mod  # P[i, c] = Σ_{k=0}^i k**c % mod
P = P.T

dp = np.zeros(C+1, dtype=np.int64)
dp[0] = 1
for a, b in zip(A, B):
    dp_new = np.zeros(C+1, dtype=np.int64)
    p = (P[b] - P[a-1]) % mod
    for c in range(C+1):
        dp_new[c] = (dp[:c+1] * p[c::-1] % mod).sum()
    dp = dp_new % mod
print(dp[C])


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

int vacation(int arr[][3],int n){
	int dp[n][3];
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for (int i=1;i<n;i++){
		dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
	}
	return max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}




int main(){
	int n;
	cin>>n;
	int arr[n][3];
	for (int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		arr[i][0]=a;
		arr[i][1]=b;
		arr[i][2]=c;
	}
	cout<<vacation(arr,n);
	return 0;
}



Measured memory_bytes: 5972
from heapq import *
import sys
input = sys.stdin.readline
INF = 10 ** 18                                          # 大きい数字

def dijkstra(V, E, G, s):                               # V:頂点数 E:辺の数 G: 隣接する頂点とその重さのリスト s:スタート地点
    d = [INF]*V                                         # 各頂点までの最短距離
    d[s] = 0                                            # 自身への距離は0
    next_set = [(0, s)]                                 # 次に進む候補の頂点と、"スタート地点"からその頂点まで進む距離
                                                        # 始めはスタート地点からスタート地点なので、距離は0
                                                        # heqpq の比較のための key は第一引数である点に注意（ =　heappush(heapq, (key,value))　）
    while next_set:
        dist, p = heappop(next_set)                     # 近いところから順に確定させていく必要があるため、heappop を用いる
        if d[p] < dist:
            continue
        for q, cost in G[p]:                            # p と隣接する点 q と p-q 間の距離
            temp_d = dist + cost                        # スタート地点から p を介して q まで行った時の距離
            if temp_d < d[q]:                           # q まで行く最小距離の更新
                d[q] = temp_d
                heappush(next_set, (temp_d, q))         # q を介して他の頂点に行く可能性を考える。q に行くまでの最短距離が明らかになっている点が重要
    return d

#####( main )#########################################################################################################################

V, E, s = map(int, input().split())
G = [[] for _ in range(V)]
for _ in range(E):
    p,q,dist = map(int, input().split())
    # G[p-1].append((q-1, dist))
    # G[q-1].append((p-1, dist))                          # 有効グラフの場合、コメントアウトする

    G[p].append((q, dist))                            # デクリメントが不要な場合はコメントアウトを消す
    # G[q].append((p, dist))

for dist in dijkstra(V,E,G,s):
    if dist == INF:
        print("INF")
    else:
        print(dist)


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

typedef long long ll;
typedef long double ld;
#define umap unordered_map
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "Yes": "No") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const ll inf = 0x3f3f3f3f;

template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; }

void dfs(int curr, vector<vector<int>> &graph, vector<bool> &visited) {
	visited[curr] = true;
	for (int neighbor : graph[curr]) {
		if (!visited[neighbor]) dfs(neighbor, graph, visited);
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m; cin >> n >> m;
	vector<bool> visited(n+1,false);
	vector<vector<int>> graph(n+1, vector<int>());
	for (int i = 0; i<m; i++) {
		int u,v; cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	int comp_cnt = 0;
	for (int i = 1; i<=n; i++) {
		if (!visited[i]) {
			dfs(i, graph, visited);
			comp_cnt++;
		} 
	}
	cout << comp_cnt - 1 << '\n';
}



Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i(a), i##_END_(b); i <= i##_END_; i++) 
#define drep(i, a, b) for(int i(a), i##_END_(b); i >= i##_END_; i--)
using namespace std;
template<class T> inline bool tomax(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T> inline bool tomin(T &a, T b) {return b < a ? a = b, 1 : 0;}
typedef long long ll;
typedef double db;

int x[105][105];
bool mark[(int) 1e6 + 100];

int P2(int x) {
    return x * x;
}

int main() {
    int n, d;
    scanf("%d%d", &n, &d);
    rep(i, 1, n) 
        rep(j, 1, d)
            scanf("%d", &x[i][j]);
    rep(i, 0, 1e3) mark[i * i] = true;
    int ans = 0;
    rep(i, 1, n)
        rep(j, i + 1, n) {
            int sum = 0;
            rep(k, 1, d)
                sum += P2(x[i][k] - x[j][k]);
            ans += mark[sum];
        }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1280
#coding:UTF-8
def Rec(N,List):
    for i in range(N):
        a=int(List[i].split(" ")[0])
        b=int(List[i].split(" ")[1])
        c=int(List[i].split(" ")[2])
        if a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a:
            print("YES")
        else:
            print("NO")

if __name__=="__main__":
    List=[]
    N=int(input())
    for i in range(N):
        List.append(input())
    Rec(N,List)

Measured memory_bytes: 7692
N = int(input())
H = list(map(int, input().split()))
C = [10**13 for i in range(N)]
C[0] = 0
for i in range(N):
    if i+1 < N:
        C[i+1] = min(C[i] + abs(H[i+1]-H[i]), C[i+1])
    if i+2 < N:
        C[i+2] = min(C[i] + abs(H[i+2]-H[i]), C[i+2])
print(C[-1])


Measured memory_bytes: 13928
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
    int N, M;

    while(cin >> N >> M){
        if(N ==0) break;
        UnionFind<int> UF(N);
        for(int i=0; i<M; ++i){
            char sign;
            int l, r, w;
            cin >> sign;
            if(sign=='?'){
                cin >> l >> r;
                --l, --r;
                if(!UF.issame(l, r)){
                    puts("UNKNOWN");
                }else{
                    cout << UF.diff(l, r) << endl;
                }
            }else{
                cin >> l >> r >> w;
                --l, --r;
                UF.merge(l, r, w);
            }
        }
    }    
}


Measured memory_bytes: 4144
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000003LL)
typedef long long Int;

int n, mi, memo[60000*4], cs[60000][2];
vector<int> g[60000];
bool has[60000];

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
}

int pre(int p, int q) {
    if (p+1 == q) return -1;
    const int k = mi++;
    has[k] = false;
    if (g[p].back() == q) {
        has[k] = true;
        g[p].pop_back();
    }
    const int r = g[p].back();
    rep (b, 4) memo[k*4|b] = -1;
    cs[k][0] = pre(p, r);
    cs[k][1] = pre(r, q);
    return k;
}

int rec(int k, int x, int y) {
    if (k == -1) return x == y;
    const int sig = k*4|x*2|y;
    if (memo[sig] != -1) return memo[sig];
    const int p = cs[k][0], q = cs[k][1];
    Int ans = 0;
    rep (i, 2) ans = (ans + (Int)rec(p, x, i)*rec(q, 1-i, y)) % MOD;
    if (x && y && has[k]) {
        rep (i, 2) ans = (ans + (Int)rec(p, 0, i)*rec(q, 1-i, 0)) % MOD;
    }
    return memo[sig] = ans;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (i, n-1) g[i].push_back(i+1);
        rep (_, m) {
            scanf("%d%d", &a, &b);
            add(a-1, b-1);
        }
        rep (i, n-1) sort(g[i].begin()+1, g[i].end());
        sort(g[n-1].begin(), g[n-1].end());
        g[0].push_back(n-1);
        mi = 0;
        pre(0, n-1);
        printf("%d\n", rec(0, 1, 1));
    }
}

Measured memory_bytes: 12632
package main

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

var scanner *bufio.Scanner

func nextInt() int {
	scanner.Scan()

	var i, _ = strconv.Atoi(scanner.Text())

	return i
}

func nextString() string {
	scanner.Scan()

	return scanner.Text()
}

func initScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

// math functuon
func maxInt(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}
func minInt(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

// 階乗
func factorial(n int64) int64 {
	if n < 1 {
		return 1
	}

	return n * factorial(n-1)
}

// 順列
func permutation(n, k int64) int64 {
	return factorial(n) / factorial(n-k)
}

// 組み合わせ
func combination(n, k int64) int64 {
	if k == 0 || k == n {
		return 1
	}

	return permutation(n, k) / factorial(k)
}

// logger
var isDebug = true

func log(format string, args ...interface{}) {
	if !isDebug {
		return
	}

	fmt.Printf(format+"\n", args...)
}

func main() {
	var debugFlag = flag.Bool("debug-mode", false, "debug flag")
	flag.Parse()
	isDebug = *debugFlag

	initScanner()

	var n, x = nextInt(), nextInt()

	var sum = 0
	var count = 1
	for i := 0; i < n; i++ {
		var l = nextInt()
		if sum+l > x {
			break
		}

		count++
		sum += l
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int n,k,x,y;
	int ans=0;
	scanf("%d %d %d %d",&n,&k,&x,&y);
	if(n>k){
		ans=k*x+(n-k)*y;
	}else{
		ans=n*x;
	}
	printf("%d",ans);

	
	return 0;
}

Measured memory_bytes: 128
H,W = map(int,input().split())
S = [["."] * (W+2)]
for i in range(H):
    S.append(list("."+input().rstrip()+"."))
S.append(["."]*(W+2))
#print(S)

def checkaround(i,j):
    dirc = [[0,1],[-1,0],[0,-1],[1,0]]
    for d in dirc:
        if S[i-d[0]][j-d[1]] == "#":
            return True
    return False
def main():
    for i in range(1,H+1):
        for j in range(1,W+1):
            if S[i][j] == "#":
                if not checkaround(i,j):
                    print("No")
                    return
    print("Yes")

main()

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

using namespace std;
using ll = long long;

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

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

  if (n % 2 == 1) {
    puts("No");
    return 0;
  }

  string t = s.substr(0, n / 2);
  if (t + t == s)
    puts("Yes");
  else
    puts("No");
  return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N+1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    if (M%2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> par(N+1, 0);
    par[1] = -1;
    queue<int> q;
    q.push(1);
    vector<int> tp;
    tp.push_back(1);
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (par[nxt] == 0) {
                par[nxt] = now;
                q.push(nxt);
                tp.push_back(nxt);
            }
        }
    }
    vector<pair<int, int>> ans;
    vector<int> go(N+1, 0);
    for (int i = 1; i <= N; i++) {
        for (int j : edge[i]) {
            if (par[i] == j || par[j] == i) continue;
            if (i < j) {
                ans.push_back({i, j});
                go[i]++;
            }
        }
    }
    for (int i = (int)tp.size()-1; i >= 1; i--) {
        if (go[tp[i]]%2 == 0) {
            ans.push_back({par[tp[i]], tp[i]});
            go[par[tp[i]]]++;
        }
        else {
            ans.push_back({tp[i], par[tp[i]]});
            go[tp[i]]++;
        }
    }
    
    for (auto p : ans) {
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 8956
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
def k(H,cx,cy,f):
    for x,y,h in f:
        if h==max(H-abs(x-cx)-abs(y-cy),0):
            continue
        else:
            return
    print(cx,cy,H)
    exit()
for x,y,h in f:
    if h==0:
        continue
    for cx in range(101):
        for cy in range(101):
            H=h+abs(x-cx)+abs(y-cy)
            k(H,cx,cy,f)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;cin>>a>>b>>c;
  ll ans=c;
  ll aki=c;
  ll sa=a-b;
  ans%=MOD;
  ll nm=(max(0LL,c-a+1))/(sa)+(max(c-a+1,0LL)%sa!=0);
  cout<<(ans+(nm%MOD)*(b%MOD))%MOD<<endl;
  return 0;
}



Measured memory_bytes: 3184
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp;
  if (n[0] == n[2]) {
    writeln("Yes");
  }  else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,v,p;
	cin>>n>>m>>v>>p;
	vl a(n);
	rep(i,n)cin>>a[i];
	sort(all(a));
	ll ok=n-1,ng=-1;
	while(ok-ng>1){
		ll mid=(ok+ng)/2;
		ll z=max(0ll,v-(mid+1)-(p-1));
		ll tar=mid+1;
		ll sum=z*m;
		//puta(mid,z,sum);
		for(;tar<=n-p;tar++){
			ll sub=a[mid]+m-a[tar];
			ll dif=min(sum,min(sub,m));
			sum-=dif;
		}
		//puta("!",sum,a[n-p]-sum,a[mid]+m);
		if(sum>0||a[n-p]+sum>a[mid]+m){
			ng=mid;//puta(mid,"f");
		}
		else{
			ok=mid;//puta(mid,"t");
		}
	}
	cout<<n-ok<<endl;;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,k;
int main()
{
	cin >>n>>m>>k;
	cout <<(n+m+k>=22 ? "bust" : "win");
	return 0; 
} 

Measured memory_bytes: 256
N, L = map(int, input().split())
A = [L+i for i in range(N)]
total = 0
min_abs = 301

for i in range(N):
    total += A[i]
    if min_abs > abs(A[i]):
        min_abs = abs(A[i])
        idx = i

print(total - A[idx])


Measured memory_bytes: 61724
import java.io.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] input = new String[100]; //入力を受け取る変数
		String output = "";	//出力する文字列を代入する変数
		int 	r,	//行数の変数
				c;	//列数の変数
		
		try{
			input = br.readLine().split("[\\s]+");	//1行目の入力
			
			r = Integer.parseInt(input[0]);	//行数(入力レコード数)を記録
			c = Integer.parseInt(input[1]);	//列数を記録
			
			int table[][] = new int[r+1][c+1];	//表の内容を記録する変数
			
			for(int y = 0;y < r;y++){	//入力レコード数分繰り返す
			
				input = br.readLine().split("[\\s]+");	//2行目以降の入力
				
				for(int x = 0;x < c;x++){	//列数分繰り返す
				
					table[y][x] = Integer.parseInt(input[x]);	//x列目のデータを格納
					
					table[y][c] += table[y][x];	//最後列(行の合計)に値を加算
				}
			}
			
			//最下行(列の合計)の計算
			for(int x = 0;x < c+1;x++){	//条件x < c+1は最後の行合計値を表全体の合計に代入するため
			
				for(int y = 0;y < r;y++){
					
					table[r][x] += table[y][x];	//最下行(列合計)に値を加算
				}
			}
			
			//出力用のループ
			for(int y = 0;y < r+1;y++){
				
				for(int x = 0;x < c+1;x++){
					
					output += table[y][x] + " ";	//出力する数字+スペースを末尾に足す
				}
				System.out.println(output.substring(0, output.length()-1));	//無駄に挿入されたスペースを取り除き出力する
				output = "";
			}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	}
}



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

typedef long long ll;

int main() {
    ll N, ans = 1, MOD = 1e9 + 7;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        ans = (ans * i) % MOD;
    }
    cout << ans << "\n";
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	string s,t;
  	cin >> s >> t;
  	int c=0;
  	for(int i=0;i<s.length();i++)
      if(s[i]!=t[i])
        c++;
  	cout << c;
    return 0;
}

Measured memory_bytes: 3768
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll k;cin>>k;
	string s;cin>>s;
	if(sz(s)<=k) cout<<s;
	else cout<<s.substr(0,k)<<"...";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3656
#include <cstdlib>
#include <cstring>
#include <cstdio>
bool vis[15];
int ano[15], n, m; 
char str[15][15]; 
inline bool chk(int x, int y)
{
	for (int i = 0; i < m; i++)
	{
		if (str[x][i] != str[y][ano[i]])
			return false; 
	}
	return true;
}
inline void work()
{
	bool flg = false; 
	memset(vis, false, sizeof(vis)); 
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue; 
		for (int j = i + 1; j < n && !vis[i]; j++)
		{
			if (!vis[j] && chk(i, j))
				vis[i] = vis[j] = true; 
		}
		if (!vis[i] && (n & 1) && chk(i, i) && !flg)
			vis[i] = flg = true; 
		if (!vis[i])
			return; 
	}
	puts("YES"); 
	exit(0); 
}
void dfs(int cur, bool rem)
{
	if (cur >= m / 2 && !rem)
	{
		work(); 
		return; 
	}
	int pos = -1; 
	for (int i = 0; i < m; i++)
	{
		if (-1 == ano[i])
		{
			pos = i; 
			break; 
		}
	}
	if (rem)
	{
		ano[pos] = pos; 
		dfs(cur, false); 
		ano[pos] = -1; 
	}
	for (int j = pos + 1; j < m; j++)
	{
		if (~ano[j])
			continue; 
		ano[pos] = j; 
		ano[j] = pos; 
		dfs(cur + 1, rem); 
		ano[pos] = ano[j] = -1; 
	}
}
int main()
{
	// freopen("ARC095-E.in", "r", stdin); 
	// freopen("ARC095-E.out", "wt", stdout); 
	scanf("%d%d", &n, &m); 
	for (int i = 0; i < n; i++)
		scanf("%s", str[i]); 
	memset(ano, -1, sizeof(ano)); 
	dfs(0, m & 1); 
	puts("NO"); 
	return 0; 
}


Measured memory_bytes: 128
use text_io::*;
use std::process::exit;

fn main() {
    let a:String = read!();
    let b:String = read!();
    let mut va:Vec<char> = a.chars().collect();
    let mut vb:Vec<char> = b.chars().collect();
    let mut n:usize = 0;
    for i in 0..va.len() {
        if va[i] != vb[i] {
            n += 1;
        }
    }
    println!("{}",n);
}


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

int ar[100001];

int main()
{
    int N,temp;
    cin>>N;
    int cnt=0;
    for(int i=0; i<N; i++)
    {

        cin>>temp;
        if(temp>100000) cnt++;
        else ar[temp]++;
    }

    for(int i=1; i<100001; i++)
    {
        if(ar[i]>=i) cnt+=(ar[i]-i);
        else cnt+=ar[i];
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>vi;
vector<ll> :: iterator vt;
ll arr[200009];
int main()
{
    ll x,n,t,mul=1,i,j,flag =0,maxi=LONG_LONG_MIN ,mini=LONG_LONG_MAX,sum=0,c=0;
    map<char,ll>mp;
    map<char,ll> :: iterator mt;
    string s, ss;
    cin>>s;
    cin>>n;
    for(i = 0 ;i<s.size() ;i++)
    {
        if(s[i]!='1'){
            x=s[i]-48;
            break;
        }
    }
    if(n<=i)
        cout<<s[0]<<endl;
    else
    cout<<x<<endl;
    //cout<<n<<" "<<i<<endl;


   return 0;
}


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

string S;

map<string, int> m;

int main()
{

	m.insert(make_pair<string,int>("SUN",7));
	m.insert(make_pair<string, int>("MON", 6));
	m.insert(make_pair<string, int>("TUE", 5));
	m.insert(make_pair<string, int>("WED", 4));
	m.insert(make_pair<string, int>("THU", 3));
	m.insert(make_pair<string, int>("FRI", 2));
	m.insert(make_pair<string, int>("SAT", 1));

	cin >> S;
	
	int ans = m.at(S);

	cout << ans << 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;
//using ll = long long;
//using P = pair<int,int>;

int main(){
  string a,b;
  int counts = 0;
  cin >> a >> b;
  rep(i,a.size()){
   if(a.at(i) != b.at(i)) counts++;
  }
  if(counts != 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin >> h[i];
    h.push_back(0);
    
    int ans = h[0];
    for(int i = 0;i < n;i++){
        if(h[i+1]-h[i] > 0) ans += h[i+1]-h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int h, w, n; cin >> h >> w >> n;
	int r, c; cin >> r >> c;
	string s, t; cin >> s >> t;
	int now = r;
	rep(i, n)
	{
		if (s[i] == 'U')
		{
			--now;
			if (now <= 0)
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		if (t[i] == 'D')now = min(now + 1, h);
	}
	now = r;
	rep(i, n)
	{
		if (s[i] == 'D')
		{
			++now;
			if (now > h)
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		if (t[i] == 'U')now = max(now - 1, 1);
	}
	now = c;
	rep(i, n)
	{
		if (s[i] == 'L')
		{
			--now;
			if (now <= 0)
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		if (t[i] == 'R')now = min(now + 1, w);
	}
	now = c;
	rep(i, n)
	{
		if (s[i] == 'R')
		{
			++now;
			if (now > w)
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		if (t[i] == 'L')now = max(now - 1, 1);
	}
	cout << "YES" << endl;
}

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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;
signed main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll d = 10e9;
  ll k;
  x *= 2;
  y *= 2;
  rep(i, max(x, y)+1) {
    k=i*c + a*max((ll)0,(x-i+1)/2) + b*max((ll)0,(y-i+1)/2);
    //cout << i << " " << k << endl;
    d = min(d, k);
  }
  cout << d;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の
string型配列と同じような感じ） map<int, string> mp; for (auto itr =mp.begin();
itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3588
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
using mint = modint998244353;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<mint> A(N);
  REP(i, N) {
    int a;
    cin >> a;
    A[i] = a;
  }
  vector<mint> B(M);
  REP(i, M) {
    int b;
    cin >> b;
    B[i] = b;
  }
  auto conv = convolution(A, B);
  REP(i, conv.size()) cout << conv[i].val() << (i!=conv.size()-1 ? " " : "");
  cout << "\n";
}

Measured memory_bytes: 19016
mult :: [Int] -> [Int] -> Int
mult [] [] = 0
mult (a:as) (b:bs) = a*b+(mult as bs)

count :: Int -> Int -> [Int] -> IO Int
count 0 _ _  = return 0
count i c bs = do
  as <- map read.words <$> getLine
  n <- count (i-1) c bs
  if mult as bs > (-c) then return $ 1 + n
    else return n

main :: IO ()
main = do
  [n,m,c] <- map read.words <$> getLine
  bs <- map read.words <$> getLine
  ans <- count n c bs
  putStrLn $ show $ ans


Measured memory_bytes: 1020
#include <stdio.h>
#include <vector>
 
using namespace std;
 
struct Node{
    Node(){
        parent = -1;
        depth = num_of_children = 0;
    }
    int parent;
    int depth;
    vector<int> children;
    int num_of_children;
};
 
void calcDepth(Node nodes[],int root_id){
    for(int i = 0;i < nodes[root_id].num_of_children;i++){
        nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
        calcDepth(nodes,nodes[root_id].children[i]);
    }
}
 
int main(){
    int n,id,k,child_id,root_id;
    scanf("%d",&n);
    Node nodes[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d %d",&id,&k);
        for(int j = 0; j < k; j++){
            scanf("%d",&child_id);
            nodes[id].children.push_back(child_id);
            nodes[id].num_of_children++;
            nodes[child_id].parent = id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(nodes[root_id].parent == -1) break;
    }
 
    calcDepth(nodes,root_id);
 
    for(int i = 0; i < n; i++){
        if(nodes[i].parent == -1){
            printf("node %d: parent = -1, depth = 0, root, ",i);
        }else if(nodes[i].num_of_children == 0){
            printf("node %d: parent = %d, depth = %d, leaf, ",i,nodes[i].parent,nodes[i].depth);
        }else{
            printf("node %d: parent = %d, depth = %d, internal node, ",i,nodes[i].parent,nodes[i].depth);
        }
        printf("[");
        for(int j = 0; j < nodes[i].num_of_children-1; j++){
            printf("%d, ",nodes[i].children[j]);
        }
        if(nodes[i].num_of_children > 0){
            printf("%d",nodes[i].children[nodes[i].num_of_children-1]);
        }
        printf("]\n");
    }
}


Measured memory_bytes: 7488
#include<iostream>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#include<string>
#include<set>
using namespace std;

set<int> S;
int main(){
    int n, x;
    cin >> n;
    while(n --){
        cin >> x;
        if(S.count(x)){
            S.erase(x);
        }else{
            S.insert(x);
        }
    }
    cout << S.size() << endl;
}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

int main(void){
    ll a,b,c;
    cin >> a >>b >>c;
    for(ll i = 1;i <= b;i++){
        ll mul = a * i;
        if(mul % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)

for i in A:
    d[i] += 1

ans = 0
for k,v in d.items():
    if v > k:
        ans += v - k
    elif v < k:
        ans += v
print(ans)

Measured memory_bytes: 22440
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
ll arr[305];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	ll sum=0;
	rep(x,0,n){
		cin>>arr[x];
		
		if (2<=x) sum^=arr[x];
	}
	
	ll a=0,b=0;
	ll left=arr[0]+arr[1];
	for (ll val=(1LL<<40);val;val>>=1){
		if (sum&val){ //either put 1 in a or b
			b+=val;
			left-=val;
		}
		else{
			if (left>=val*2){
				a+=val;
				left-=val*2;
			}
		}
	}
	
	ll ans=a;
	for (ll val=(1LL<<40);val;val>>=1){
		if (b&val && ans+val<=arr[0]){
			ans+=val;
		}
	}
	
	if (a*2+b==arr[0]+arr[1] && 0<ans && ans<=arr[0]) cout<<arr[0]-ans<<endl;
	else cout<<"-1"<<endl;
	//cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(){
  long long n,m;
  scanf("%lld %lld",&n,&m);
  if(m==1)printf("%lld\n",(n*(n-1))/2);
  else{
    n-=m-2;
    printf("%lld\n",(n*(n-1))/2+m-3);
  }
  return 0;
}

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

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

using ll = long long;
using ull = unsigned long long;

int main() {
  queue<pair<string, int> > Q;
  queue<pair<string, int> > ans;
  int n, q;
  cin >> n >> q;
  rep(i, n) {
    pair<string, int> p;
    cin >> p.first >> p.second;
    Q.push(p);
  }
  int time = 0;
  while (!Q.empty()) {
    if (Q.front().second <= q) {
      pair<string, int> p = Q.front(); Q.pop();
      time += p.second;
      p.second = time;
      ans.push(p);
    } else {
      pair<string, int> p = Q.front(); Q.pop();
      time += q;
      p.second -= q;
      Q.push(p);
    }
  }
  rep(i, n) {
    cout << ans.front().first << ' ' << ans.front().second << endl;
    ans.pop();
  }
  return 0;
}



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

int H, W, a[501][501];
vector<vector<int>>movess;

/// Returns true if x is an even number.
bool fe(int x) { return x % 2 == 0; }
/// Returns true if x is an odd number.
bool fo(int x) { return x % 2 == 1; }

/// Prints.
bool fp() {
  printf("##### fp()\n");
  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W; w++) {
      printf("%d ", a[h][w]);
    }
    printf("\n");
  }
}

main() {
  cin >> H >> W;
  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W; w++) {
      cin >> a[h][w];
    }
  }
  // fp();
  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W - 1; w++) {
      if (fo(a[h][w])) {
        movess.push_back({h, w, h, w+1});
        a[h][w]--;
        a[h][w+1]++;
      }
    }
  }
  // fp();
  for (int h = 1; h <= H - 1; h++) {
    if (fo(a[h][W])) {
      movess.push_back({h, W, h+1, W});
      a[h][W]--;
      a[h+1][W]++;
    }
  }
  // fp();
  printf("%d\n", (int)movess.size());
  for (auto& xs : movess) {
    printf("%d %d %d %d\n", xs[0], xs[1], xs[2], xs[3]);
  }
}

Measured memory_bytes: 9904
#include "bits/stdc++.h"
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

void solve(){
	int h,w,k ;
	cin >> h >> w >> k ;
	vector<string> a(h) ;
	for(int i = 0 ; i < h ; i++){
		cin >> a[i] ;
	}
	int ans = 0 ;
	for(int i = 0; i < 1<<h ; i++){
		for(int j = 0 ; j < 1<<w ; j++){
			int cnt = 0 ;
			for(int x = 0 ; x < h ; x++){
				for(int y = 0 ; y < w ; y++){
					if((i&(1<<x)) || (j&(1<<y)) || (a[x][y]=='.')) continue ;
					cnt++ ;
				}
			}
			if(cnt == k) ans++ ;
		}
	}
	cout << ans << endl ;
}

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	FAST_IO ;
	int tt = 1;
//	cin >> tt ;
	while(tt--){
		solve() ;
	}
}


Measured memory_bytes: 3620
N = int(input())
if 0<=N<=9:
    print(N)
elif 10<=N<=99:
    print(9)
elif 100<=N<=999:
    print(N-99+9)
elif 1000<=N<=9999:
    print(9+999-99)
elif 10000<=N<=99999:
    print(N-9999+909)
else:
    print(90909)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll mod = 998244353;
int main(){ 
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));

  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      (dp[i + 1][j] += dp[i][j] * 2 % mod) %= mod;
      if (j + a[i] <= s) {
        (dp[i + 1][j + a[i]] += dp[i][j]) %= mod;
      }
    }
  }
  
  cout << dp[n][s] << endl;

  return 0;
} 

Measured memory_bytes: 73692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll k,n;cin>>n>>k;
    vector<ll> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    vector<ll> nx=x,ny=y;
    sort(nx.begin(),nx.end());
    sort(ny.begin(),ny.end());
    ll res=5e18;
    rep(xl,n)rep(xr,n)rep(yl,n)rep(yr,n){
        ll lx=nx[xl],ly=ny[yl],rx=nx[xr],ry=ny[yr];
        ll bufm=abs(rx-lx)*abs(ry-ly);
        ll buf=0;
        rep(i,n){
            ll bufx=x[i],bufy=y[i];
            if(lx<=bufx&&bufx<=rx&&ly<=bufy&&bufy<=ry)buf++;
        }
        //cout<<(rx-lx)<<" "<<(ry-ly)<<" "<<bufm<<endl;
        if(buf>=k)chmin(res,bufm);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<string> name(n);
        vector<vector<bool> > time(n, vector<bool>(30, false));
        vector<int> point(30, n+1);
        for(int i=0; i<n; ++i){
            int m;
            cin >> name[i] >> m;
            for(int j=0; j<m; ++j){
                int d;
                cin >> d;
                time[i][d] = true;
                -- point[d];
            }
        }

        pair<int, string> ret(INT_MAX, "");
        for(int i=0; i<n; ++i){
            pair<int, string> p(0, name[i]);
            for(int j=0; j<30; ++j){
                if(time[i][j])
                    p.first += point[j];
            }
            ret = min(ret, p);
        }
        cout << ret.first << ' ' << ret.second << endl;
    }
}

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

int main() {
    int K, N, ans = 0, max = 0;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        int dis;
        if (i < N - 1) {
            dis = A[i + 1] - A[i];
        } else {
            dis = K - A[i] + A[0];
        }
        if (dis > max) {
            max = dis;
        }
        ans += dis;
    }

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


Measured memory_bytes: 1024