akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> p(n);
  REP(i, n) {
    ll ina, inb;
    cin >> ina >> inb;
    p[i] = {ina, inb};
  }
  sort(ALL(p));
  ll cnt = 0;
  REP(i, n) {
    ll a, b;
    tie(a, b) = p[i];
    cnt += b;
    if (cnt >= k) {
      cout << a<< "\n";
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4748
n=int(input())
s=input()

#Eが出てくる回数の累積和を取る(O(n))
l=[0]
l_tmp=0
for i in range(n):
    if s[i]=="E":
        l_tmp+=1
        l.append(l_tmp)
    else:
        l.append(l_tmp)

#クエリ(O(n))

ans=n
for j in range(1,n+1):
    #j番目より左のWの数は(j-1)-l[j-1]
    #j番目より右のEの数はl[-1]-l[j]
    ans=min(ans,(j-1)-l[j-1]+l[-1]-l[j])
    
print(ans)

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

int main(){
	int N, K;
	scanf("%d%d", &N,&K);
	
	double ans=0;
	
	for(int i=1; i<=N; i++){
	   double prob = 1.0/N;
	   int score = i;
	   while(score<K) {
	      score *= 2;
	      prob /= 2;
	   }
	   ans += prob;
	}
	
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

uf = UnionFind(n)
f = [0 for i in range(n)]
ans = []

for a, b in ab:
    uf.union(a-1, b-1)
    f[a-1] += 1
    f[b-1] += 1

for i in range(n):
    ans.append(-uf.parents[uf.find(i)]-f[i] - 1)

for c,d in cd:
    if uf.find(c-1) == uf.find(d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1
print(" ".join([str(i) for i in ans]))


Measured memory_bytes: 67556
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  string s;
  cin >> s;
  vector<int> a(s.size());
  for (int i = 0; i < s.size(); i++)
  {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T')
    {
      a.at(i) = 1;
    }
    else
    {
      s.at(i) = 0;
    }
  }
  vector<int> nums;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (a.at(i) == 1)
    {
      cnt++;
    }
    else
    {
      nums.push_back(cnt);
      cnt = 0;
    }
  }
  if (cnt != 0)
  {
    nums.push_back(cnt);
  }
  int ans = 0;
  for (int i = 0; i < nums.size(); i++)
  {
    ans = max(ans, nums.at(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# 全域木？っていうんだっけ？でもコストは関係ないか
# 適当に隣接リストでもってしてDFSする
N, M = map(int, input().split())
Neighbor_list = [[] for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    Neighbor_list[s-1].append(t-1)
    Neighbor_list[t-1].append(s-1)


def dfs(cur, path):
    if len(path) == N:
        return 1
    else:
        ret = 0
        for neighbor in Neighbor_list[cur]:
            if neighbor not in path:
                next_list = path[:]
                next_list.append(neighbor)
                ret += dfs(neighbor, next_list)
        return ret


print(dfs(0, [0]))


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

    int a, b, ans;
    cin >> a >> b;
    ans = a - b + 1;

    cout << ans << endl;

    return 0;
}

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

def factorization(n):
    arr = []
    temp = n
    i=2
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

cnt=0
for a in A:
    f=factorization(a)[0]
    if f[0]==2:
        cnt+=f[1]

print(cnt)

Measured memory_bytes: 4276
import math

def koch(n, ax, ay, bx, by):
    if n == 0: return ;
    
    sin = math.sin(math.radians(60))
    cos = math.cos(math.radians(60))
    
    sx = (2.0 * ax + 1.0 * bx) / 3.0
    sy = (2.0 * ay + 1.0 * by) / 3.0
    tx = (1.0 * ax + 2.0 * bx) / 3.0
    ty = (1.0 * ay + 2.0 * by) / 3.0
    ux = (tx - sx) * cos - (ty - sy) * sin + sx
    uy = (tx - sx) * sin + (ty - sy) * cos + sy
    
    koch(n-1, ax, ay, sx, sy)
    print(str(sx)+ " " + str(sy))
    koch(n-1, sx, sy, ux, uy)
    print(str(ux)+ " " + str(uy))
    koch(n-1, ux, uy, tx, ty)
    print(str(tx)+ " " + str(ty))
    koch(n-1, tx, ty, bx, by)

if __name__ == '__main__':
    n = int(input())
    ax = 0.00000000
    ay = 0.00000000
    bx = 100.00000000
    by = 0.00000000
    
    print(str(ax) + " " + str(ay))
    koch(n, ax, ay, bx, by)
    print(str(bx)+ " " + str(by))


Measured memory_bytes: 5740
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N, T, A;
  cin >> N;
  cin >> T >> A;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) cin >> H.at(i);
  int out;
  double temp_diff;
  for (int i = 0; i < N; ++i) {
    double t = T - 0.006 * H.at(i);
    double diff = abs(A - t);
    if (i == 0) {
      temp_diff = diff;
      out = i + 1;
    } else if (temp_diff > diff) {
      temp_diff = diff;
      out = i + 1;
    }
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int main() {
	int n, m;
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		vector<ll> v(n);
		rep(i, n) cin >> v[i];

		vector<ll> p;
		rep(i, n) p.push_back(v[i]);

		rep(i, n) {
			REP(j, i, n) {
				p.push_back(v[i] + v[j]);
			}
		}

		sort(p.begin(), p.end());
		ll ans = 0;
		rep(i, p.size()) {
			int id = upper_bound(p.begin(), p.end(), m - p[i]) - p.begin();
			if(id == 0) {
				if(p[i] <= m) ans = max(ans, p[i]);
			}
			else ans = max(ans, p[i] + p[id-1]);
		}

		cout << ans << endl;
	}

	return 0;
}

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

struct joutai{
  int saisyou;
  int migihasi;
};

struct joutai dp[1048576];
int ruiseki[20][100001];

int bekijou[21];

int main(){
  bekijou[0]=1;
  for(int i=1;i<=20;i++){
    bekijou[i]=2*bekijou[i-1];
  }
  int n, m;
  cin >> n >> m;
  int narabi;
  int kosuu[20];
  for(int i=0;i<m;i++){
    kosuu[i]=0;
    ruiseki[i][0]=0;
  }
  for(int i=0;i<n;i++){
    cin >> narabi;
    narabi--;
    kosuu[narabi]++;
    for(int j=0;j<m;j++){
      ruiseki[j][i+1]=ruiseki[j][i];
    }
    ruiseki[narabi][i+1]++;
  }
  dp[0]={0,0};
  int toridasu;
  for(int i=1;i<bekijou[m];i++){
    dp[i].saisyou=10000000;
    for(int j=0;j<20;j++){
      if(i&(1<<j)){
        toridasu = dp[i^(1<<j)].saisyou + kosuu[j]
         + ruiseki[j][dp[i^(1<<j)].migihasi] - ruiseki[j][dp[i^(1<<j)].migihasi+kosuu[j]];
        dp[i].saisyou=(toridasu<dp[i].saisyou)?toridasu:dp[i].saisyou;
        dp[i].migihasi=dp[i^(1<<j)].migihasi+kosuu[j];
      }
    }
  }

  cout << dp[bekijou[m]-1].saisyou << endl;

  return 0;
}


Measured memory_bytes: 19060
#include <stdio.h>

int main(void)
{
        int k,i,j,s=0;

        scanf("%d",&k);

        for (i=1;i<=k;i=i+2){
                for (j=2;j<=k;j=j+2){
                        s++;
                }
        }

        printf("%d\n",s);

        return 0;
}


Measured memory_bytes: 128
// 2012/12/14 Tazoe

#include <iostream>
using namespace std;

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

if(n==0)
break;

	bool T[201];
	bool H[201];
	for(int i=0; i<=200; i++){
		T[i] = H[i] = false;
	}

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

		T[m] = true;
	}

	for(int i=1; i<=2*n; i++){
		if(!T[i]){
			H[i] = true;
		}
	}

	int n_T = n;
	int n_H = n;

	int f = 0;
	int t = 0;

	while(true){
		if(t==0){
			int i;
			for(i=f+1; i<=2*n; i++){
				if(T[i]){
					f = i;
					T[i] = false;
					n_T--;
					break;
				}
			}

			if(i>2*n){
				f = 0;
			}
		}
		else{
			int i;
			for(i=f+1; i<=2*n; i++){
				if(H[i]){
					f = i;
					H[i] = false;
					n_H--;
					break;
				}
			}

			if(i>2*n){
				f = 0;
			}
		}

		if(n_T==0||n_H==0)
			break;

		t = (t+1)%2;
	}

	cout << n_H << '\n';
	cout << n_T << '\n';
}

	return 0;
}

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

int main() {
  int A, B, C ,D;
  cin >> A >> B >> C >> D;
  
  if ((A + B) > (C + D))
    cout << "Left" << endl;
  
  else if ((A + B) == (C + D))
    cout << "Balanced" << endl;
  
  else
    cout << "Right" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n;
ll a[N];

void solve()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1);
    ll mx = a[n];
    if (mx % 2 == 0)
    {
        ll mid = a[n] / 2;
        ll ans2 = a[1], now = llinf;
        for (int i = 1; i <= n; ++i)
        {
            if (abs(a[i] - mid) < now)
            {
                now = abs(a[i] - mid);
                ans2 = a[i];
            }
        }
        printf("%lld %lld\n", mx, ans2);
    }
    else
    {
        ll mid1 = a[n] / 2, mid2 = a[n] / 2 + 1;
        ll ans2 = a[1], now = llinf;
        for (int i = 1; i <= n; ++i)
        {
            if (min(abs(a[i] - mid2), abs(a[i] - mid1)) < now)
            {
                now = min(abs(a[i] - mid2), abs(a[i] - mid1));
                ans2 = a[i];
            }
        }
        printf("%lld %lld\n", mx, ans2);
    }
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 1152
# coding: utf-8
N = int(input())
s = 0
l = []
for i in range(N):
    t = int(input())
    s += t
    if t % 10 != 0:
        l.append(t)
if str(s)[-1] != "0":
    print(s)
elif len(l) == 0:
    print(0)
else:
    l.sort()
    print(s - l[0])

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	double radius, area, length;
	double PI = 3.141592653589793;
	
	scanf("%lf", &radius);
	
	//円の面積
	area = PI * radius * radius;
	//円周の長さ
	length = 2 * PI * radius;
	
	printf("%lf %lf\n", area, length);
	return 0;
}


Measured memory_bytes: 2112
s = input()
n = len(s)

string = '0'
ans1 = 0
for i in range(n):
	if s[i] != string:
		ans1 += 1
	if string == '0':
		string = '1'
	else:
		string = '0'

string = '1'
ans2 = 0
for i in range(n):
	if s[i] != string:
		ans2 += 1
	if string == '0':
		string = '1'
	else:
		string = '0'

print(min(ans1,ans2))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
    ll x,y,z;
    cin>>x>>y>>z;
    ll ans=1;
    ans+=(x-y-2*z)/(y+z);
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=110;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int f[N][N*N];
const int mod=1e9+7;
int main()
{
	int n=gi(),k=gi(),i,j,t,ans=k*(k+1)/2*n;
	for (i=1;i<n;i++) ans=1LL*ans*(k+1)%mod;
	f[n][0]=1;
	for (i=n;i;i--)
		for (j=0;f[i][j];j++)
			for (t=0;t<=k;t++)
				(f[i-1][j+(t<=i?(j+t)/i:0)]+=f[i][j])%=mod;
	for (j=0;f[0][j];j++) ans=(ans-1LL*j*f[0][j])%mod;
	cout<<(ans+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 2560
import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    var aList = readInputLine().split(" ").map { it.toLong() }
    
    val allXor = aList.fold(0L, { all, elem -> all xor elem })
    val aArr = aList.map { it and allXor.inv() }.toLongArray()
    
    var rank = 0
    for (i in 59 downTo 0) {
        var j = rank
        while (j < N) {
            if (aArr[j] and (1L shl i) != 0L) {
                break
            }
            j++
        }
        if (j == N) {
            continue
        }
        
        if (j > rank) {
            aArr[rank] = aArr[rank] xor aArr[j]
        }
        
        for (j in rank + 1 until N) {
            aArr[j] = Math.min(aArr[j], aArr[j] xor aArr[rank])
        }
        
        rank++
    }
    
    println(aArr.fold(0L) { acc, a ->
        Math.max(acc, acc xor a)
    } * 2L + allXor)
}

fun readInputLine(): String {
    return readLine()!!
}



Measured memory_bytes: 75852
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean isLoop = true;
        if (n % 2 == 0){
            isLoop = false;
        }
        if (n % 5 == 0){
            isLoop = false;
        }

        int k  = 1000000;
        int mod = 0;
        boolean isAnswer = false;
        if (isLoop) {
            for (int i = 1; i < k; i++) {
                mod = (mod * 10 + 7) % n;
                if (mod == 0){
                    System.out.println(i);
                    isAnswer = true;
                    break;
                }else{
//                    System.out.println(mod);
                }

            }
        }
        if (!isAnswer) {
            System.out.println("-1");
        }
    }
}


