akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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


using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    pair<bool,int> pr[100001];
    int n,m; cin >> n >> m;
    int p;
    string s;
    int ansAC = 0;
    int ansWA = 0;
    rep(i,100001){
        pr[i].first = false;
        pr[i].second = 0;
    }
    rep(i,m){
        cin >> p >> s;
        if(s == "AC"){
            pr[p].first = true;
        }
        else if(pr[p].first == false){
            pr[p].second ++;
        }
    }

    rep(i,100001){
        if(pr[i].first == true){
            ansWA += pr[i].second;
            ansAC ++;
        }
    }

    cout << ansAC <<" "<< ansWA;
    return 0;
}











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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int n = a;
  if (a < k) n = k;
  int cnt = 0;
  
  while (n <= b) {
    if (n % k == 0) {
      cnt = 1;
      break;
    }
    n++;
  }
  
  if (cnt) cout << "OK";
  else cout << "NG";
}
  

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

int main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i=0; i<s.size(); i++)
    ans += (s[i] != t[i]);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3848
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

ls = [n for n in range(2,30001) if n % 2 == 0 or n % 3 == 0]

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def check(N, ans):
  assert len(ans) == len(set(ans)) == N
  S = sum(ans)
  assert reduce(gcd, ans) == 1
  assert all(gcd(S - a, a) != 1 for a in ans)

def solve(N):
  if N == 3:
    return [2, 5, 63]
  q, r = divmod(N, 8)
  t = q * 8
  ans = ls[:t]
  if r % 2 == 1:
    ans += [ls[t+3]]
  r //= 2
  if r == 1:
    ans += [ls[t], ls[t+2]]
  elif r == 2:
    ans += ls[t:t+3] + [ls[t+5]]
  elif r == 3:
    ans += ls[t:t+3] + ls[t+4:t+7]
  return ans

# for N in range(3, 100):
#   ans = solve(N)
#   print(N, ans, file=stderr)
#   check(N, ans)

N = read()
print(' '.join(str(a) for a in solve(N)))

