akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n;
    set<int> st;
    cin >> n;
    REP(i, n) {
        int t;
        cin >> t;
        st.insert(t);
    }
    int ans = st.size();
    if (ans % 2 != n % 2) ans--;
    cout << ans << endl;
    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

#define MAXN 100005

int m;

int add(int a, int b) {
    a += b;
    if (a >= m)
        a -= m;
    return a;
}

void mul(int &a, int b) {
    a = (long long) a * b % m;
}

int dp[MAXN], ret[MAXN];
vector<int> adj[MAXN], all[MAXN];

void dfs1(int u, int p) {
    dp[u] = 1;
    for (int v : adj[u])
        if (v != p) {
            dfs1(v, u);
            mul(dp[u], add(dp[v], 1));
            all[u].push_back(add(dp[v], 1));
        }
}

void dfs2(int u, int p, int top = 1) {
    ret[u] = dp[u];
    mul(ret[u], top);
    vector<int> suff(all[u].size() + 1);
    suff[all[u].size()] = 1;
    for (int i=(int)all[u].size()-1; i>=0; i--) {
        suff[i] = all[u][i];
        mul(suff[i], suff[i+1]);
    }
    int pref = top, i = 0;
    for (int v : adj[u])
        if (v != p) {
            top = pref;
            mul(top, suff[i+1]);
            dfs2(v, u, add(top, 1));
            mul(pref, all[u][i++]);
        }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n >> m;
    for (int i=0; i<n-1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs1(0, -1);
    dfs2(0, -1);

    for (int i=0; i<n; i++)
        cout << ret[i] << "\n";

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  double a, b;
  double amax, amin, bmax, bmin;
  cin >> a >> b;

  amin = a * 12.5;
  amax = (a+1) * 12.5 -1; 
  bmin = b * 10;
  bmax = (b+1) * 10 -1;
  
  amin = (int)(amin + 0.9);
  amax = (int)(amax + 0.9);
  
  
  if((bmax < amin) || (amax < bmin)){
    cout << -1 << endl;
  }
  else if(amin <= bmin){
    cout << bmin << endl;
  }
  else{
    cout << amin << endl;
  }

}




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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

string s,t;

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

	cin>>s>>t;
	reverse(ALL(t));
	if(s==t) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


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

int main()
{
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  bool can = false;
  int con_stone = 1;
  int now_stone = 1;
  if (A < B and C < D)
  {
    for (int i = A; i < D - 1; i++)
    {
      if (S.at(i) == '#' and S.at(i - 1) == '#')
        now_stone++;
      if (S.at(i) == '.')
      {
        con_stone = max(con_stone, now_stone);
        now_stone = 1;
      }
    }
    con_stone = max(con_stone, now_stone);
    if (con_stone < 2)
      can = true;
  }
  else if (A < B and D < C)
  {
    for (int i = A; i < C - 1; i++)
    {
      if (S.at(i) == '#' and S.at(i - 1) == '#')
        now_stone++;
      if (S.at(i) == '.')
      {
        con_stone = max(con_stone, now_stone);
        now_stone = 1;
      }
    }
    con_stone = max(con_stone, now_stone);
    bool exist = false;
    for (int i = B - 1; i <= D - 1; i++)
    {
      if (S.at(i - 1) == '.' and S.at(i) == '.' and S.at(i + 1) == '.')
        exist = true;
    }
    if (con_stone < 2 and exist)
      can = true;
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

    bool dp[101][10001] = {};
    dp[0][0] = true;

    int x;
    for(int i = 0; i < n; i++){
        cin >> x;

        for(int j = 0; j <= 10000; j++){
            if(dp[i][j]){
                dp[i+1][j] = true;
                if(j + x <= 10000){
                    dp[i+1][j+x] = true;
                }
            }
        }

    }

    for(int j = 10000; j > 0; j--){
        if(dp[n][j] && j % 10 != 0){
            cout << j << endl;
            return 0;
        }
    }

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

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt() - (i+1); // 予めAi - i = a[i]としておく
		}
		// 中央値を取るためにソート
		Arrays.sort(a);
		// 数直線上にa[i]をプロットしたときに、bを動かしたときに影響を受けるa[i]が左右で同数ならOK
		// aが奇数個なら中央値は常にa[(N+1)/2 - 1]
		// aが偶数個の場合、中央の2つの値a[N/2 - 1],a[N/2]の間ならbはどこに取っても良い。
		// 公式の解説放送参照 https://www.youtube.com/watch?v=UX4AuiCVtN4
		int b = 0;
		if (N%2 != 0) {
			b = a[(N+1)/2 - 1];
		} else {
			b = (a[N/2 - 1] + a[N/2])/2;
		}
		long sadness = 0;
		for (int i = 0; i < N; i++) {
			sadness += Math.abs(a[i] - b);
		}
		System.out.println(sadness);
	}
}