Measured memory_bytes: 35824
#include<iostream>
#include<bits/stdc++.h>
#include<array>
using namespace std;
#define int long long
#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests int t; cin >> t; while(t--){ solve(); cout << endl; }
#define without_tests solve(); cout << endl;
#define CEIL(x, y) (ll)ceil((long double)(x)/(long double)(y))
#define epsilon 1e-9 
typedef long long ll;
const int mod = 1e9+7;
const int N = 1e5+1;

void solve(){
    
    
    int n;
    cin >> n;
    vector<int> a(n), pref(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    pref[n-1] = a[n-1];
    for(int i=n-2; i>=0; i--){
        pref[i] = (pref[i+1] + a[i])%mod;
    }
    int ans = 0;
    for(int i=0; i<n-1; i++){
        ans = (ans + (a[i]*pref[i+1])%mod)%mod;
    }
    cout << ans;

}

int32_t main(){

    fast_cin;
    // with_tests;
    without_tests;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    int a = 0, b = 0;
    for(int i = 0 ; i < n; i++){
        if(i % 2 == 0){
            a += v[i];
        } else {
            b += v[i];
        }
    }
    cout <<  a - b << endl;
    return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  s.resize(s.size() - 8);
  cout << s << endl;

  return 0;
}



Measured memory_bytes: 256
#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;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

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

	      	  int N;
	      	  cin >> N;
	      	  map<int,int> mp;
	      	  for(i=1;i<=N;i++){
	      		  int a;
	      		  cin >> a;
	      		  mp[a]++;
	      	  }

	      	  int ans=0;
	      	  foreach(mp,itr){
	      		  if((*itr).first==(*itr).second) continue;
	      		  if((*itr).first>(*itr).second) ans+=(*itr).second;
	      		  else ans+=(*itr).second-(*itr).first;
	      	  }

	      	  cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 4736
package main

import (
	"fmt"
)

func main() {
	var r,d,x2000 int
	fmt.Scan(&r,&d,&x2000)
	
	x := make([]int, 11)
	x[0] = r*x2000 - d
	fmt.Println(x[0])
	for i:=1; i<10; i++ {
		x[i] = r*x[i-1] - d
		fmt.Println(x[i])
	}
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }
        else if(a>b){
            System.out.println("a > b");
        }
        else{
            System.out.println("a == b");
        }
        }
    }