Measured memory_bytes: 41456
#include<bits/stdc++.h>
using namespace std;
int a[10000];
int b[10000];
int c[10000];
int main(){
  string s;;
  int i=0,a,b,c=1;
  cin>>a>>b;
  while(1){
    if(c>=b) break;
    c+=-1+a;
    i++;
  }
  cout<<i<<"\n";
  return(0);
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k;cin >> n >> k;
	set<int> ar[n];
	for(int i=0;i<k;i++){
		int d;cin >> d;
		while(d--){
			int a;cin >> a;
			ar[a-1].insert(i);
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++) ans += ar[i].empty();
	cout << ans << '\n';
	return 0;
}


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

int main()
{
	int n=0,iCnt=0,iPoint1=0,iPoint2=0,iNum1=0,iNum2=0;

	vector<int> iSum1(10000);
	vector<int> iSum2(10000);

	while( 1 ){
		cin >> n;
		if( n == 0 ){ break; }
		else{
			for( int i=0;i<n;i++ ){
				cin >> iNum1 >> iNum2;
				if( iNum1 > iNum2 ){ iPoint1 += iNum1+iNum2; }
				else if( iNum1 < iNum2 ){ iPoint2 += iNum1+iNum2; }
				else if( iNum1 == iNum2 ){
					iPoint1 += iNum1;
					iPoint2 += iNum2;
				}
			}
			iSum1[iCnt] = iPoint1;
			iSum2[iCnt] = iPoint2;
			iCnt++;
			iPoint1 = 0;
			iPoint2 = 0;
		}
	}

	for( int i=0;i<iCnt;i++ ){
		cout << iSum1[i] << " " <<iSum2[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
#define ull unsigned long long
using namespace std;

int main() {

	ll A;
	ll B;
	ll C;
	ll X;
	ll Y;
	cin >> A >> B >> C >> X >> Y;

	int loop = 0;
	if (X > Y)
		loop = X;
	else {
		loop = Y;
	}
	
	ll min = 5000 * 100010 * 2;
	FOR(i, 0, loop + 1) {
		ll costA = (X - i)*A;
		ll costB = (Y - i)*B;
		if (costA < 0) costA = 0;
		if (costB < 0) costB = 0;

		ll cost = costA + costB + i*2*C;
		
		if (min > cost)	min = cost;
		//cout << "(" << (X - i) << "," << (Y - i) << "," << i*2 << ")"<< " " << cost << endl;
	}

	cout << min << endl;


	system("pause");
	return 0;
}

Measured memory_bytes: 504
n=int(input())
l = list(map(int, input().split()))
res = 0
for i in range(1,n-1):
  if l[i-1]<l[i] and l[i]<l[i+1] or l[i-1]>l[i] and l[i]>l[i+1]: res+=1
print(res)


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

int main(){
    
    int h, n,at,bt,o;
    cin >> h >> n;
    
    vector<int> a;
    vector<int> b;
    int n_t = n + 1;
    int h_t = h + 1;
    vector<vector<int> > dp(n_t, vector<int>(h_t));
    
    for(int i=0;i<n;i++){
        cin >> at >> bt;
        a.push_back(at);
        b.push_back(bt);
    }
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=h;j++){
            dp[i][j] = 0;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<h;j++){
            
            if(j - a[i] < 0){
                o = b[i];
            }else{
                o = dp[i+1][(j+1-a[i])] + b[i];
            }
            if(i != 0){
                dp[i+1][j+1] = min(dp[i][j+1], o);
            }else{
                dp[i+1][j+1] = o;
            }
            
        }
    }
    
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=h;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    cout << dp[n][h] << endl;
    
}


Measured memory_bytes: 39424
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;



int r;
main () {
	cin >> r;
	cout << setprecision(9) << 2 * acos(-1) * r << endl;
}


Measured memory_bytes: 3788
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    s = input()
    print(s[0:3])

main()


Measured memory_bytes: 9316
N=int(input())

A=list(map(int,input().split()))

Amap=dict()

for i in range(N):
    if A[i] in Amap:
        Amap[A[i]]+=1
    else:
        Amap[A[i]]=1

# print(Amap)

s = 0
for k in Amap.keys():
    s += (int(k)*Amap[k])


Q=int(input())
ans = list()
for i in range(Q):
    B, C =list(map(int,input().split()))

    if B in Amap:
        if C in Amap:
            Amap[C] += Amap[B]
            s += (C-B)*Amap[B] 
        else:
            Amap[C] = Amap[B]
            s += (C-B)*Amap[B] 

    else:
        if C in Amap:
            Amap[C] += 0
        else:
            Amap[C] = 0

    Amap[B] = 0
    # print(i, B, C, Amap)


    ans.append(s)
    # print(s)

for s in ans:
    print(s)

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

int main(){
	int n, m, a[100][100], b[100];
	cin >> n >> m;
	for(int i = 0;i < n;i++)
		for(int j = 0;j < m;j++)
			cin >> a[i][j];
	for(int i = 0;i < m;i++)cin >> b[i];
	
	for(int i = 0;i < n;i++){
		int t = 0;
		for(int j = 0;j < m;j++){
			t += a[i][j] * b[j];
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
<?php
fscanf(STDIN, "%d", $T);
while($T-- > 0){
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    $a *= $a;
    $b *= $b;
    $c *= $c;
    if($a + $b == $c || $a + $c == $b || $b + $c == $a){
        echo "YES\n";
    }
    else{
        echo "NO\n";
    }
}

Measured memory_bytes: 6532
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int n;
    cin>>n;
    int ans=0;
    rep2(1,i,n+1){
        string s =to_string(i);
        if(s.length()%2==1){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
a = []
p = []
for i in range(n):
    k,v = map(int,input().split())
    p.append(k)
    a.append(v)

dp = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    dp.append(o)


for i in range(n):
    for j in range(w+1):
        if p[i] > j:
            dp[i+1][j] = dp[i][j]

        else:
            dp[i+1][j] = max(a[i] + dp[i][j - p[i]], dp[i][j])

print(dp[n][w])

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

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

ll n, ans = 0;

int dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << endl;
    return 0;
  }

  for (char i = 'a'; i <= mx + 1; ++i) {
    string t = s;
    t += i;
    dfs(t, max(i, mx));
  }
  return 0;
}

int main() {
  cin >> n;
  dfs("", 'a' - 1);
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  string s;
  cin >> s;
  ll n = s.length();
  ll sum = 0;
  for (ll i = 0; i < n; ++i)
    sum += (s[i] - '0');
  if (sum % 9)
    cout << "No";
  else
    cout << "Yes";
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define ll long long
#define testfor(T) ll T; cin>>T; while(T--)
using namespace std;
void quickstart()
{
	ios_base::sync_with_stdio(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}
int main()
{
	quickstart();
	double b;
	ll a;
	cin >> a >> b;
	ll product=(a*(ll)(b*100+0.5))/100;
	cout<<product;
	return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>
int main(void){
	int t,n;
	int i;
	
	for(i=0;i<4;i++){
		scanf("%d %d",&t,&n);
		
		if(t==1){
			printf("%d\n",6000*n);
		}
		if(t==2){
			printf("%d\n",4000*n);
		}
		if(t==3){
			printf("%d\n",3000*n);
		}
		if(t==4){
			printf("%d\n",2000*n);
		}
	}
		
	
	
	return 0;
}

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

int main(){
	int n;
	int count = 0;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++){
		cin >> v[i];
	}
	while(1){
		for(int i=0; i<n; i++){
			if(v[i]%2==0) v[i]/=2;
			else{
				cout << count;
				return 0;
			}
		}
		count++;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    string op;
    cin >>a>>op>>b;
    
    if (op == "+")cout << a+b << endl;
    else cout << a-b << endl;
    
    return 0;
}



Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,m=MI()
lis=LI()
u=sum(lis)
count=0
lis.sort(reverse=True)
for i in range(n):
    if (4*m)*lis[i]>=u:
        count+=1
if count>=m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 65760
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        int[] a = ReadIntArray();
        Array.Sort(a);

        int find = 0;
        long cand1, cand2 = 1000000001;

        cand1 = a[n-1];
        for (int i = n-2; i >= 0; i--)
        {
            int x = a[i];
            if (find == 0)
            {
                if (cand1 == x)
                {
                    find = 1;
                }
                else
                {
                    cand1 = x;
                }
            }
            else
            {
                if (cand2 == x)
                {
                    find = 2;
                    break;
                }
                else
                {
                    cand2 = x;
                }
            }
        }

        WriteLine(find == 2 ? cand1 * cand2 : 0);
    }
}

Measured memory_bytes: 21728
#include <iostream>

using namespace std;

int num, num2, divisor;

int main(){

    cin >> num >> num2 >> divisor;
    int array[100];
    int largest = 0;
    int index = 0;
    for (int i=1; i < 101; i++){
        if (num % i == 0 && num2 % i == 0){
            array[index] = i;  
            largest = i;
            index += 1;
        }
    }

    cout << array[index - divisor] ;

    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=110;
bool flag=true;
int a[maxn],ans[maxn];
void work(int n)
{
	if(n==0)return ;
	if(a[n]>n)
	{
		flag=false;
		return;
	}
	work(n-1);
	int st=a[n];
	for(int i=a[n];i<n;i++)
		if(ans[i]<=st)st++;
	if(st<n)
	{
		flag=false;
		return ;
	}
	for(int i=n-1;i>=a[n];i--)
		ans[i+1]=ans[i];
	ans[a[n]]=a[n];
}
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	work(n);
	if(!flag)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
	cout<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if(c-a-b <= 0){
    cout <<"No" << endl;
  }else{
    long long cal;
    cal = a*a + b*b + c*c -2*a*c -2*a*b -2*b*c;
  if(cal>0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#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 print(a) cout << (a) << endl; 
typedef long long ll;

int main() {
    int n, k; 
    cin >> n >> k;
    vector<int> ps(n);
    rep(i, n) cin >> ps[i]; 
    
    int mi = 0, mv = 0, pk = 0; 
    rep(i, n) {
        pk += ps[i];
        if (i >= k) pk -= ps[i-k];
        if (i >= k-1) {
            if (mv < pk) mi = i, mv = pk;  
        }
    }
    double ret = 0;
    rep(i, k) {
        double p = ps[mi-i];
        ret += (p+1) / 2;
    }
    cout << setprecision(10) << ret << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <deque>

using namespace std;

void printDeque(deque<int> &d){
    deque<int>::iterator ite = d.begin();
    while(ite != d.end()){
        if(ite != d.begin())
            cout << " ";
        cout << *ite;
        ite++;
    }
    cout << endl;    
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    deque<int> d;
    while(n--){
        string cmd;
        int val;
        cin >> cmd;
        if(cmd.compare("insert") == 0){
            cin >> val;
            d.push_front(val);
        }else if(cmd.compare("delete") == 0){
            cin >> val;
            deque<int>::iterator ite = d.begin();
            while(ite != d.end()){
                if(val == *ite){
                    d.erase(ite);
                    break;
                }
                ite++;
            }
        }else if(cmd.compare("deleteFirst") == 0){
            d.pop_front();
        }else if(cmd.compare("deleteLast") == 0){
            d.pop_back();
        }
    }
    printDeque(d);
    return 0;
}

Measured memory_bytes: 5316
let rec make_tournament losers winner =
  List.map (make_tournament losers) (losers winner)
    |> List.sort compare
    |> List.fold_left (fun d d' -> 1 + max d d') 0

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init (n - 1) (fun _ -> Scanf.scanf "%d\n" (fun a -> a)) in
  let losers = Array.make n [] in
  Array.iteri (fun i a ->
    losers.(a - 1) <- i + 1 :: losers.(a - 1)) as_;
  Printf.printf "%d\n" (make_tournament (fun i -> losers.(i)) 0)


Measured memory_bytes: 17280
from collections import deque
h,w,k = map(int, input().split())
g = [list(input()) for _ in range(h)]
ans = h*w
for i in range(h):
  if 'S' in g[i]:
    sx = g[i].index('S')
    sy = i
    break
g[sy][sx] = 0
q = deque()
q.append(sy*w+sx)
while q:
  v = q.popleft()
  y,x = v//w, v%w
  cur = min((y-1)//k, (x-1)//k, (h-y-2)//k, (w-x-2)//k) + 2
  if ans > cur:
    ans = cur
  if g[y][x] < k:
    for dx,dy in ((0,1),(1,0),(0,-1),(-1,0)):
      nx = x+dx; ny = y+dy
      if 0 <= nx < w and 0 <= ny < h and g[ny][nx] == '.':
        g[ny][nx] = g[y][x] + 1
        q.append(ny*w+nx)
print(ans)

Measured memory_bytes: 111196
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
    long long int sum=0,range=0,a=0,b=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0;
    long long int longnum[200005];
    //vector <int> v;
    //float f,g,h;
    char c,d;
    string s;
    cin>>c>>d;
    switch (c)
    {
    case 'S':
        if(d=='U') cout<<7;
        else cout<<1;
        break;
    case 'M':
        cout<<6;
        break;
    case 'T':
        if(d=='U') cout<<5;
        else cout<<3;
        break;
    case 'W':
        cout<<4;
        break;
    case 'F':
        cout<<2;
        break;
    }
    return 0;
}




Measured memory_bytes: 256
program d174

implicit none
character(len = 200000) :: c
integer :: i, n, r, a

r = 0
a = 0

read *, n
read *, c

do i = 1, n
 if(c(i:i) == 'R') then
  r = r + 1
 end if
end do

do i = r+1, n
 if(c(i:i) == 'R') then
  a = a + 1
 end if
end do

print *, a

end program d174

Measured memory_bytes: 3220
n = gets.to_i
array = gets.chop.split.map(&:to_i)
var = []
num = []
array.each do |ary|
  if ary%2 == 0
    var.push(ary)
  end
end

var.each do |vv|
  if vv % 3 == 0 || vv % 5 == 0
    num.push(vv)
  end
end

if var.length == num.length
  puts 'APPROVED'
else
  puts 'DENIED'
end

Measured memory_bytes: 1788
N = int(input())
A=[]
l=[1]
ans=0
for i in range(N):
    A.append(int(input()))
for i in range(N):
    l.append(A[l[i]-1])
    if l[i+1]==2:
        ans=i+1
        break
if ans!=0:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 7876
row, col = gets.chomp.split.map(&:to_i)

ary = Array.new(row) do
    Array.new(col)
end

row.times do |r|
    ary[r] = gets.chomp.split.map(&:to_i)
end

ary.each do |r|
    rowsum = 0
    r.each do |i|
        print "#{i} "
        rowsum += i
    end
    puts rowsum
end

colsum = Array.new(col, 0)
col.times do |c|
    ary.each do |r|
        colsum[c] += r[c]
    end
end

allsum = 0
colsum.each do |cs|
    print "#{cs} "
    allsum += cs
end
puts allsum

Measured memory_bytes: 6204
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long int ll;
typedef vector<ll> vl;
typedef vector<string> vs;

#define A 100005

int main(){
	ll p[A];
	for (ll i = 0; i < A; i++) {
		p[i] = 0;
	}

	ll n, m;
	cin >> n >> m;
	vl a(m);
	vl b(m);
	for (ll i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		p[a[i]]++;
		p[b[i]]++;
	}

	for (ll i = 0; i < A; i++) {
		if (p[i] % 2 != 0) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}


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

int main(void){
    int x,n;
    cin >> x >> n;

    if(n==0){
        cout << x << endl;
        return 0;
    }

    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());




    int absnum = 100000;
    int ans = -1;
    int j = 0;
    for(int i=0;i<=200;i++){
        if(i==p[j]){
            j++;
            continue;
        }

        int tmp = abs(x-i);
        if(tmp<absnum){
            absnum = tmp;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n+1);
  rep(i,n) cin >> a.at(i+1);
  
  vector<int> d(n+1,-1);
  
  int L=0,l=0,r=0;
  
    {
    int j = 1;
    d.at(1) = 0;
    rep(i,n){
      if(d.at(a.at(j)) == -1) {
        d.at(a.at(j)) = d.at(j)+1;
        j = a.at(j);
      }else{
        L = d.at(j)+1;
        l = d.at(a.at(j));
        r = L-l;
      }
    }
  }
  int ans;
  if(k < l) {
    rep(i,n+1){
      if(d.at(i) == k) cout << i << endl;
    }
  }
  
  if(k >= l){
    rep(i,n+1){
      if(d.at(i) == l + (k-l)%r) cout << i << endl;
    }
  }
  //cout << "ループの終端にたどりつくまでL = " << L << endl;
  //cout << "ループの長さr = " << r << endl;
  //cout << "ループにたどり着くまでl = " << l << endl;
}

Measured memory_bytes: 4832
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

double dist3(double x, double y, double z) {
    double d = x * x + y * y + z * z;
    return sqrt(d);
}

double crprd3(tddd p, tddd q) {
    double x = get<1>(p) * get<2>(q) - get<2>(p) * get<1>(q);
    double y = get<2>(p) * get<0>(q) - get<0>(p) * get<2>(q);
    double z = get<0>(p) * get<1>(q) - get<1>(p) * get<0>(q);
    return dist3(x, y, z);
}

double dtprd3(tddd p, tddd q) {
    double ans = 0;
    ans += get<0>(p) * get<0>(q);
    ans += get<1>(p) * get<1>(q);
    ans += get<2>(p) * get<2>(q);
    return ans;
}

tddd plus3(tddd p, tddd q) {
    double x = get<0>(p) + get<0>(q);
    double y = get<1>(p) + get<1>(q);
    double z = get<2>(p) + get<2>(q);
    return tddd(x, y, z);
}

tddd constprod3(double k, tddd p) {
    double x = k * get<0>(p);
    double y = k * get<1>(p);
    double z = k * get<2>(p);
    return tddd(x, y, z);
}

int main() {
    int N, Q;
    cin >> N >> Q;
    ll drpt[N][5];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> drpt[i][j];
        }
    }
    for (int i = 0; i < Q; i++) {
        ll pos[6];
        for (int j = 0; j < 6; j++) {
            cin >> pos[j];
        }
        ll ans = 0;
        ll line[3];
        for (int j = 0; j < 3; j++) {
            line[j] = pos[j] - pos[j + 3];
        }
        for (int j = 0; j < N; j++) {
            ll xyz[3];
            for (int k = 0; k < 3; k++) {
                xyz[k] = drpt[j][k] - pos[k + 3];
            }
            tddd l = tddd(line[0], line[1], line[2]);
            tddd xxyyzz = tddd(xyz[0], xyz[1], xyz[2]);
            double crp = crprd3(l, xxyyzz);
            double ldis = dist3(line[0], line[1], line[2]);
            double pre = dtprd3(l, xxyyzz);
            double ovr = dtprd3(constprod3(-1, l), plus3(xxyyzz, constprod3(-1, l)));
            //cout << pre << " " << ovr << " " << crp / ldis << " " << drpt[j][3]  << " " << drpt[j][4]<< endl;
            if (pre >= -1e-7 && ovr >= -1e-7 && crp / ldis - 1e-7 <= drpt[j][3]) {
                ans += drpt[j][4];
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3120
from collections import Counter
s = [i for i in str(input())]
t = [h for h in str(input())]
s1 = Counter(s).most_common()
t1 = Counter(t).most_common()
if len(s1) != len(t1):
    print('No')
else:
    z = 'Yes'
    for j in range(len(s1)):
        if s1[j][1] != t1[j][1]:
            z = 'No'
            break
    print(z)

Measured memory_bytes: 12432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read() {
	ll x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int n, m, v[1000005], p[1000005], tot, cnt[1000005];
void build(){
	for(int i=2;i<=1000000;i++){
		if(!v[i]){
			v[i]=i;
			p[++tot]=i;
		}
		for(int j=1;j<=tot;j++){
			if(p[j]>v[i]||(ll)p[j]*i>1000000) break;
			v[i*p[j]]=p[j];
		}
	}
}
int a[1000005];
int main() {
	build();
	cin>>n;
	int ok1=1;
	for(int i=1;i<=n;i++) {
		a[i]=read();
		int tmp=a[i];
		while(tmp!=1) {
			if(cnt[v[tmp]]) {
				ok1=0;
				break;
			}
			cnt[v[tmp]]=1;
			int now=v[tmp];
			while(tmp%now==0) tmp/=now;
		}
	}
	if(ok1) {
		cout<<"pairwise coprime";
		return 0;
	}
	int g=a[1];
	for(int i=2;i<=n;i++) {
		g=__gcd(a[i], g);
	}
	if(g==1) {
		cout<<"setwise coprime";
		return 0;
	}
	cout<<"not coprime";
}


Measured memory_bytes: 15592
n = int(input())
a = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in range(n):
    b,f,r,v = map(int,input().split())
    a[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        print(''.join(' {}'.format(a[b][f][r]) for r in range(10)))
    if b<3:
        print('#'*20)

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

int main() {
    while (true) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

ll S(ll n){
	if(n<10) return n;
	else return n%10+S(n/10);
}

double snuke(pair<ll,ll> p){
	return (double)p.first/p.second;
}

ll f(ll n){

	vector<pair<ll,ll> > res;

	for(int d = 0; d < 15; d++){
		ll x = pow(10,d)*floor((double)n/pow(10,d)+1)-1;
		pair<ll,ll> y;
		y.first = x;
		y.second = S(x);
		res.push_back(y);
	}

	ll m = res[0].first;
	double ms = snuke(res[0]);

	for(int i = 0; i < res.size(); i++){
		if(ms > snuke(res[i])){
			m = res[i].first;
			ms = snuke(res[i]);
		}
	}

	return m;
}

int main()
{
	ll k;
	cin >> k;
	ll a = 1;
	for(int i = 1; i <= k; i++){
		cout << a << endl;
		a = f(a+1);
	}

	return 0;
}


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

num4 = 0
num2 = 0
odd = 0
for i in a:
    if i%4 == 0:
        num4 += 1
    elif i%2 == 0 and i%4 != 0:
        num2 += 1
    elif i%2 == 1:
        odd += 1

if odd > num4+1:
    print("No")
else:
    if num2%2 == 1:
        if odd+1 > num4+1:
            print("No")
        else:
            print("Yes")
    else:
        print("Yes")
    


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	ll n,y;cin>>n>>y;
	for(ll i=0;i<=y/10000&&i<=n;i++){//10000
		for(ll j=0;j<=(y-i*10000)/5000&&j<=n-i;j++){//5000
			ll k=(y-i*10000-j*5000)/1000;
			if(i+j+k==n){
				cout<<i<<' '<<j<<' '<<k<<endl;
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
}

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

const int MAX = 510000;
const int mod = 1000000007;

ll 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;
    }
}

// 二項係数計算
ll 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;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans = 1e18;
    for(ll p=1;p<=100;p++){
        ll ret = 0;
        for(int i=0;i<n;i++){
            ret += (a[i]-p)*(a[i]-p);
        }
        ans = min(ans,ret);
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, k, a[114514], d[114514], s;

int main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	a[n] = a[0];
	rep(i,n) d[i] = a[i+1] - a[i];
	s = accumulate(a, a+n, 0ll);
	if (s%(n*(n+1)/2)!=0) {
		cout << "NO" << ln;
		return 0;
	}
	// k回操作を行う必要がある
	k = s/(n*(n+1)/2);
	rep(i,n) {
		if (d[i]-k>0 || (d[i]-k)%n!=0) {
			cout << "NO" << ln;
			return 0;
		}
	}
	cout << "YES" << ln;
}

Measured memory_bytes: 1792
def c_train_ticket(N):
    A, B, C, D = int(N[0]), int(N[1]), int(N[2]), int(N[3])
    op = ['---', '--+', '-+-', '-++', '+--', '+-+', '++-', '+++']
    ans = 0
    for i, j in enumerate(op):
        code = 'A {0} B {1} C {2} D'.format(j[0], j[1], j[2])
        if eval(code) == 7:
            ans = i
    return '{0}{1}{2}{3}{4}{5}{6}=7'.format(A, op[ans][0], B, op[ans][1], C, op[ans][2], D)
  
N = input()
print(c_train_ticket(N))

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

ll inf =1e9+7;

#define pi 3.14159265358979323846L
bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{

ll x;
cin>>x;


for(ll a=-200;a<200;a++)
{	
	ll z=pow(a,5);
	for(ll b=-200;b<200;b++)
	{
		ll y=pow(b,5);
		if(z-y==x )
		{
			cout<<a<<" "<<b;
			return;
		}
	}
}

}

int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 3940
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String week = sc.next();
    
    if(week.equals("SUN")){
      System.out.println(7);
    }else if(week.equals("MON")){
      System.out.println(6);
    }else if(week.equals("TUE")){
      System.out.println(5);
    }else if(week.equals("WED")){
      System.out.println(4);
    }else if(week.equals("THU")){
      System.out.println(3);
    }else if(week.equals("FRI")){
      System.out.println(2);
    }else if(week.equals("SAT")){
      System.out.println(1);
    }else{}
  }
}


Measured memory_bytes: 21844
package main

import (
	"fmt"
)

const LARGE = 100000 * 10000 * 2

var h [100000]int
var c [100000]int

func abs(x int) int {
	if x >= 0 {
		return x
	} else {
		return -x
	}
}

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	c[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		c[i] = LARGE
		for j := 1; i+j < n && j <= k; j++ {
			a := c[i+j] + abs(h[i+j]-h[i])
			c[i] = min(a, c[i])
		}
	}

	fmt.Printf("%d\n", c[0])
}


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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a-b)>d or abs(b-c)>d) and abs(a-c)>d) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
function Main(arg) {
    const input = arg.trim().split('\n');
    const d = parseInt(input[0].split(' ')[1], 10);

    let count = 0;
    for(let i=1; i<input.length; i++){
        const xy = input[i].split(' ');
        const x = parseInt(xy[0], 10);
        const y = parseInt(xy[1], 10);
        const ret = Math.sqrt((x*x) + (y*y));
        if(ret <= d) {
            count++;
        }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 62600
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

struct UnionFind {
    vector<int> parent;

    UnionFind(int n) : parent(n) {
        for (int i = 0; i < n; i++) parent[i] = i;
    }

    int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        int rootX = root(x);
        int rootY = root(y);
        if (rootX == rootY) return;
        parent[rootX] = rootY;
    }
};

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

    UnionFind tree(n);
    for (int i = 0; i < m; i++) {
        int a, b, z;
        cin >> a >> b >> z;
        --a, --b;

        tree.unite(a, b);
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        if (tree.parent[i] == i) ++res;
    }
    cout << res << endl;
}


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

ll A[200000];

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

	int N;
	cin >> N;

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

	ll ans = 1LL << 60;
	ll x = 0, y = sum;
	for(int i = 0; i < N - 1; i++) {
		x += A[i];
		y -= A[i];
		ans = min(ans, abs(x - y));
	}
	cout << ans << endl;
}


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

int main()
{
    vector<int> v(3);
    for(int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        v[i] = x;
    }

    for(int j = 0; j < 2; j++) {
        for(int k = j + 1; k < 3; k++) {
            if(v[j] > v[k]) {
                int tmp;
                tmp = v[j];
                v[j] = v[k];
                v[k] = tmp;
            }
        }
    }

    cout << v[0] << " " << v[1] << " " << v[2] << endl;
    
    return 0;
}




Measured memory_bytes: 3116
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

int main()
{
    int n;
    int p[20];
    int count=0;
    std::cin >> n;
    for(int i=0; i<n;i++){
        std::cin >> p[i];
    }   
    for(int i=1; i<n-1;i++){
        if((p[i-1] <p[i] && p[i]<p[i+1])|| (p[i+1]<p[i] && p[i] <p[i-1])){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m;
vector<int> s, t;
int dp[2010][2010];
bool vis[2010][2010];

int solve(int x, int y)
{
    if (vis[x][y])
        return dp[x][y];
    vis[x][y] = true;
    if (x == 0 || y == 0)
        return dp[x][y] = 1;
    if (s[x - 1] == t[y - 1])
        (dp[x][y] += (solve(x - 1, y - 1))) %= mod;
    (dp[x][y] += (solve(x - 1, y) + solve(x, y - 1) - solve(x - 1, y - 1))) %= mod;
    if (dp[x][y] < 0)
        dp[x][y] += mod;
    return dp[x][y];
}

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

    cin >> n >> m;
    s.resize(n), t.resize(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    cout << solve(n, m) << endl;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;


signed main(){
    int N;
    int Ans=0;
    int A[114514]={},B[114514],C[114514];
    ZREP(i,114514){A[i]=INF;}
    cin >> N;
    REP(i,N){cin >> A[i];}sort(A,A+N+1);
    REP(i,N){cin >> B[i];}sort(B,B+N);
    REP(i,N){cin >> C[i];}C[N]=INF;sort(C,C+N+1);
    REP(i,N){
        
        int sum1=distance(A,lower_bound(A,A+N,B[i]));
        int sum2=N - distance(C,lower_bound(C,C+N,B[i]+1));
        Ans+=sum1*sum2;
    }
    cout << Ans << endl;
    return 0;
}   


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<pair<int, int>> a(m);
	rep(i,m){
		cin >> a[i].second >> a[i].first;
		a[i].first--;
	}

	sort(all(a));

	int cur = 0, ans = 0;
	rep(i,m){
		if(cur >= a[i].second and cur <= a[i].first) continue; 
		ans++;
		cur = a[i].first;
	}
	cout << ans << endl;
}


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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int n;
  string c;
  int card[10];
  int ba;
  
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    
    cin>>c;

    fill(card,card+10,0);
    ba=0;
    for(int i=0;i<100;i++){
      int p=i%n;
      if(c[i]=='S'){
	ba+=card[p]+1;
	card[p]=0;
      }else if(c[i]=='L'){
	card[p]+=ba+1;
	ba=0;
      }else{
	card[p]++;
      }
    }
    
    sort(card,card+n);
    for(int i=0;i<n;i++){
      printf("%d ",card[i]);
    }
    printf("%d\n",ba);
  }
	
  
  return (0);
}



Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
inline void re(int &x)
{
	x=0;bool flag=false;
	char c=getchar();
	while(c<'0'||c>'9'){
		flag= c=='-';
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+(c^'0');
		c=getchar();
	}
	if(flag)x=-x;
	return ;
}
int a[100010],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i+1]<=i)
		{
			int r=i;
			while(a[r+1]==i)r++;
			ans=(((a[i]-i+1)&1)&((r-i+1)&1))^1;
			break;
		}
	}
	if(ans)printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
A,B,K=map(int,input().split())
Q=[]
for i in range(K):
    if A+i<=B:
        Q.append(A+i)
for i in range(K):
    if B-K+i+1>=A:
        Q.append(B-K+i+1)
U=list(set(Q))
U=sorted(U)
for i in U:
    print(i)

Measured memory_bytes: 3064
n=gets.to_i-1
a=gets.split.map &:to_i
c=0
(0..n).map{|i|m=i
(m..n).map{|j|a[m]>a[j]&&m=j}
i!=m&&(a[i],a[m]=a[m],a[i])&&c+=1}
puts a*" ",c

Measured memory_bytes: 6140
#include <stdio.h>

int main(void)
{
	int i;
	int area;
	int n;

	while (scanf("%d", &n) != EOF){
		area = 0;

		for (i = n; i < 600; i += n){
			area +=  n * i * i;
		}

		printf("%d\n", area);
	}

	return (0);
}

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

#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
set <int> lin, col;
map <int, int> vall, valc;
int x[N], y[N], n, use[2 * N];
long long ans;
vector <pair<int, int> > v[2 * N];
vector <int> l, c;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
		lin.insert(x[i]);
		col.insert(y[i]);
	}

	int nr = 0;
	for(auto i : lin) vall[i] = ++nr, l.push_back(i);
	for(auto i : col) valc[i] = ++nr, c.push_back(i);

	for(int i = 1; i < l.size(); i++) {
		v[vall[l[i - 1]]].push_back({l[i] - l[i - 1], vall[l[i]]});
		v[vall[l[i]]].push_back({l[i] - l[i - 1], vall[l[i - 1]]});
	}

	for(int i = 1; i < c.size(); i++) {
		v[valc[c[i - 1]]].push_back({c[i] - c[i - 1], valc[c[i]]});
		v[valc[c[i]]].push_back({c[i] - c[i - 1], valc[c[i - 1]]});
	}

	for(int i = 1; i <= n; i++) {
		v[vall[x[i]]].push_back({0, valc[y[i]]});
		v[valc[y[i]]].push_back({0, vall[x[i]]});
	}

	use[1] = 1;
	priority_queue <pair<int, pair<int, int> > > pq;

	for(auto i : v[1]) pq.push({-i.st, {1, i.nd}});

	while(!pq.empty()) {
		pair<int, int> pp = pq.top().nd;
		int val = -pq.top().st;
		int cand = -1;
		pq.pop();
		if(!use[pp.st]) cand = pp.st;
		else if(!use[pp.nd]) cand = pp.nd;

		if(cand != -1) {
			use[cand] = 1;
			for(auto i : v[cand]) pq.push({-i.st, {cand, i.nd}});
			ans += val;
		}
	}
	cout << ans << '\n';

}


Measured memory_bytes: 45164