Measured memory_bytes: 64468
INF = 10 ** 9
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [INF] * (h + 1)
dp[0] = 0

for i in range(h + 1):
    for damage, mp in ab:
        rep = INF
        if (0 <= (i - damage)):
            rep = dp[i - damage] + mp
        else:
            rep = mp
        dp[i] = min(dp[i], rep)
print(dp[h])


Measured memory_bytes: 42476
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N%2==1:
    print(B[N//2]-A[N//2]+1)
else:
    A_chu=(A[N//2-1]+A[N//2])/2
    B_chu=(B[N//2-1]+B[N//2])/2
    ans=(B_chu-A_chu)*2+1
    print(int(ans))

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

int Pnumber(int n)
{
  int count = 0;
  vector<int> v(2*n+1, 1);

  if (n==1) {
    return 1;
  }
  
  for (int i = 2; i < n; i++) {
    for (int j = 2*i; j < 2*n; j = j+i) {
      v[j] = 0;
    }
  }

  for (int i = n+1; i < 2*n; i++) {
    if (v[i]==1) {
      count++;
    }
  }

  return count;
}

int main(int argc, char *argv[])
{
  int n;

  while (cin >> n, n) {
    n = Pnumber(n);
    cout << n << endl;
  }
  
  return 0;
}



Measured memory_bytes: 4248
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int n;
	cin >> n;
	vector < int > v(n);
	for (auto &el: v) {
		cin >> el;
	}
	int tot = accumulate(all(v), 0), o = 0;
	int ans = INF;
	for (int i = 0; i < n - 1; ++i) {
		o += v[i];
		tot -= v[i];
		ans = min(ans, abs(o - tot));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#define MAX_N 200

int max (int a,int b){
	if(a>b) return a;
	else return b;
}

int min (int a,int b){
	if(a<b) return a;
	else return b;
}

int abs(int i){
	if(i<0) return i*-1;
	else return i;
}

//maxxxxxxxxxxxzzzzzz dpppppp!!!!!!!!

int D,N;
int dp[MAX_N+1][MAX_N+1];
int T[200];
int C[200][3];



int main(){
	scanf("%d%d",&D,&N);
	for(int i=0;i<=D;i++){
		for(int ii=0;ii<=N;ii++){
			dp[i][ii]=-1;
		}
	}
	for(int i=0;i<D;i++)
		scanf("%d",&T[i]);
	for(int i=0;i<N;i++)
		scanf("%d%d%d",&C[i][0],&C[i][1],&C[i][2]);
	for (int j = 0; j < N; j++) if (C[j][0] <= T[0] && T[0] <= C[j][1]) 
		dp[0][j] = 0;
	
	for(int d=0;d<D-1;d++){
		for(int c=0;c<N;c++){
			if(dp[d][c]>=0){
				for(int i=0;i<N;i++){
					if (C[i][0] <= T[d+1] && T[d+1] <= C[i][1]) 
						dp[d+1][i]=max(dp[d+1][i],dp[d][c]+abs(C[c][2]-C[i][2]));
				}
			}
		}
	}

	int ans = -1;
	for (int j = 0; j < N; j++) {
		if (ans < dp[D-1][j]) {
			ans = dp[D-1][j];
		}
	}
	printf("%d\n", ans);
	return 0;
}
		

Measured memory_bytes: 1188
#!/usr/local/bin/python3

import os, sys

if __name__ ==  "__main__":
    d = {}
    text = input()

    for j in text:
        for i in j:
            if i not in d:
                d[i] = 1
            else :
                d[i] += 1

    # for j in d:
    #     print(j, ':', d[j])
    flag = 0
    for j in d:
        if d[j] % 2 == 0:
            continue
        else:
            flag = 1
            break
    if flag != 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int k = sc.nextInt();
    int x = sc.nextInt();

    for (int i = x - (k - 1); i < (x + (k - 1)); i++) {
      System.out.print(i + " ");
    }

    System.out.println((x + k) - 1);

  }
}

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

int main(){
	int h,w,d;
	scanf("%d%d%d",&h,&w,&d);
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			int x=i+j,y=i-j+w;
			bool f=((x/d)%2==0),g=((y/d)%2==0);
			if(f){
				if(g) printf("R");
				else printf("Y");
			}else{
				if(g) printf("G");
				else printf("B");
			}
		}
		printf("\n");
	}
}

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

int main(void){
    int n, k;
    int count = 0, result;
    
    cin >> n >> k;
    
    int h[n];
    
    rep(i, n){
        cin >> h[i];
        if(h[i] >= k){
            count++;
        }
    }
    
    result = count;
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h> 

void swap(int *a, int *b){
	int k;
	k = *a;
	*a = *b;
	*b = k;
}

int getGCD(int a,int b){
	int q,r;
	if(b > a){swap(&a,&b);}
	while(1){
		q = a / b;
		r = a % b;
		if(r <= 0){return b;}
		a = b;
		b = r;
	}

}

int main(void){ 
	int a, b;
	int gcd,lcm;
	while(1){
		if(scanf("%d%d",&a,&b) == EOF){break;}
		gcd = getGCD(a,b);
		lcm = (a / gcd) * (b / gcd) * gcd;
		printf("%d %d\n",gcd,lcm);
	}

	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if ((C >= A && C <= B) || (C <= A && C >= B)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll n,d,x;
    cin >> n >> d >> x;
    vector<ll> aa(n);
    rep(i,n) {
        cin >> aa[i];
    }

    ll choco = x;
    for(auto a: aa) {
        ll day = 1;
        while(day <= d) {
            ++choco;
            day += a;
        }
    }
    cout << choco << endl;
    return 0;
}


Measured memory_bytes: 256
n, a = map(int, input().split())
x = list(map(int, input().split()))

for i in range(n):
    x[i] -= a


def full(shape, value):
    if not shape:
        return value
    return [full(shape[1:], value) for _ in range(shape[0])]

minus_cnt = 0
plus_cnt = 0
for v in x:
    if v < 0:
        minus_cnt -= v
    elif v > 0:
        plus_cnt += v

dp = full((n + 1, minus_cnt + plus_cnt + 5, n + 1), None)
def dfs(k, s=0, depth=n - 1): # ret -> pattern count
    if dp[k][s][depth] is not None:
        return dp[k][s][depth]
    if k == 0:
        if s == 0:
            result = 1
        else:
            result = 0
        dp[k][s][depth] = result
        return result
    if depth == -1:
        dp[k][s][depth] = 0
        return 0
    result = dfs(k - 1, s + x[depth], depth - 1) + dfs(k, s, depth - 1)
    dp[k][s][depth] = result
    return result

result = 0
for i in range(1, n + 1):
    result += dfs(i)
print(result)


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

int main(){
  int N,K,l[60];
  cin >> N >> K;
  for(int i=0 ; i<N ; i++) cin >> l[i];

  sort(l,l+N,greater<int>()); // lを大きい順にソート

  int total=0;
  for(int i=0 ; i < K ; i++) total += l[i];

  cout << total;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n, m ,c; cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n)rep(j,m) cin >> a[i][j];
    int cnt = 0;
    rep(i,n) {
        int x = c;
        rep(j,m) {
            x += a[i][j] * b[j];
        }
        if(x > 0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

   class Main{
         static public void main(String[] args){
               Scanner scan = new Scanner(System.in);

               int a;
               a =Integer.parseInt(scan.next());
               while(a!=0){
                  int c1=0;
                  
                  for(int j=1;j<1000;j++){
                     for(int k=1;k<1000;k++){
                     
                        int l=(j+1)*(2*k+j)/2;
                        if(l == a){
                           c1++;
                     
                         
                        }
                     
                        
                         
                       
                   
                  
                        }
                   }
                   System.out.println(c1);
                   
                   a =Integer.parseInt(scan.next());
               }
         }
   
   
   
   }

Measured memory_bytes: 26564
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *
def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1/f

def make_next(n, nums):
    imos = [0 for i in range(n)]
    for i, num in enumerate(nums):
        if num > i:
            imos[0] += 1
        else:
            imos[i - num] += 1

        if i + num + 1 < n:
            imos[i+num+1] -= 1
    # print(imos)
    nx = []
    tmp = 0
    for im in imos:
        tmp += im
        nx.append(tmp)

    return nx

def mantan_check(n, nums):
    if sum(nums) == n ** 2:
        return True
    else:
        return False

def solve():
    n, k = getList()
    nums = getList()
    for i in range(k):
        nums = make_next(n, nums)
        if mantan_check(n, nums):
            print(*nums)
            return

    print(*nums)
    return



def main():
    # n = getN()
    # for _ in range(n):
    solve()
if __name__ == "__main__":
    solve()

"""
5 10000000000000
4 0 0 0 0
"""

Measured memory_bytes: 183356
#include <iostream>

using namespace std;

int main(){

  float sum = 0;
  float x;
  string str;

  int N;

  cin >> N;
  
  for(int i = 0; i < N; i++){
    cin >> x >> str;

    if(str == "JPY"){
      sum += x;
    }
    else{
      sum += x * 380000;
    }
  }

  cout << sum << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll ans = LLINF;
void dfs(ll now, ll cou, ll a, ll b, ll sum){
	if(a <= 0)return;
	if(ans < now)return;
	if(cou == 41){
		ans = min(ans, now);
		return;
	}
	ll A = (a >> cou) & 1;
	ll B = (b >> cou) & 1;
	ll C = (sum >> cou) & 1;

	if((A + B + C) % 2){
		return;
	}

	ll tmp = (1LL << cou);
	dfs(now, cou+1, a, b, sum);
	dfs(now + tmp, cou+1, a - tmp, b + tmp, sum);
}

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	ll sum = 0;
	for(ll i = 2;i < n;i++)sum ^= v[i];

	dfs(0, 0, v[0], v[1], sum);
	if(ans < v[0]){
		cout << ans << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);

int main()
{
  int n;
  int M[MAX][MAX];

  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      int e;
      cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  int d[MAX], p[MAX];
  bool visited[MAX];
  for (int i = 0; i < n; ++i)
  {
    d[i] = INFTY;
    p[i] = -1;
    visited[i] = false;
  }
  d[0] = 0;

  while (true)
  {
    int minv = INFTY;
    int u = -1;
    for (int v = 0; v < n; ++v)
    {
      if (!visited[v] && minv > d[v])
      {
        minv = d[v];
        u = v;
      }
    }
    if (u == -1) break;

    visited[u] = true;
    for (int v = 0; v < n; ++v)
    {
      if (!visited[v] && M[u][v] != INFTY)
      {
        if (d[v] > M[u][v])
        {
          d[v] = M[u][v];
          p[v] = u;
        }
      }
    }
  }

  int sum = 0;
  for (int i = 0; i < n; ++i)
  {
    if (p[i] == -1) continue;
    sum += M[i][p[i]];
  }

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 3112
/*
 *  * main.cpp
 *   *
 *    */

#include<iostream>
#include<fstream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<cstring>
#include<string>
#include<cassert>
#include<stdlib.h>
#include<time.h>
using namespace std;

int A[300000];
int main() {

    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) scanf("%d", A + i);
    int res = 1;

    for (int i = 0; i < N; ++i) if (res == A[i]) res++;


    if (res == 1) printf("-1\n");
    else printf("%d\n", N - res + 1);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using P = pair<ll,int>;

const int N = 2020;

int n;
ll a[N];
vector<P> v;

ll dp[N][N];
ll dfs(int l, int r){
    if(l>r) return 0;
    if(dp[l][r]>=0) return dp[l][r];
    int idx = l+(n-1-r);
    int p = v[idx].se;
    ll x = v[idx].fi;

    ll ret = 0;
    ret = max(ret, dfs(l+1,r)+x*(p-l));
    ret = max(ret, dfs(l,r-1)+x*(r-p));
    return dp[l][r] = ret;
}

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

    v = vector<P>(n);
    rep(i,n) v[i] = {a[i],i};
    sort(all(v), greater<P>());

    memset(dp,-1,sizeof(dp));
    cout << dfs(0,n-1) << "\n";
    return 0;
}


Measured memory_bytes: 35648
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>

#define INF 1010000000
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);

using namespace std;


int main(){
	while(1){
		int n,m;
		sintt(m,n);
		if(n==0)break;
		int fro[101][101][2];
		rep(i,101)rep(j,101)fro[i][j][0]=fro[i][j][1]=INF;
		
		rep(i,m){
			int a,b,c,d;
			sintt(a,b);
			sintt(c,d);
			
			fro[a][b][0]=fro[b][a][0]=c;
			fro[a][b][1]=fro[b][a][1]=d;
		}
		
		
		reps(k,n){
			reps(i,n){
				reps(j,n){
					fro[i][j][0]=min(fro[i][j][0],fro[i][k][0]+fro[k][j][0]);
					fro[i][j][1]=min(fro[i][j][1],fro[i][k][1]+fro[k][j][1]);
				}
			}
		}
		
		int t;
		sint(t);
		
		rep(i,t){
			int a,b,c;
			sinttt(a,b,c);
			
			printf("%d\n",fro[a][b][c]);
		}
	}
}

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

using namespace std;

const int maxn=1e5+5;
const int NIL=-1;

int n,color[maxn];
vector<int>g[maxn];

void dfs(int r,int c)
{
    stack<int>s;
    s.push(r);
    color[r]=c;
    while(!s.empty()){
        int u=s.top();
        s.pop();
        for(int i=0;i<g[u].size();i++){
            int v=g[u][i];
            if(color[v]==NIL){
                color[v]=c;
                s.push(v);
            }
        }
    }
}

void assigncolor()
{
    int id=1;
    for(int i=0;i<n;i++){
        color[i]=NIL;
    }
    for(int u=0;u<n;u++){
        if(color[u]==NIL){
            dfs(u,id++);
        }
    }
}

int main()
{
    int s,t,m,q;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>s>>t;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    assigncolor();
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>s>>t;
        if(color[s]==color[t]){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}
/*
10 9
0 1
0 2
3 4
5 7
5 6
6 7
6 8
7 8
8 9
3
0 1
5 9
1 3
*/



Measured memory_bytes: 9012
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll w[2002], h[2002], a[2002][2002] = {}, ans = 0;
int n, m, w1 = 0, h1 = 0;
struct seg {
    int pos;
    int fr;
    int to;
    bool operator<(const seg& s)const {
        return (pos < s.pos ||
            (pos == s.pos && fr < s.fr));
    }
}wseg[1001], hseg[1001];
void cut(seg* segs, ll* t1, ll* t2, int t2_n, int k, int sw) {
    int r = 0;
    for (int i = 0; i < k; i++) {
        if (segs[i].pos != t1[r])r += 2;
        if (i < n - 1)if (segs[i].pos == segs[i + 1].pos && segs[i].to >= segs[i + 1].fr) {
            segs[i + 1].fr = segs[i].fr;
            segs[i + 1].to = max(segs[i].to, segs[i + 1].to);
            continue;
        }
        for (int j = lower_bound(t2, t2 + t2_n, segs[i].fr) - t2; j<t2_n&&(j==t2_n-1?1:t2[j+1]<=segs[i].to); j++) {
            if (sw)a[r][j] = 1;
            else a[j][r] = 1;
        }
    }
}
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> wseg[i].fr >> wseg[i].to >> wseg[i].pos;
    }
    for (int i = 0; i < m; i++) {
        cin >> hseg[i].pos >> hseg[i].fr >> hseg[i].to;
    }
    sort(wseg, wseg + n);
    sort(hseg, hseg + m);
    int pr = wseg[0].pos;
    w[w1++] = pr;
    for (int i = 1; i < n; i++) {
        if (wseg[i].pos != pr) {
            w[w1++] = pr;
            pr = wseg[i].pos;
            w[w1++] = pr;
        }
    }
    pr = hseg[0].pos;
    h[h1++] = pr;
    for (int i = 1; i < m; i++) {
        if (hseg[i].pos != pr) {
            h[h1++] = pr;
            pr = hseg[i].pos;
            h[h1++] = pr;
        }
    }
   
    cut(wseg, w, h, h1, n, 1);
    cut(hseg, h, w, w1, m, 0);
    queue<pair<int, int>> que;
    int x0 = upper_bound(w, w + w1, 0) - w;
    int y0 = upper_bound(h, h + h1, 0) - h;
    if (!x0 || !y0||x0>=w1||y0>=h1) {
        cout << "INF";
        return 0;
    }
    que.push({ x0-1,y0-1 });
    while (!que.empty()) {
        auto t = que.front();
        que.pop();
        int x = t.first;
        int y = t.second;
        if (a[x][y])continue;
        if (x == 0 || y == 0 || x == w1 - 1 || y == h1 - 1) {
            cout << "INF";
            return 0;
        }
        ans += (w[x + 1] - w[x]) * (h[y + 1] - h[y]);
        a[x][y] = 1;
        que.push({ x + 1,y });
        que.push({ x - 1,y });
        que.push({ x,y + 1 });
        que.push({ x,y - 1 });
    }
    cout << ans;
}

Measured memory_bytes: 34960
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
      int sum = 0;
      
      if(a == 5 || a == 7) {
      	sum += a;
      }
      if(b == 5 || b == 7) {
      	sum += b;
      }
      if(c == 5 || c == 7) {
      	sum += c;
      }
      
      if(sum == 17) {
      	System.out.print("YES");
      } else {
      	System.out.print("NO");
      }
      scan.close();
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
long long INF=1e9+7;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
#define int long long
signed main(){
  int a,b; cin>>a>>b;
  if((a+b)%3!=0||a*2<b||b*2<a){cout<<0<<endl;return 0;}
  int c=((a+b)/3-(a-b))/2,d=(a+b)/3-c;
  int count=1;
  for(int i=c+d;i>d;i--){
    count*=i;
    count%=INF;
  }
  int A=1;
  for(int i=1;i<=c;i++){
    A*=i;
    A%=INF;
  }
  int B=modinv(A,INF);
  count*=B;
  count%=INF;
  cout<<count<<endl;
}

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

int n, b, bp, s;

int main(){
	cin >> n;
	cin >> bp;
	s = bp;
	b = bp;
	for (int i = 0; i < n-2; ++i){
		cin >> b;
		s += min(bp, b);
		bp = b;
	}
	s += b;
	printf("%d\n", s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int ans;

void merge(vi &a, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vi l(n1+1), r(n2+1);
    rep(i, n1) l[i] = a[left+i];
    rep(i, n2) r[i] = a[mid+i];
    l[n1] = INT_MAX; r[n2] = INT_MAX;
    int i = 0, j = 0;
    for (int k = left; k < right; ++k) {
        ans++;
        if (l[i] <= r[j]) {
            a[k] = l[i];
            i++;
        } else {
            a[k] = r[j];
            j++;
        }
    }
}

void mergesort(vi &a, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) >> 1;
        mergesort(a, left, mid);
        mergesort(a, mid, right);
        merge(a, left, mid, right);
    }
}

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    mergesort(a, 0, n);
    rep(i, n) cout << a[i] << (i == n-1 ? '\n' : ' ');
    cout << ans << endl;
}



Measured memory_bytes: 6676
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n):
    h = {0:'0', 1:'1', -2:'10', -1:'11'}
    if n in h:
        ret = h[n]
        #ddprint(f"foo {n} ret {ret}")
        return ret
    r = n%4
    if r==0:
        s = '00'
        v = 0
    elif r==1:
        s = '01'
        v = 1
    elif r==2:
        s = '10'
        v = -2
    else:
        s = '11'
        v = -1
    ret = foo((n-v)//4) + s
    #ddprint(f"foo {n} ret {ret}")
    return ret

n = inn()
if n==0:
    print(0)
else:
    s = foo(n)
    for i in range(len(s)):
        if s[i]=='1':
            break
    print(s[i:])



Measured memory_bytes: 38384
import sys
N = int(input())
H = [int(i) for i in input().split()]

max_num = H[0]
for i in range(N-1):
  if max_num < H[i]:
    max_num = H[i]
  if max_num - H[i+1] >= 2:
    print("No")
    sys.exit()

print("Yes")

Measured memory_bytes: 14396
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    # https://atcoder.jp/contests/abc156/submissions/11621672
    def modpow(a, b, mod=10 ** 9 + 7):
        ret = 1
        while b > 0:
            if b % 2 == 1:
                ret = ret * a % mod
            a = a * a % mod
            b //= 2
        return ret

    def modcomb(n, c, mod=10 ** 9 + 7):
        if c > n - c:
            c = n - c
        u, d = 1, 1
        for i in range(c):
            u = u * (n - i) % mod
            d = d * (i + 1) % mod
        return u * modpow(d, mod - 2) % mod

    mod = 10 ** 9 + 7
    n, a, b = map(int, input().split())
    ans = (modpow(2, n) - 1) % mod
    ans = (ans - modcomb(n, a)) % mod
    ans = (ans - modcomb(n, b)) % mod
    print(ans)


resolve()

Measured memory_bytes: 38512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int gcd(int a,int b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    long long int n,h=0,w=0;
    cin>>n;
    vector<long long int>a(200000);

    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=n;i++){
        if(a[i]==i+1&&i!=n){
            h++;
        }
        else{
            h=(h+1)/2;
            w+=h;
            h=0;
        }
    }
    cout<<w<<endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([a[i], i])
b = sorted(b, key=lambda x: x[0], reverse=False)
for i in range(n):
    if i<n//2:
        b[i].append(b[n//2][0])
    else:
        b[i].append(b[n//2-1][0])
b = sorted(b, key=lambda x: x[1], reverse=False)
for i in range(n):
    print(b[i][2])


Measured memory_bytes: 130644
K, A, B = map(int, input().split())

if K == 1:
    print(2)
elif K == 2:
    if A == 1 and B >= 2:
        print(B)
    else:
        print(2)
else:
    ans = 1
    # 変換したほうが得なら変換する
    if B-A >= 2:
        # A枚を1円に変換、1円をB枚に変換で行動件を2回使うので2で割る
        cnt, amari = divmod(K-(A-1), 2)
        ans = A+cnt*(B-A)+amari
    else:
        ans += K
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
int main()
{
    long A,B;
    std::cin >> A >> B;
    if(A*B%2==1){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

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

int main(){
  int D, N;
  cin >> D >> N;
  int a=1;
  for(int i=0; i<D; i++){
    a*=100;
  }
  if(N==100)N=101;
  cout << a*N << endl;
  return 0;
}

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

#define     str             string
#define     PB              push_back
#define     FOR(i,a,n)      for(int i=a;i<=n;i++)
#define     FORA(i,a,n)     for(int i=a;i<n;i++)
#define     srt(a)          sort(a.begin(),a.end())
#define     rev(a)          reverse(a.begin(),a.end())

#define     c1(a)           cin>>a
#define     c2(a,b)         cin>>a>>b
#define     c3(a,b,c)       cin>>a>>b>>c
#define     c4(a,b,c,d)     cin>>a>>b>>c>>d

#define     p(a)            cout<<a<<endl

#define     sci1(a)         scanf("%d",&a)
#define     sci2(a,b)       scanf("%d %d",&a,&b)
#define     sci3(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define     sci4(a,b,c,d)   scanf("%d %d %d %d",&a,&b,&c,&d)

#define     pri1(a)         printf("%d\n",a)
#define     pri2(a,b)       printf("%d %d\n",a,b)
#define     pri3(a,b,c)     printf("%d %d %d\n",a,b,c)
#define     pri4(a,b,c,d)   printf("%d %d %d %d\n",a,b,c,d)

#define     fast            ios_base::sync_with_stdio(false);cin.tie(NULL)


#define     intahn           int a,b,c,d,e,f,g,h,n

#define     pi              acos(-1)

typedef     long long int   ll;
typedef     vector<int>     vi;
typedef     vector<str>     vs;
typedef     pair<ll,ll>     paii;
typedef     pair<ll,str>    pais;

intahn;
vi x;
set< ll > se;

int main(){
    fast;
    sci1(n);

    FOR(i,1,n){
        sci1(a);
        x.PB(a);
        se.insert(a);
    }

    d=*max_element(x.begin(),x.end());
    auto it = se.end();
    it--;
    it--;
    ll k=*it;
    int D=0;
    for(int i=0;i<n;i++){

        if(x[i]==d)
            D++;
        if(D==2) break;
    }

    for(int i=0; i<n; i++){
        if(x[i]!=d){
            cout<<d<<endl;
        }
        else if(x[i]==d && D==2){
            cout<<d<<endl;
        }

        else{
            cout<<k<<endl;
        }
    }

}


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

int main(void) {
  int n,k;
  cin >> n >> k;
  auto p = vector<int>(n);
  for(int i = 0;i < n;++i) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int res = 0;
  for(int i = 0;i < k;++i) {
    res += p[i];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3624
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int maxn = 1e5 + 5;

int n;
int a[maxn];
lli f[maxn], su[maxn];

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

void solve()
{
    if(n == 1)
    {
        if(a[1] == 1) cout << "1\n";
        else cout << "-1\n";
        return;
    }
    else if(a[1] != 0)
    {
        cout << "-1\n";
        return;
    }
    su[n + 1] = 0;
    for(int i = n; i > 0; --i)
        su[i] = su[i + 1] + a[i];
    lli ans = 0;
    f[1] = 1;
    for(int i = 1; i <= n; ++i)
    {
        cerr << f[i] << '\n';
        ans += f[i];
        if(i == n) break;
        f[i] -= a[i];
        lli low = 1, high = f[i];
        while(low <= high)
        {
            lli mid = (low + high) / 2;
            if(f[i] + mid - su[i + 1] <= 0)
                low = mid + 1;
            else high = mid - 1;
        }
        f[i + 1] = f[i] + high;
    }
    if(f[n] != a[n]) ans = -1;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 5608
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n;
vector<int>v,vv;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			cout<<__builtin_ctz(i-j)+1<<' ';
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


ll MAX = 1000000000;


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

	vec A(N + 1), B(N);

	for (int i = 0; i < N + 1; ++i)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> B[i];
	}

	ll ans = 0;

	for (int i = N - 1; i >= 0; --i)
	{
		if (A[i + 1] > B[i])
		{
			ans += B[i];
		}
		else
		{
			ans += A[i + 1];
			ans += min(A[i], B[i] - A[i + 1]);
			A[i] = max(0ll, A[i] - B[i] + A[i + 1]);
		}

		//cout << ans << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
using System;
using System.IO;
using System.Collections.Generic;

namespace NIKKEI2019A
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var A = ss.Next(int.Parse);
            var B = ss.Next(int.Parse);

            sw.WriteLine(Math.Min(A, B));
            sw.WriteLine(Math.Max(0, A + B - N));
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    if (k > (n - 1) * (n - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }
    
    cout << (n - 1) + (n - 1) * (n - 2) / 2 - k << endl;

    for (int i = 2; i <= n; i++) {
        printf("1 %d\n", i);
    }
    int u = 2;
    int v = 3;
    for (int i = 0; i < (n - 1) * (n - 2) / 2 - k; i++) {
        printf("%d %d\n", u, v);
        v++;
        if (v > n) {
            u++;
            v = u + 1;
        }
    }
}

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


int n, m;
int h[1000000];
int a, b;

bool good[1000000];

int main(){

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

    for(int i = 1; i <= n; i++){
        good[i] = true;
    }

    for(int i = 0; i < m; i++){
        cin >> a >> b;

        if(h[a] > h[b]){
            good[b] = false;
        }
        else if(h[a] < h[b]){
            good[a] = false;
        }
        else{
            good[b] = false;
            good[a] = false;
        }

    }

    int ans = 0;


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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4128
#include<bits/stdc++.h>
#define FR first
#define SE second
using namespace std;

typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int N=200010;
int n,V,X[N],dep=0;
int L[20][N],R[20][N];
int exL[N<<4],exR[N<<4];
pii seg[N];
bool ans[N];

int main()
{
    scanf("%d%d",&n,&V);
    for(int i=1;i<=n;i++) scanf("%d",X+i);
    X[0]=-INF-V-1;X[n+1]=INF+V+1;
    for(int v=V;v>=0;v>>=1,dep++)
    {
        R[dep][n+1]=n+1;
        for(int i=1;i<=n;i++) L[dep][i]=(X[i]-X[i-1]<=v)?L[dep][i-1]:i;
        for(int i=n;i>=1;i--) R[dep][i]=(X[i+1]-X[i]<=v)?R[dep][i+1]:i;
        if(v==0){dep++;break;}
    }
    for(int i=1;i<=n;i++) seg[i]=pii(L[0][i],R[0][i]);
    int cnt=unique(seg+1,seg+1+n)-(seg+1);
    for(int i=0;i<(1<<dep);i++) exR[i]=n+1;
    for(int s=0;s<(1<<dep);s+=2)
        for(int i=0;i<dep;i++)
        {
            if(!(s&(1<<i))) continue;
            exL[s]=max(exL[s],R[i][exL[s^(1<<i)]+1]);
            exR[s]=min(exR[s],L[i][exR[s^(1<<i)]-1]);
        }
    if(cnt>dep) goto output;
    for(int i=1;i<=cnt;i++)
        for(int s=0;s<(1<<dep);s+=2)
            if(exL[s]>=seg[i].FR-1&&exR[(1<<dep)-1-s-1]<=seg[i].SE+1)
            {
                for(int j=seg[i].FR;j<=seg[i].SE;j++) ans[j]=1;
                break;
            }
    output: for(int i=1;i<=n;i++) puts(ans[i]?"Possible":"Impossible");
    return 0;
}

Measured memory_bytes: 41856
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

const int MAX = 8100;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll floormod(ll a, ll mod) {
  if (a > 0) return (a % mod);
  else if (a % mod == 0 ) return 0;
  else return (a % mod) + mod;
}

int main() {
  int N;
  cin >> N;
  vi A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];

  vector<vector<ll>> T(4005, vector<ll>(4005, 0));
  rep(i, N) {
    T[2001 - A[i]][2001 - B[i]]++;
  }

  vector<vector<ll>> dp(4005, vector<ll>(4005, 0));
  for (int i = 1; i < 4002 ; i++) {
    for (int j = 1 ; j < 4002 ; j++) {
      ll a = dp[i - 1][j] + dp[i][j - 1] + T[i][j];
      dp[i][j] = a % MOD;
    }
  }


  ll X = 0;
  rep(i, N) {
    ll b = X + dp[2001 + A[i]][2001 + B[i]];
    X = b % MOD;
  }

  COMinit();
  ll Y = 0;
  rep(i, N) {
    ll c  = Y + COM(2 * A[i] + 2 * B[i], 2 * A[i]);
    Y = c % MOD;
  }

  ll d = inv[2];
  ll e = X - Y;
  ll res = floormod(e * d, MOD);

  cout << res << endl;

}


Measured memory_bytes: 252928
# B
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1,n-1):
    if (p[i+1] < p[i] < p[i-1] or p[i+1] > p[i] > p[i-1]):
        ans += 1
print(ans)

Measured memory_bytes: 38256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val aList = readIntegerList()
    var money = 1000L
    var stock = 0L
    var pre = aList.first()
    var state = 0
    for (a in aList.drop(1)) {
        if (state == 1) {
            if (pre > a) {
                // 売る
                money += stock * pre
                stock = 0
                state = -1
            }
        } else if (state == 0) {
            if (pre < a) {
                // 買う
                stock += money / pre
                money %= pre
                state = 1
            } else if (pre > a) {
                // 売る
                money += stock * pre
                stock = 0
                state = -1
            }
        } else {
            if (pre < a) {
                // 買う
                stock += money / pre
                money %= pre
                state = 1
            }
        }

        pre = a
    }

    money += stock * aList.last()
    out.println(money)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main() {
	int N;
	cin >> N;
	multiset<ll> S;
	for (int i = 0; i < N; i++) {
		ll s;
		cin >> s;
		S.insert(s);
	}

	auto it = S.rbegin();
	ll score = -(*it);
	while(N > 0){
		score += *it;
		N--;
		if (N == 0) break;
		score += *it;
		N--;
		if (N == 0) break;
		it++;
	}

	cout << score << endl;
	return(0);
}


Measured memory_bytes: 12996