Measured memory_bytes: 26204
N = int(input())
t = []
x = []
y = []
for i in range(N + 1):
    t.append(0)
    x.append(0)
    y.append(0)

for i in range(1, N + 1):
    t[i], x[i], y[i] = map(int, input().split())

f = 0
for i in range(N):
    abs_list = []
    a = t[i + 1] - t[i]
    while a >= 0:
        abs_list.append(a)
        a += -2
    if abs(x[i] - x[i + 1] + y[i] - y[i + 1]) not in abs_list:
        f += 1
if f >= 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 11832
#include<bits/stdc++.h>
using namespace std; 
 
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"


int main(){
	IOS;
		long long int n,ans=1;
		cin >> n;
	long long int a[n];
		long long int mx = 1e18;
		for(int i=0; i<n; i++){
			cin >> a[i];
			if(a[i] == 0){
				ans = 0;
				}
			}
			if(ans == 0){
			cout << ans << endl;
		}else{
		for(int i=0; i<n; i++){
			if(a[i] > mx/ans){
				ans = -1;
				break;
				}else{
					ans *= a[i];
					}
		if(ans > mx){
			ans= -1;
			break;
			}
			}
		cout << ans << endl;
	}
	return 0;	
}



Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N,M;cin >> N >> M;
  if(N==1&&M==1) cout << 1 << endl;
  else if(N==1||M==1) cout << max(0ll,max(N,M)-2) << endl;
  else cout << (N-2)*(M-2) << endl;
  return 0;
}


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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int tenth = max(a, max(b,c));
  if (tenth == a) {
    a = 0;
  }
  else if (tenth == b) {
    b = 0;
  }
  else {
    c=0;
  }
  cout << tenth*10 +  a + b + c << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int n,t; double a;
  cin >> n >> t >> a;
  int ans=-1;
  double b=inf;
  rep(i,n){
    int h;
    cin>>h;
    if(b>abs(a-(t-h*0.006))){
      b=abs(a-(t-h*0.006));
      ans=i+1;
    }
  }

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


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int[] data = new int[3];
      int sum = 0;
      for(int i =0;i<3;i++){
        data[i] = sc.nextInt();
      }

      Arrays.sort(data);

      sum = Math.abs(data[1]-data[0]);
      sum = sum + Math.abs(data[1]-data[2]);

      System.out.println(sum);

      }

  }


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vpii ans;
    if (n%2) {
        for (int l=1,r=n-1; l<r; ++l,--r) {
            ans.emplace_back(l, r);
        }
    }
    else {
        bool flug = false;
        for (int l=1,r=n-1; l<r; ++l,--r) {
            if (!flug&&r-l<=n/2) {
                --r;
                flug = true;
            }
            ans.emplace_back(l, r);
        }
    }
    rep(i, m) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}


