akhauriyash/Code-Regression huggingface dataset:
/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
const ll inf= 1e9;
const ll inf64= 1e18;
const ll MOD= 1e9 +7;



void Solve()
{
	m(ll,ll) mp;
	ll sum=0;
	ll n,x,y,z;
	cin>>n;
	f(i,1,n)
	{
		cin>>x;
		sum += x;
		mp[x]++;
	}
	
	ll Q;
	cin>>Q;
	while(Q--)
	{
		cin>>x>>y;
		sum -= mp[x]*x;
		sum += mp[x]*y;
		mp[y] += mp[x];
		mp[x]=0;
		cout<<sum<<endl;
	}	
} 
 
signed main() 
{
	speed		
	
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	return 0;
} 

Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define read1(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define read4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
  return 0;
}

int main() {

    IO; 

    ll a,b;
    cin>>a>>b;
    ll srt=max(b-a+1,-(ll)1000000);
    ll end=min(b+a-1,(ll)1000000);
    for(ll i=srt;i<=end;i++){
        cout<<i<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    G = [0] * H
    for i in range(H):
        G[i] = readline().strip()
    dxdy4 = ((-1, 0), (0, -1), (0, 1), (1, 0))

    dist = [[-1] * W for _ in range(H)]
    dist[0][0] = 1
    queue = deque([(0, 0)])
    while queue:
        x, y = queue.popleft()
        if x == H - 1 and y == W - 1:
            break
        for dx, dy in dxdy4:
            nx, ny = x + dx, y + dy
            if 0 <= nx < H and 0 <= ny < W and G[nx][ny] == '.' and dist[nx][ny] == -1:
                queue.append((nx, ny))
                dist[nx][ny] = dist[x][y] + 1

    if dist[H - 1][W - 1] == -1:
        print(-1)
    else:
        ans = sum(row.count('.') for row in G) - dist[H - 1][W - 1]
        print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
from operator import itemgetter
from itertools import chain


N = int(input())
inc = []
dec = []
for i in range(N):
    S = input()
    low = 0
    pos = 0

    for s in S:
        if s == '(':
            pos += 1
        else:
            pos -= 1
        low = min(low, pos)
    
    if pos >= 0:
        inc.append((low, pos))
    else:
        dec.append((low, pos))

inc.sort(key=itemgetter(0), reverse=True)
dec.sort(key=lambda x: x[0] - x[1])
height = 0
for i, (low, pos) in enumerate(chain(inc, dec)):
    if height + low < 0:
        ans = 'No'
        break
    height += pos
else:
    ans = 'Yes' if height == 0 else 'No'
print(ans)


Measured memory_bytes: 212212
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define le(x) (int) x.length()
#define rsz resize

using namespace std;
typedef vector <int> vi;
typedef vector <vector <int> > vii;
typedef pair <int, int> pii;
typedef queue <int> qi;
typedef double db;
typedef long long ll;
typedef long double ld;
 
const long double PI=3.141592653589793238462643383279502884;
const long long PRIME1=1e9+787;
 
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll minll(ll a,ll b) {return a<=b?a:b;}
ll maxll(ll a,ll b) {return a>=b?a:b;}

int main () {
    fast;
    int n;
    ll d;
    int ans=0;
    cin>>n>>d;
    for (int i=0; i<n; i++) {
        ll x, y;
        cin>>x>>y;
        if (x*x+y*y<=d*d) {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}
 
 


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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n), c(n - 1);
    rep(i, n) {
        scanf("%d", &a[i]);
    }
    rep(i, n) {
        scanf("%d", &b[i]);
    }
    rep(i, n - 1) {
        scanf("%d", &c[i]);
    }
    int result = 0;
    rep(i, n - 1) {
        if (a[i + 1] - a[i] == 1) {
            result += c[a[i] - 1];
        }
    }
    printf("%d", result + accumulate(b.begin(), b.end(), 0));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	long long x, y;
	std::cin >> x >> y;
	int ans = 1;
	while(x * 2 <= y) x *= 2, ans++;
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
import sys
def angleis(p1, p2):
    return True if p1[0] * p2[1] - p1[1] * p2[0] > 0 else False

Ps = sys.stdin.readlines()
for P in Ps:
    xa, ya, xb, yb, xc, yc, xd, yd = map(float, P.split(','))
    p = [[xb-xa, yb-ya],[xc-xb, yc-yb],[xd-xc, yd-yc],[xa-xd, ya-yd],[xb-xa, yb-ya]]
    a = []
    for i in range(4):
        a.append(angleis(p[i], p[i+1]))
    if a.count(True) == 0 or a.count(True) == 4:
        print('YES')
    else :
        print('NO')

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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	//sort(a.begin(), a.end());
	long long ans = 0;
	int m = 0;
	for(int i=0; i<n; i++) {
		m = max(m, a[i]);
		ans += (m - a[i]);
	}
	printf("%lld", ans);
	return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int position;
    rep(i, N)
    {
        int a;
        cin >> a;
        if (a == 1)
            position = i + 1;
    }
    int ans = 1e8;
    rep(i, K)
    {
        int tmp = 1;

        int tmp1 = ceil((position - i - 1) / (double)(K - 1));
        tmp += max(0, tmp1);

        tmp1 = ceil((N - position - (K - 1 - i)) / (double)(K - 1));
        tmp += max(0, tmp1);

        ans = min(tmp, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;

  rep(i,tx-sx) cout<<'R';
  rep(i,ty-sy) cout<<'U';

  rep(i,tx-sx) cout<<'L';
  rep(i,ty-sy) cout<<'D';

  cout<<'D';
  rep(i,tx-sx+1) cout<<'R';
  rep(i,ty-sy+1) cout<<'U';
  cout<<'L';

  cout<<'U';
  rep(i,tx-sx+1) cout<<'L';
  rep(i,ty-sy+1) cout<<'D';
  cout<<'R';

  cout<<endl;
}

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

using namespace std;


int main()
{
    int n[3];

    cin>> n[0]>>n[1]>>n[2];


    sort(n,n+sizeof(n)/sizeof(n[0]));

    for(int i=0;i<sizeof(n)/sizeof(n[0]);i++)
    {
        cout<<n[i];
        if(i!=sizeof(n)/sizeof(n[0])-1)
            cout << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

bool check(int x, int a[])
{
    while(x > 0) {
        if(a[x % 10]) {
            return false;
        }
        x /= 10;
    }
    return true;
}

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

    int a[10] = {0};
    for(int i = 0; i < k; ++i) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    int ans = n;
    while(true) {
        if(check(ans, a)) {
            break;
        } else {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); 
        long k = sc.nextLong();
        long count = 0;
        int ans = 0;
		long [] in = new long [100000];
        int a;
        long b;
        for(int i=0;i<n;i++){a = sc.nextInt();
                             b = sc.nextLong();
                             in[a-1]+=b;                           
                            }       		
        for(int i=0;i<100000;i++){count+=in[i];
                             if(count>=k){ans=i+1;break;}
                            }                                                      
		System.out.println(ans);
	}
}


Measured memory_bytes: 65952
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.printf("a < b\n");
        if(a > b) System.out.printf("a > b\n");
        if(a == b) System.out.printf("a == b\n");
    }
}


Measured memory_bytes: 26104
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    ll n = stoll(s);
    ll x = 1;
    for (char i : s) {
        x *= 10;
    }
    string t = "0123456789";
    ll ans = INF<ll>, diff = 0;
    do {
        ll u = stoll(t.substr(0, s.size()));
        if(diff < min(x-abs(u-n), abs(u-n))){
            diff = min(x-abs(u-n), abs(u-n));
            ans = u;
        }else if(diff == min(x-abs(u-n), abs(u-n))){
            ans = min(ans, u);
        }
    }while(next_permutation(t.begin(),t.end()));
    string y = to_string(ans);
    while(s.size() > y.size()) y = "0" + y;
    cout << y << "\n";
    return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		while (i < n - 1 && v[i] == v[i + 1]) {
			i++;
		}
		if (i < n - 1 && v[i] < v[i+1]) {
			ans++;
			while (i < n - 1 && v[i] <= v[i + 1]) {
				i++;
			}
		} else {
			ans++;
			while (i < n - 1 && v[i] >= v[i + 1]) {
				i++;
			}
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3736
//
//  main.cpp
//  B - Comparing Strings
//
//  Created by Hashizo on 2020/01/19.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


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

	ll a,b;
	cin >> a >> b;

	string A,B;
	
	REP(i, b) {
		A += to_string(a);
	}

	REP(i, a) {
		B += to_string(b);
	}

	
	if (A <= B) {
		cout << A << endl;
	}
	else {
		cout << B << endl;
	}
	
	
	return 0;
}


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

int main(){
  int iN;
  cin >> iN;
  vector<double> A(iN);
  double Sum=0;
  for(int i=0; i<iN; i++){
    cin >> A.at(i);
    Sum+=A.at(i);
  }
  double N=(double)iN;
  double K=Sum/N;
  double Ans=N+1;
  double now=100000000;
  for(int i=N-1; i>=0; i--){
    if(abs(A.at(i)-K)<=now){
      Ans=i;
      now=abs(A.at(i)-K);
    }
  }
  cout << (int)Ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<vector>

#include<algorithm>



typedef long long lli;

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

#define rep1(i, n) for(int i=1; i < (int)(n); i++)

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

#define fill(x,y) memset(x,y,sizeof(x))

#define debug1(i) cout << i << '\n'

#define debug2(i,j) cout << i << j << '\n'



using namespace std;



int main() {
	lli a[20], b, c, n;
	cin >> n;
	vector<lli> vec(n, 0);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
		int k = 0;
		for (int j = 0; j < i; j++) {
			if (vec[i] >= vec[j])k++;
		}
		if (k == i)ans++;
	}
	cout << ans;
	
}

Measured memory_bytes: 256
//C - たくさんの数式
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int ii,answer=1;ii=exponent;while(ii!=0){answer=answer*base;--ii;}return answer;}//ruijou base^exponent


long long int llketasuu(long long int x){
  ll jjj=0;
  while(x!=0){
    x/=10;
    jjj++;
  }
  return(jjj);
}

int main()
{
  ll s,ans=0;
  scanf("%lld", &s);
  ll keta=llketasuu(s);
  for(ll i=1;i<=keta;i++){
    if(i==1){
      //printf("%lld;%lld,%lld\n", i,s%10,(s%10)*llruijou(2,keta-1));
      ans+=(s%10)*llruijou(2,keta-1);
    }
    else{
      //ll tmp1=((s/llruijou(10,i-1))%10)*llruijou(2,keta-2)*((9*llruijou(5,i-1) - 1)/4);
      //printf("%lld:%lld,%lld\n", i,(s/llruijou(10,i-1))%10,tmp1);
      ans+=((s/llruijou(10,i-1))%10)*llruijou(2,keta-2)*((9*llruijou(5,i-1) - 1)/4);
    }
  }
  //printf("keta:%lld\n",llketasuu(s));
  //printf("keta:%lld\n",keta);
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1724
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N = int(input())

group = []
n = N
if N % 2 == 1:
    group.append([N])
    n -= 1

for i in range(n//2):
    group.append([n - i, i + 1])

#print(group)

edge = []

for i in range(len(group)-1):
    for x in group[i]:
        for y in group[i+1]:
            edge.append([x, y])

if len(group) > 2:
    for x in group[len(group)-1]:
        for y in group[0]:
            edge.append([x, y])

print(len(edge))

for i in edge:
    print("{0} {1}".format(i[0], i[1]))


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

using namespace std;

int n, w, i, j;
long long val[100003];
int main() {
    
    cin >> n >> w;
    
    for(; n > 0; --n){
        cin >> i >> j;
        for(int k = w; k >= i; --k)
            val[k] = max(val[k], val[k - i] + j);
    }
    
    cout << val[w] << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
 int N,M;
 cin>>N>>M;
  int ans=0;
  vector<int>a(N);
  for(int i=0;i<M;i++){
  int K;
    cin>>K;
   for(int j=0;j<K;j++){
   		int s;
        cin>>s;
      	s--;
      a.at(s) |= 1<<i;
	  }
  }
  int P=0;
  for(int i=0;i<M;i++){
    int x;
    cin>>x;
    P |=x<<i;
  }
  for(int s=0;s< (1<<N);s++){
  int t=0;
    for(int i=0;i<N;i++){
    if(s>>i &  1){
    	t ^=a.at(i);
      }
    }
    if(t==P){
    ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

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

    auto a = vector<uint64_t>();

    for (size_t i = 0; i < n; ++i) {
        uint64_t _a;
        cin >> _a;
        a.push_back(_a - 1);
    }

    cout << accumulate(a.begin(), a.end(), uint64_t()) << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
a_minus = [-x for x in a]
import heapq
heapq.heapify(a_minus)
for i in range(m):
    nex_num = heapq.heappop(a_minus)
    nex_num = (-1 * nex_num) // 2 * -1
    heapq.heappush(a_minus, nex_num)
print(-sum(a_minus))

Measured memory_bytes: 14224
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

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

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

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

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
    return 0;
}

Measured memory_bytes: 3576
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
	for (auto x : V)	cout << x << ' ' ;
	cout << '\n';
}
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int n; cin >> n;
	vi v(n);
	rep(i,0,n)	cin >> v[i];
	int ans = 0;
	rep(i,1,n) {
		if (v[i] >= v[i-1])	continue;
		else {
			ans += (v[i-1] - v[i]);
			v[i] = v[i-1];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4780
#include <algorithm>
#include <iostream>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>

using std::set;
using std::multiset;
using std::tuple;
using std::vector;
using std::unordered_map;

int64_t mul(int a, int b)
{
	return static_cast<int64_t>(a) * static_cast<int64_t>(b);
}

int64_t solve(int N, const vector<int> &P)
{
	vector<int> X(N + 1);
	for (int i = 0; i < N; ++i) { X[P[i]] = i; }

	multiset<int> set;
	set.emplace(-1);
	set.emplace(-1);
	set.emplace(N);
	set.emplace(N);

	int64_t ans = 0;
	for (int i = N; i >= 1; --i)
	{
		int L[2], R[2];
		auto it0 = set.upper_bound(X[i]);
		{
			auto it = it0;
			R[0] = *it++;
			R[1] = *it++;
		}
		{
			auto it = it0;
			L[0] = *--it;
			L[1] = *--it;
		}
		int64_t sum = 0;
		sum += mul(R[1] - R[0], X[i] - L[0]);
		sum += mul(R[0] - X[i], L[0] - L[1]);
		ans += mul(sum, i);
		set.emplace(X[i]);
	}
	return ans;
}

int main(int argc, char *argv[])
{
	int N;
	std::cin >> N;
	vector<int> P(N);
	for (int i = 0; i < N; ++i) { std::cin >> P[i]; }
	std::cout << solve(N, P) << std::endl;
	return 0;
}


Measured memory_bytes: 5760
from collections import*
h,*t=open(0)
h,w=map(int,h.split())
f,o=1,0
for i in Counter(''.join(t)).values():
    f+=i//4
    o+=i&1
print('YNeos'[o-h%2>h*w%2or f-h//4<=h//2*(w//2)::2])

Measured memory_bytes: 3316
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var grf = new List<long>[N];
            for (var i = 0; i < N; ++i) grf[i] = new List<long>();
            for(var i=0;i<M;++i)
            {
                var ab = Sarray();
                var a = ab[0] - 1;
                var b = ab[1] - 1;
                grf[a].Add(b);
                grf[b].Add(a);
            }
            var q = new Queue<Tuple<long, long>>();
            q.Enqueue(new Tuple<long, long>(0, 0));
            var dpt = 0L;
            while (q.Count != 0)
            {
                var r = q.Dequeue();
                foreach (var c in grf[r.Item1])
                {
                    if (c == N - 1)
                    {
                        WriteLine("POSSIBLE");
                        return;
                    }
                    if (r.Item2 < 1)
                        q.Enqueue(new Tuple<long, long>(c, r.Item2 + 1));
                }
            }
            WriteLine("IMPOSSIBLE");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 47104
main = interact $ unlines . map (orthogonal . map ((*1000) . read::String->Double) . words) . lines
orthogonal [xa,ya,xb,yb,xc,yc,xd,yd] = if equal' (ab + cd) bd then "YES" else "NO"
 where
  ab = (yb-ya)^2 + (xb-xa)^2
  cd = (yd-yc)^2 + (xd-xc)^2
  bd = ((xd-xc)-(xb-xa))^2 + ((yd-yc)-(yb-ya))^2
  equal' x y = abs (x-y) < 0.000001

Measured memory_bytes: 4432
/**Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n;
    f=1;
    for(i=0;i<n;i++){
        cin>>a;
        if(a%2==0&&((a%3)&&(a%5)))f=0;

    }
    if(f)cout<<"APPROVED\n";
    else cout<<"DENIED\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>d(n),e(n);
  for(int i=0;i<n;++i){
    cin >> d[i] >> e[i];
  }
  bool ans=false;
  int cnt=0;
  for(int i=0;i<n;++i){
    if(d[i]==e[i]) cnt++;
    else cnt=0;
    if(cnt==3){
      ans=true;
      break;
    }
    }
  if(ans==true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
    

Measured memory_bytes: 3580
#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.at(i);
  
  sort(v.begin(), v.end());
  
  double two = 2;
  double ans = (v.at(0) + v.at(1)) / two;
  
  if (N == 2) cout << ans << endl;
  else {
    for (int i = 2; i < N; ++i) ans = (ans + v.at(i)) / two;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int n;
const int N = 500000 + 5;
set<int>adj[26];

int main()
{
    cin >> n;
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++)
    {
        adj[s[i]-'a'].insert(i+1);
    }
    int q;
    cin >> q;
    while (q--)
    {
        int t, l, r;
        cin >> t;
        if (t == 1)
        {
            char c;
            cin >> l >> c;
            if (s[l - 1] != c)
            {
                adj[s[l-1]-'a'].erase(l);
                s[l-1]=c;
                adj[s[l-1]-'a'].insert(l);
            }
        }
        else
        {
            cin >> l >> r;
            long long int ans=0;
            for(int i=0;i<26;i++)
            {
                auto it=adj[i].lower_bound(l);
                if(it!=adj[i].end())
                {
                    if(*it<=r)
                        ans++;
                }
            }
            cout<<ans<<"\n";
        }   
    }
}

Measured memory_bytes: 24196
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

char buff[6003];


int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", buff);
  vector<int> a, b;
  for (int i = 0; i < 2 * n; i++) {
    if (buff[i] == 'a') {
      a.push_back(i);
    }
    else {
      b.push_back(i);
    }
  }
  vector<int> ba;
  for (int i = 0; i < n; i++) {
    if (a[i] > b[i]) {
      ba.push_back(i);
    }
  }
  int bacnt = ba.size();
  a.push_back(INT_MAX); b.push_back(INT_MAX);
  ba.push_back(n);
  vector<string> best(bacnt + 1);
  vector<int> best_end(bacnt + 1); // exclusive
  for (int i = bacnt - 1; i >= 0; i--) {
    string cur;
    int ap = i, bp = i;
    int last_insert = -1;
    do {
      if (a[ba[ap]] < b[ba[bp]]) {
        cur.push_back('a');
        last_insert = a[ba[ap]];
        ap++;
      }
      else {
        cur.push_back('b');
        last_insert = b[ba[bp]];
        bp++;
      }
    } while (ap != bp);
    cur += best[ap];
    if (cur > best[i + 1]) {
      best_end[i] = max(last_insert + 1, best_end[ap]);
      best[i] = cur;
    }
    else {
      best_end[i] = best_end[i + 1];
      best[i] = best[i + 1];
    }
  }
  string ans = best[0];
  int last_ind = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] < best_end[0]) continue;
    if (a[i] > b[i]) continue;
    if (last_ind < a[i]) {
      ans += "ab";
      last_ind = b[i];
    }
  }
  printf("%s\n", ans.c_str());
  return 0;
}


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

using namespace std;

const long long inf = 2100000000;

long long cost[100100];

void solve(){
    int n, v, smc = 0;
    long long tw, w;
    
    cin >> n >> tw;
    
    for(int i = 1;i <= 100010;++i){
        cost[i] = inf;
    }
    
    for(int i = 1;i <= n;++i){
        cin >> w >> v;
        smc += v;
        for(int j = smc;j - v >= 0;--j){
            if(cost[j - v] != inf){
                cost[j] = min(cost[j], cost[j - v] + w);
            }
        }
    }

    int res = 0;
    
    for(int i = 1;i <= smc;++i){
        if(cost[i] <= tw){
            res = i;
        }
    }
    
    cout << res;
}

int main(){
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <functional>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double>p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  vector<vector<double>>dp(n, vector<double>(n / 2 + 1, -1.0));
  function<double(int, int)>solve = [&](int i, int k)->double {
    if (i == n) {
      return 1.0;
    }
    if (dp[i][k] != -1.0) 
      return dp[i][k];
    double heads = solve(i + 1, k) * p[i];
    double tails = 0;
    if (k - 1 >= 0) {
      tails = solve(i + 1, k - 1) * (1.0 - p[i]);
    }
    return dp[i][k] = heads + tails;
  };
  cout<<fixed<<setprecision(9) << solve(0, n / 2) << endl;
  return 0;
}

Measured memory_bytes: 35840
from decimal import *
import math

N = int(input())
input_list = [[int(i) for i in input().split()] for j in range(N)]

T, A = input_list[0][0], input_list[0][1]

for i in range(1, N):
    n = Decimal(max(math.ceil(T/input_list[i][0]), math.ceil(A/input_list[i][1])))
    T = input_list[i][0] * n
    A = input_list[i][1] * n

print(T + A)

Measured memory_bytes: 5204
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
ll a[22];
ll n;
signed main() {
	ll cnt = 0, ans = 0;
	cin >> n;
	rep(i, n)cin >> a[i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (a[j] <= a[i])cnt++;
		}
		if (cnt == i)ans++;
		cnt = 0;
	}
	cout << ans + 1 << endl;
	ggr
}


Measured memory_bytes: 256
'use strict';

function main(arg) {
  const input = arg.trim().split('\n');
  const d = Number(input[0]);
  const diff = 25 - d;
  let ans = 'Christmas';
  if (diff > 0) {
    ans = ans + ' Eve'.repeat(diff);
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29504
n=int(input())
h=list(map(int,input().split()))
dp=[1]*n
for i in range(n-1,-1,-1):
    if i+1<n:
        if h[i]>=h[i+1]:
            dp[i]=1+dp[i+1]
        else:
            dp[i]=1
    else:
        dp[i]=1
print(max(dp)-1)
'''st=[]
ans=1
for i in range(n-1,-1,-1):
    if len(st)==0:
        ans=max(ans,n-1-i+1)
    else:
        while len(st)>0 and st[-1][0]<=h[i]:
            st.pop()
        if len(st)>0:
            ans=max(ans,st[-1][1]-i)
        else:
            ans=max(ans,n-1-i+1)
    st.append([h[i],i])
print(ans-1)'''


Measured memory_bytes: 15020
#include<stdio.h>

#define N 2000001

int B[N], C[N];

void countingSort(int A[], int B[], int k, int n){
  int i, j;

  for(i = 0; i <= k; i++){
    C[i] = 0;
  }
  for(j = 1; j <= n; j++){
    C[A[j]]++;
  }   
  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i - 1];
  } 
  for(j = n; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    printf("%d", B[i]);
    if(i != n) printf(" ");
  }
  printf("\n");

}

int main(){
  int A[N];
  int i, j, n, k = 0;

  //input
  scanf("%d", &n); 
  for(i = 1; i <= n; i++){
    scanf("%d", &A[i]);
    if(k < A[i]) k = A[i];
  }

  //sort and out
  countingSort(A, B, k, n);

  return 0;
}



Measured memory_bytes: 17424
import java.util.Scanner;

class Main {

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

        int a[];
        a = new int[6];
        int Min = 101;
        int total = 0;
        for (int i = 0; i < 6; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = 0; i < 4; i++) { //理科系科目

            if (Min > a[i]) {
                Min = a[i];
            }
            total += a[i];

            if (i == 3) {

                total = total - Min;

            }
        }
        if (a[4] < a[5]) {
            System.out.println(total + a[5]);

        } else {
            System.out.println(total + a[4]);
        }

    }
}



Measured memory_bytes: 26248
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;


int n;
char s[105];
map<char, int> mp1;
map<char, int> mp2;
map<char, int> mp3;
int diff(int x){
	mp1.clear();
	mp2.clear();
	mp3.clear();
	int ans1 = 0, ans2 = 0;
	int ans = 0;
	int i;
	for(i = 0; i < x; i++){
		if(mp1.count(s[i]))
			continue;
		mp1[s[i]]++;
		ans1++;
	}
	for(i = x; i < n; i++){
		if(mp2.count(s[i]))
			continue;
		mp2[s[i]]++;
		ans2++;
	}
	for(i = 0; i < x; i++){
		if(mp1.count(s[i]) == 1 && mp2.count(s[i]) == 1 && mp3.count(s[i]) == 0){
			mp3[s[i]] = 1;
			ans++;
		}
	}
	return ans;
}

int main(){
	scanf("%d",&n);
	scanf("%s",s);
	int maxx = -100;
	for(int i = 1; i < n; i++){
	 	if(maxx < diff(i))
	 		maxx = diff(i);
	}
	printf("%d\n",maxx);
return 0;
}

Measured memory_bytes: 256
/*


O(n^2) approach 
    dp[i] -  max total value so far if the last taken flower has height i
    
    Inshort - we go to all height less than current height 
            and the find the one with the mas value ad use it
            
            We need max(dp[i]) in range [0, h-1]        - h - current height 

    for(int flower = 0; flower < n; flower++) {
        for(int i = 0; i< h[flower]; i++) { 
            int &curr = dp[h[flower]];
            curr = max(curr, dp[i] + val[flower]); 
        }
    } 
*/

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

#define int long long int

void solve() {
    int n;
    cin >> n;
    
    // making a segemnt tree for finding masx(dp[i]) in some range 
    int base = 1;
    while(base <= n) {
        base *= 2;
    }
    // base is the smallest power of 2 that is not smaller than n
    vector<int> tree(2*base);       


    int h[n];
    int val[n];
    for(int i=0; i<n; i++)
        cin >> h[i];
    for(int i=0; i<n; i++)
        cin >> val[i];
    
    int dp[n+1];                                // dp[i] = max total value so far if the last taken flower has height i
    memset(dp, 0, sizeof(dp));

    for(int flower = 0; flower < n; flower++) {

        int x = h[flower] + base;
        int best = 0;
        while(x > 1) {
            if(x%2 == 1) {
                best = max(best, tree[x-1]);
            }
            x /= 2;
        }
        dp[h[flower]] = best + val[flower];

        for(int i= base+h[flower]; i >= 1; i/=2) {
            tree[i] = max(tree[i], dp[h[flower]]);
        }

        // for(int i = 0; i< h[flower]; i++) {
        //     int &curr = dp[h[flower]];
        //     curr = max(curr, dp[i] + val[flower]); 
        // }
    }

    int ans = 0;
    for(int i=0; i<=n; i++) {
        ans = max(ans, dp[i]);
    }

    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}

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

#define pb push_back
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int> 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

int main(){
    fastio
    string s;
    cin>>s;
    int n = s.length();
    int flg=1;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            flg =0;
            break;
        }
    }
    if(flg) cout<<"Good";
    else    cout<<"Bad";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll n; cin >> n;
    vector<ll> a(n); 
    FOR(i, 0, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return;
        }
    }
    ll ans = 1;
    ll inf = 1'000'000'000'000'000'001;
    FOR(i, 0, n) {
        ans = inf / ans < a[i] ? inf : ans * a[i];
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3988
n, m = map(int, input().split())
h = list(map(int, input().split()))

ab = [list(map(lambda x: x -1, map(int, input().split()))) for _ in range(m)]

# 一つづつ展望台を見る必要はなく、道を見て条件に合わないものを除けば良い
ans_list = [True] * n
for i in range(m):
    if h[ab[i][0]] >= h[ab[i][1]]:
        ans_list[ab[i][1]] = False
    if h[ab[i][0]] <= h[ab[i][1]]:
        ans_list[ab[i][0]] = False
print(sum(ans_list))

Measured memory_bytes: 31996
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> n = new ArrayList<Integer>();
        ArrayList<Integer> x = new ArrayList<Integer>();
        int tempn, tempx;
        int count;

        while (true) {
            tempn = sc.nextInt();
            tempx = sc.nextInt();

            if (tempn == 0 && tempx == 0)
                break;

            n.add(tempn);
            x.add(tempx);
        }

        for (int m = 0; m < n.size(); m++) {
            count = 0;
            for(int i = 1; i <= n.get(m); i++){
                for(int j = i + 1; j <= n.get(m); j++){
                    for(int k = j + 1; k <= n.get(m); k++){
                        if(i + j + k == x.get(m)) count++;
                    }
                }
            }
            System.out.println(count);
        }

        sc.close();
    }
}


Measured memory_bytes: 27408
module global_variables
end module global_variables
program main
  use global_variables
  implicit none
  integer a,b,c,x,res
  integer i,j,k
  read *, a,b,c,x
  res = 0
  do i=a,0,-1
    do j=b,0,-1
      do k=c,0,-1
        if (i*500 + j*100 + k*50 == x) then
          res = res + 1
        endif
      enddo
    enddo
  enddo
  print '(i0)', res
end program main


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<ll> q;
  REP(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }

  REP(i, m) {
    ll a = q.top();
    q.pop();
    a /= 2;
    q.push(a);
  }

  ll ans = 0;
  REP(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}


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

#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod	%1000000007
#define FOR(I,N) for(I=0;I<N;++I)

int main()
{
	ll n,k,j,i,f;
	cin>>n>>k;
	ll a[n];
	FOR(i,n)
		cin>>a[i];
	bool dp[k+1];
	for(i=0;i<a[0];++i)
		dp[i]=0;
	while(i<=k)
	{
		f=0;
		for(j=0;j<n && a[j]<=i; ++j)
		{
			if(dp[i-a[j]] == 0)
			{
				dp[i]=1;
				f=1;
				break;
			}
		}
		if(f==0)
			dp[i]=0;
		++i;
	}
	if(dp[k])
		cout<<"First";
	else
		cout<<"Second";	
}

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

using namespace std;

long long mem[100005][2];

int a[105];
int b[105];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&a[i],&b[i]);
    }
    for(i=0;i<=k;i++)
    {
        mem[i][0] = -1e9;
        mem[i][1] = -1e9;
    }
    mem[0][0] = 0;
    mem[0][1] = 0;
    bool flag = 0;
    for(i=0;i<n;i++)
    {
        flag = !flag;
        int j;
        for(j=0;j<=k;j++)
        {
            if(j-a[i]>=0)mem[j][flag] = max(mem[j][!flag],mem[j-a[i]][!flag] + b[i]);
            else mem[j][flag] = mem[j][!flag];
        }
    }
    long long ans = 0;
    for(i=0;i<=k;i++)
    {
        ans = max(mem[i][flag],ans);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int a[200000];

int main() {
	int N, x;
	cin >> N >> x;
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	ll ans = 0;

	if (a[0] + a[1] > x) {
		if (a[0] > x) {
			int d = a[0] + a[1] - x;
			ans += a[1];
			a[1] = 0;
			ans += a[0] - x;
			a[0] = x;
		}
		else {
			int d = a[0] + a[1] - x;
			ans += d;
			a[1] -= d;
		}
	}

	for (int i = 1; i < N - 1; i++) {
		if (a[i] + a[i + 1] > x) {
			int d = a[i] + a[i + 1] - x;
			ans += d;
			a[i + 1] -= d;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位


vector<int> stable, ntable,table;
bool visited[1000000];
int D[32][32];
int grid[502][502];
int allData[32][3];
signed main() {
	int N, C;
	cin >> N >> C;
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			int inp;
			cin >> inp;
			D[i][j] = inp;
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			int inp;
			cin >> inp;
			grid[i][j] = inp;
		}
	}

	//allData[i][j]は、あまりjのところをcoloriに統一したときのいわかん
	for (int color = 1; color <= C; color++) {
		int ds[3] = {0,0,0};
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				ds[(i + j) % 3] += D[grid[i][j]][color];
			}
		}
		for (int k = 0; k < 3; k++) {
			allData[color][k] = ds[k];
		}
	}


	int ans = LL_HALFMAX;
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			for (int k = 1; k <= C; k++) {
				if (i == j || j == k || k == i) continue;
				int tans = allData[i][0] + allData[j][1] + allData[k][2];
				if (tans < ans) ans = tans;
			}
		}
	}

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 2176