Measured memory_bytes: 4236
import itertools

N = int(input())
ans = 0

shichigosan = ["3", "5", "7"]

for i in range(3, 11):
    shichi_nums = itertools.product(shichigosan, repeat=i)
    for nums in shichi_nums:
        # print(nums)
        num = "".join(nums)
        if "3" in num and "5" in num and "7" in num:
            num = int(num)
            if num <= N:
                # print(num, ans)
                ans += 1
            else:
                print(ans)
                quit()


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T>;
void in() {}; template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); };
template <typename T> void _out(const char *sep, const char *end, T &&x) { cout << x << end; };
template <typename T, typename...TS> void _out(const char *sep, const char *end, T &&x, TS &&...xs) { cout << x << sep; _out(sep, end, move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t _; cin >> _; return _; }()
#define put(...) _out("", "", __VA_ARGS__)
#define out(...) _out(" ", "\n", __VA_ARGS__)
#define times(n, i) for (i32 i =  0 ; i <  (n); ++i)
#define range(a, b, i) for (i32 i = (a); i <  (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 n, k;
i64 a[200000];
i64 b[200001];

struct fenwicktree {
	i32 n;
	vec<i64> data;
	fenwicktree(i32 size) : n(size), data(size + 1, 0) { }
	void add(i32 i, i64 x) { for (++i; i <= n; i += (i&-i)) data[i] += x; }
	i64 sum(i32 i) { i64 acc = 0; for (++i; 0 < i; i -= (i&-i)) acc += data[i]; return acc; }
};

i32 main()
{
	in(n, k);
	times(n, i) {
		in(a[i]);
		a[i] -= k;
	}
	vec<i64> comp; comp.append(0);
	range(1, n+1, i) {
		b[i] = b[i - 1] + a[i - 1];
		comp.append(b[i]);
	}
	sortall(comp);
	map<i64, i64> m;
	upto(0, n, i) {
		if (m.find(comp[i]) == m.end()) {
			m.insert(make_pair(comp[i], m.size()));
		}
	}
	i64 ans = 0;
	fenwicktree tree(n + 1);
	upto(0, n, i) {
		i64 c = m.at(b[i]);
		ans += tree.sum(c);
		tree.add(c, 1);
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 19184
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	string s; cin >> s;
	int k; cin >> k;
	set<int>  a;

	fo(i,k){
		int x; cin >> x;
		a.insert(x);
	}

	vi le;

	fo(i,10) if(a.find(i)==a.end()) le.pb(i);

	debug() << deb(a);

	bool ok = 1;
	fo(i,sz(s)){
		int x = s[i]-'0';
		// cout << x << " ";
		if(a.find(x)!=a.end()){
			ok=0;
			break;
		}
	}

	if(ok){
		cout << s << endl;
		return 0;
	}


	// debug() << "saif";

	sort(le.begin(), le.end());
	int n = stoi(s);

	for(int i=n;;i++){
		bool ok =  1;
		int temp=i;
		while(temp!=0){
			int rem = temp%10;
			temp /= 10;
			if(a.find(rem)!=a.end()){
				ok=0;
				break;
			}
		}
		if(ok){
			cout << i << endl;
			return 0;
		}	
	}
	
	return 0;
}

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

int main() {
  vector<int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  sort(vec.begin(),vec.end());
  
  cout << vec[0] + vec[1] << endl;
}


Measured memory_bytes: 256
//Problem D
#include<bits/stdc++.h>
using namespace std;
const int p=1000000007;
int h,w,k,dp[105][9],x[9];
int upd(int &a,int b){a+=b;if(p<=a)a-=p;return a;}
int main(){
    dp[0][1]=1;scanf("%d%d%d",&h,&w,&k);
    for(int i=1;i<=h;i++){
        for(int j=0;j<1<<(w-1);j++){
            memset(x,0,sizeof(x));int f=1;
            for(int k=0;k<w;k++)if(1<<k&j)x[k+1]=1;
            for(int k=1;k<w;k++)if(x[k]&&x[k+1])f=0;
            if(f)for(int k=1;k<=w;k++){
                int K=k;
                if(x[k-1])--K;else if(x[k])++K;
                upd(dp[i][K],dp[i-1][k]);
            }
        }
    }
    printf("%d",dp[h][k]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void){
    int n,a,b; //n=s.length,

    cin >> n >> a >> b;
    string s;
    cin >> s;

    int acount=0,bcount=0;
    for(int i = 0;i < n;i++){
        if((acount + bcount) >= (a + b)){
            cout << "No" << endl;
            continue;
        }

        if(s[i] == 'a'){
            acount++;
            cout << "Yes" << endl;
        } else if (s[i] == 'b' && bcount < b){
            bcount++;
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
def main(argv)
  n = gets.chomp.to_i
  a = gets.chomp.split(' ').map(&:to_i)

  k = 0
  n.times{ |i| k += 1 if a[i] % 2 == 0 }

  s = (3 ** n) - (2 ** k)
  puts s.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        if((A * B) > (C * D)) System.out.println(A * B);
        else System.out.println(C * D);
	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll gcd(ll a,ll b){while(b!=0){a%=b; swap(a,b);} return a;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A,B,C;
  cin>>A>>B>>C;
  ll X=3*C;
  cout<<A<<" "<<B<<" "<<X-A-B<<endl;
  cout<<X-A-(X-C-(X-A-B))<<" "<<C<<" "<<X-(X-A-B)-(X-A-C)<<endl;
  cout<<X-C-(X-A-B)<<" "<<X-B-C<<" "<<X-A-C<<endl;
  

  return 0;
}


Measured memory_bytes: 384
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;

int64_t powm(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powm(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}

int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		a.push_back(temp);
	}
	a[0]-=1;
	bool possible=true;
	for(ll i1=0;i1<n-1;i1++){
		if(a[i1]<=a[i1+1]-1){
			a[i1+1]-=1;
		}else if(a[i1]==a[i1+1]){

		}else{
			possible=false;
		}
	}
	if(possible){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


}


Measured memory_bytes: 1400
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <ctime>
using namespace std ;
#define SET(arr, what)  memset(arr, what, sizeof(arr))
#define FF(i, s, e)     for(int i=s; i<e; i++)
#define SD(a)           scanf("%d", &a)
#define SSD(a, b)       scanf("%d%d", &a, &b)
#define SF(a)           scanf("%lf", &a)
#define SS(a)           scanf("%s", a)
#define SLD(a)          scanf("%lld", &a)
#define PF(a)           printf("%d\n", a)
#define PPF(a, b)       printf("%d %d\n", a, b)
#define SZ(arr)         (int)arr.size()
#define SWAP(a,b)       a=a xor b;b= a xor b;a=a xor b;
#define READ            freopen("in.txt", "r", stdin)
#define WRITE           freopen("fracdec.out", "w", stdout)
#define SYNCOFF         std::ios_base::sync_with_stdio(false);
#define MAX             1<<30
#define ESP             1e-5
#define lson            l, m, rt<<1
#define rson            m+1, r, rt<<1|1
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline void AMin(T &a,T b){if(a>b)a=b;}
template<class T> inline void AMax(T &a,T b){if(a<b)a=b;}
template<class T> inline T Min(T a,T b){return a>b?b:a;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}



std::map<string,int> flag;
struct status
{
  int pos;
  int n;
  string chess;
  status(int pos,int n,string chess)
  {
    this->pos = pos;
    this->n = n;
    this->chess = chess;
  }
};

std::vector<std::vector<int> > trans(8,std::vector<int>());

int bfs()
{
  std::queue<status> Q;
  Q.push(status(0,0,"01234567"));
  flag["01234567"] = 0;

  while(!Q.empty())
    {
      status tmp = Q.front();
      Q.pop();

      for(int i = 0 ; i < trans[tmp.pos].size(); i++)
	{
	  int pos = trans[tmp.pos][i];
	  string chess = tmp.chess;
	  SWAP(chess[pos],chess[tmp.pos]);
	  int n = tmp.n + 1;
	  if(flag.count(chess) == 0)
	    {
	      flag[chess] = n;
	      Q.push(status(pos,n,chess));
	    }
	}
      
    }
  return 0;
}

int main(int argc,char* argv[])
{
  trans[0].push_back(1);
  trans[0].push_back(4);
  
  trans[1].push_back(0);
  trans[1].push_back(2);
  trans[1].push_back(5);

  trans[2].push_back(1);
  trans[2].push_back(3);
  trans[2].push_back(6);

  trans[3].push_back(2);
  trans[3].push_back(7);

  trans[4].push_back(5);
  trans[4].push_back(0);
  
  trans[5].push_back(4);
  trans[5].push_back(6);
  trans[5].push_back(1);

  trans[6].push_back(5);
  trans[6].push_back(7);
  trans[6].push_back(2);

  trans[7].push_back(6);
  trans[7].push_back(3);

  bfs();
  int ch;
  SYNCOFF;
  while(std::cin>>ch)
    {
      string str;
      str.push_back((char) (ch + '0'));
      for(int i = 0 ; i < 7 ; i++)
	{
	  std::cin>>ch;
	  str.push_back((char)(ch + '0'));
	}
      //std::cout<<str<<std::endl;
      std::cout<<flag[str]<<std::endl;
    }
  return 0;
}

Measured memory_bytes: 5288
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
double round(double r)
{
    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}

int main()
{
    int x,n,t;
    cin>>n>>x>>t;
    int m=n/x;
    int ans=t*m;
    if(m*x<n)
        cout<<ans+t;
    else
        cout<<ans;
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    map<int,int> cnt;
    REP(i,N){
        int a; cin>>a;
        cnt[a]++;
    }
    
    int ans=0;
    for(auto p:cnt){
        if(p.second%2==1) ans++;
    }
    cout<<ans<<endl;
}


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

struct P {
    int cnt;
    string word;
    bool operator < (const P& p) const {
        return (cnt != p.cnt ? cnt > p.cnt : word < p.word);
    }
};

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

    int n;
    while(cin >> n && n){
        cin.ignore();

        vector<string> str(n);
        for(int i = 0; i < n; ++i){
            getline(cin, str[i]);
        }

        char c;
        cin >> c;

        vector<P> vec;
        for(int k = 0; k < n; ++k){
            for(size_t i = 0; i < str[k].size(); ++i){
                if((i == 0 || str[k][i - 1] == ' ') && str[k][i] == c){
                    size_t j = i;
                    string s;
                    while(j < str[k].size()){
                        if(str[k][j] == ' '){
                            s = str[k].substr(i, j - i);
                            break;
                        }
                        if(j == str[k].size() - 1){
                            s = str[k].substr(i, j - i + 1);
                            break;
                        }
                        ++j;
                    }
                    //cout << s << endl;

                    bool check = false;
                    for(size_t i = 0; i < vec.size(); ++i){
                        if(vec[i].word == s){
                            ++vec[i].cnt;
                            check = true;
                            break;
                        }
                    }

                    if(!check){
                        vec.push_back(P{1, s});
                    }
                }
            }
        }

        sort(vec.begin(), vec.end());

        if(vec.empty()){
            cout << "NA";
        }

        for(int i = 0; i < min(5, (int)vec.size()); ++i){
            if(i != 0) cout << ' ';
            cout << vec[i].word;
        }

        cout << endl;
    }

   return 0;
}

Measured memory_bytes: 1240
//ALDS1_5_D_InversionNumber.cpp

#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;
typedef pair<int,int> Pair;
typedef long long LL;
LL cnt=0;

void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int *L=new int[n1+1];
    int *R=new int[n2+1];
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1]=R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i];
            i=i+1;
        }else {
            A[k]=R[j];
            j=j+1;
            cnt+=n1-i;
        }
        
    }
    delete[] L;
    delete[] R;
}

void mergeSort(int A[],int left,int right){
    if(left+1<right){
        int mid =(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}

int main(){
    int n;
    int A[200100];
    cin >> n;
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    mergeSort(A,0,n);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4440
#include<stdio.h>

void aiko ( int deta[] ) {
	int i;
	for ( i = 0; i < 5; i++ )
		deta[i] = 3;
	return;
}

void saerch ( int deta[] , int result[] , int win ) {
	int i;
	for ( i = 0; i < 5; i++ ) {
		if ( deta[i] == win ) result[i] = 1;
		else result[i] = 2;
	}
	return;
}

int check ( int g , int c , int p ) {
	if ( g && c && p ) return 1;
	else if ( g == 5 || c == 5 || p == 5 ) return 1;
	else return 0;
}

int judge ( int g , int c , int p ) {
	if ( g && c ) return 1;
	if ( c && p ) return 2;
	if ( p && g ) return 3;
}

int main() {
	int i , win , goo , cho , paa , deta[8] , result[8];
	while (1) {
		goo = 0; cho = 0; paa = 0; win = 0;
		scanf("%d",&deta[0]);
		if ( deta[0] == 0 ) break;
		scanf("%d %d %d %d",&deta[1],&deta[2],&deta[3],&deta[4]);
		for ( i = 0; i < 5; i++ ) {
			if ( deta[i] == 1 ) goo++;
			else if ( deta[i] == 2 ) cho++;
			else if ( deta[i] == 3 ) paa++;
		}
		if ( check(goo,cho,paa) ) aiko(result);
		else {
			win = judge(goo,cho,paa);
			saerch(deta,result,win);
		}
		for ( i = 0; i < 5; i++ ) {
			printf("%d\n",result[i]);
			result[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys


def CheckRangeInt(input_str,_min,_max):

    if input_str.isdecimal()==0 or int(input_str)<_min or int(input_str)>_max:
        print("error")
        sys.exit()

    return int(input_str)


def CheckRangeList(input_list,_min,_max):
    for i in range(len(input_list)) :
        if H[i]<_min or H[i]>_max :
            print("error")
            sys.exit()
    return input_list

N=input()

# if N.isdecimal()==0 or int(N)<1 or int(N)>20:                                                                                                                                                             
#     print("error")                                                                                                                                                                                        
#     sys.exit()                                                                                                                                                                                            

# N=int(N)                                                                                                                                                                                                  
N=CheckRangeInt(N,1,20)


H=list(map(int,input().strip().split()))

if len(H)!=N :
    print("error")
    sys.exit()

# for i in range(N) :                                                                                                                                                                                       
#     if H[i]<1 or H[i]>100 :                                                                                                                                                                               
#         print("error")                                                                                                                                                                                    
#         sys.exit()                                                                                                                                                                                        

H=CheckRangeList(H,1,100)

highest=0
can_see=0

for i in range(N):
    if H[i]>=highest :
        can_see=can_see+1
        highest=H[i]

print(can_see)




Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9000000000000000000;
const double PI = acos(-1);

int fib[50];
int main() {
	int n;
	cin >> n;
	fib[0] = 0;
	fib[1] = 1;
	if (n < 2) {
		cout << fib[n] << endl;
		return 0;
	}
	for (int i = 2; i <= n+1; i++) {
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	cout << fib[n+1] << endl;
}

Measured memory_bytes: 3084
#include <iostream>
#define INF 1e9
using namespace std;
int cnt;

void merge(int A[],int L,int M,int R){
  int n1=M-L;
  int n2=R-M;
  int a[500000],b[500000];
  for(int i=0;i<n1;i++)a[i]=A[L+i];
  for(int i=0;i<n2;i++)b[i]=A[M+i];
  a[n1]=INF,b[n2]=INF;
  int i=0,j=0;

  for(int k=L;k<R;k++){
    cnt++;
    if(a[i]<=b[j]) A[k]=a[i++];
    else A[k]=b[j++];
  }
}

void mergeSort(int A[],int L,int R){
  if(L+1<R){
    int M=(L+R)/2;
    mergeSort(A,L,M);
    mergeSort(A,M,R);
    merge(A,L,M,R);
  }
}

int main(){
  int n, a[500000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  mergeSort(a,0,n);
 
  for(int i=0;i<n-1;i++)cout <<a[i]<<" ";
  cout <<a[n-1]<<endl;
  cout <<cnt<<endl;
  return 0;
}

Measured memory_bytes: 5076
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
 
#define PII pair<LL,LL>
#define mem(v, x) memset(v, x, sizeof v)
 
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
 
#define sf(x) scanf("%lf", &x)
#define endl '\n'

#define FOR(i , N) for(int i = 0  ; i < N ; i++)
#define FOR1(i , N) for(int i = 1  ; i <= N ; i++)

template <typename T> T six(T &n){n = 0;bool neg = false;char c = getchar();while( c < '0' || c > '9'){if(c == '-') neg = true;c = getchar();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = getchar();}if(neg) n = ~(n-1);return n;}

using namespace std;
 
typedef long long LL;
 
int SET(int N,int pos){return N=N | (1<<pos);}
int RESET(int N,int pos){return N= N & ~(1<<pos);}
bool CHECK(int N,int pos){return (bool)(N & (1<<pos));}

const int MOD = 1000000007;
#define PLL pair<LL, LL> 
const LL inf = 1e17;
/*
   D er iterative parlam na
   D te First WA Why???
   Probability Expected Value pari na
*/

LL add(LL x, LL y) {
   x %= MOD;
   y %= MOD;
   x += y;
   x %= MOD;
   return x;
}

int N;
int arr[3003];
PLL dp[3003][3003][2];

PLL rec(int st = 0, int en = N - 1, int sign = 1) {
  if(st > en) return {0,0};
  if(st == en) {
    if(sign) return PLL(arr[st], 0);
    return PLL(0, arr[st]);
  }
  PLL &ret = dp[st][en][sign];
  if(ret.fi != -1 && ret.se != -1) return ret;
  LL ans1 = -inf, ans2 = -inf;
  if(sign) {
      PLL p = rec(st + 1 , en, sign ^ 1);
      LL var1 = arr[st] + p.fi;
      if(ans1 < var1) {
        ans1 = var1;
        ans2 = p.se;
      }

      p = rec(st , en - 1, sign ^ 1);
      var1 = arr[en] + p.fi;
      if(ans1 < var1) {
        ans1 = var1;
        ans2 = p.se;
      }
  } else {
      PLL p = rec(st + 1, en, sign ^ 1);
      LL var1 = arr[st] + p.se;
      if(ans2 < var1) {
        ans2 = var1;
        ans1 = p.fi;
      }

      p = rec(st, en - 1, sign ^ 1);
      var1 = arr[en] + p.se;
      if(ans2 < var1) {
        ans2 = var1;
        ans1 = p.fi;
      }
  }
  ret = PLL(ans1, ans2);
  return ret = PLL(ans1, ans2);
}

int main()
{

#ifndef ONLINE_JUDGE // dont use this in toph/codemarshal
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    mem(dp , -1);
    cin >> N;
    FOR(i , N) cin >> arr[i];
    cout << rec(0, N-1).fi - rec(0, N - 1).se << endl;
}  


Measured memory_bytes: 282240