akhauriyash/Code-Regression huggingface dataset:
#define taskname "MST"
#include<bits/stdc++.h>
#define ll  long long
#define ld  long double
#define ull unsigned long long
#define fi  first
#define se  second
using namespace std;
typedef pair<ll,ll> LL;
const ll base   = 31;
const ll mod    = 123456789;
const ll limit  = 1e6 +  69;
const ll inf    = round(1e17) + 69;
int n;


void Input ()
{
   cin>>n;
}


void Sol()
{
   cout<<ceil(1.0*n/1000)*1000 - n;
}

int main()
{
   //if (fopen(taskname".INP", "r"))
    //{
      //  freopen(taskname".INP","r",stdin);
      //  freopen(taskname".OUT","w",stdout);
    //}
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    Input();
    Sol();
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int A, B, C;

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

    cin >> A >> B >> C;

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

    return 0;
}


Measured memory_bytes: 764
def mod_inverse(n, mod=10**9+7):
    return pow(n, mod-2, mod)


def combination(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * mod_inverse(denom, mod)) % mod


mod = 10**9+7
n, k = map(int, input().split())

fact = [1] * (n+1)
fact_inv = [1] * (n+1)
for i in range(1, n+1):
    fact[i] = i * fact[i-1] % mod
    fact_inv[i] = mod_inverse(fact[i])

ans = combination(2*n-1, n)
for i in range(k+1, n):
    ans -= (fact[n] * fact_inv[i] * fact_inv[n-i]) * (fact[n-1] * fact_inv[i] * fact_inv[n-1-i])
    # ans -= combination(n, i) * combination(n-1, i)
    ans %= mod
print(ans)


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
vector<vector<pi > > F;
vector<vector<pi > > B;
struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
 
    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }
 
    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return 0;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;
 
        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }
 
        return r;
 
    }
 
    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }
 
};

int main(){

    ll N, M, K; cin >> N >> M >> K;
    //初期化
    UnionFind tomo(N);
    F.assign(N, vector<pi >());
    B.assign(N, vector<pi >());

    //友達関係
    for(ll i = 0; i < M; i++){
        ll u, v;
        ll w = 0;
        cin >> u >> v;
        u--;
        v--;
        //双方向に貼りましょうね
        F[u].push_back(make_pair(v, w));
        F[v].push_back(make_pair(u, w));
        tomo.unite(u, v);
    }
    //ブロック関係
    for(ll i = 0; i < K; i++){
        ll u, v;
        ll w = 0;
        cin >> u >> v;
        u--;
        v--;
        //双方向に貼りましょうね
        B[u].push_back(make_pair(v, w));
        B[v].push_back(make_pair(u, w));
        // block.unite(u, v);
    }

    //ブロック関係でもなく，友人関係でもない人は？
    //連結成分のサイズ-自分と直接つながっている人の数(隣接リストのサイズ)

    for(ll i = 0; i < N; i++){
        ll cn = 0;
        for(ll j = 0; j < B[i].size(); j++){
            if(tomo.same(i, B[i][j].first) == true) cn++;
        }
        cout << tomo.FindSize(i) - F[i].size() - 1 - cn << endl;
    }


}

Measured memory_bytes: 18816
#include <stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	while(1){
		if((n%11==0)||(n%7==0)||(n%4==0)){
			printf("Yes\n");
			break;
		}
		n -= 7;
		if(n<4){
			printf("No\n");
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 128
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;

    if (N==0) {
        cout << "0" << endl;
        return 0;
    }

    string ans = "";

    int n = N;
    int q, r;
    while(abs(n)>0) {
        q = n / (-2);
        r = n % (-2);

        if (r == -1) {
            q++;
            r += 2;
        }

        ans = to_string(r) + ans;
        n = q;        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n:usize,
       mut a:[u32;n]
    }
    let mut _cnt = 0;
    let mut is_break = false;
    loop {
        for i in 0..n {
            if a[i] % 2 == 0 {
                a[i] = a[i] / 2;
            } else {
                is_break = true;
            }
        }
        if is_break {
            break;
        }
        _cnt += 1;
    }
    println!("{}", _cnt);
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		long total = 0;
		for (long i = 0; i < h; i++) {
		    for (long j = 0; j < w; j++) {
		        long x = sc.nextInt();
		        total += x * (i + 1) * (h - i) * (j + 1) * (w - j);
		    }
		}
	    System.out.println(total);
	}
}



Measured memory_bytes: 101772
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  for(int i=s.size()-t.size();i>=0;i--){
    int cnt=0;
    for(int j=0;j<t.size();j++){
      if(s[i+j]==t[j]||s[i+j]=='?'){
        cnt++;
      }
    }
    if(cnt==t.size()){
      for(int j=0;j<s.size();j++){
        if(j==i){
          cout << t;
          j+=t.size()-1;
        }else{
          if(s[j]=='?'){
            cout << 'a';
          }else{
            cout << s[j];
          }
        }
      }
      cout << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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

int main()
{

    int N,K;
    cin >> N >> K;


    int ans=-1;
    int max_b = N-2 + (N-3)*(N-2)/2;

    if(K>max_b){
    	cout << ans << endl;
    	return 0;
    }

    if(N==3){
    	if(K==0){
    		cout << 3 << endl;
    		cout << 1 << " " << 2 << endl;
    		cout << 2 << " " << 3 << endl;
    		cout << 1 << " " << 3 << endl;
    		return 0;

    	}
    }

    int M;
    M = N-1 + max_b - K;

    vector<P> output;
    output.push_back(P(1,2));
    FOR(i,2,N){
    	output.push_back(P(2,i+1));
    }

    int count = 0;
    int tmp_s = 3;
    int tmp_i = 4;

    bool not_f = false;
    while(count!=max_b-K){
    	output.push_back(P(tmp_s,tmp_i));
    	tmp_i ++;
    	count ++;
    	if(tmp_i>N){
    		tmp_s ++;
    		tmp_i = tmp_s+1;
    	}
    	if(tmp_s>=N){
    		not_f = true;
    		break;
    	}
    }
    if(not_f){
        int tmp_s = 1;
        int tmp_i = 3;
        while(count!=max_b-K){
        	output.push_back(P(tmp_s,tmp_i));
        	tmp_i ++;
        	count ++;
        	//if(tmp_i>=N) break;
        }
    }

    cout << M << endl;
    for(auto i:output){
    	cout << i.first << " " << i.second << endl;
    }

}


Measured memory_bytes: 384
def main():
  l, r = map(int, input().split(' '))
  if r - l >= 2019:
    print(0)
  else:
    ans = l * r
    i = l
    while i < r:
      j = i + 1
      while j <= r:
        ij = i * j
        if mod(ij) < ans:
          ans = mod(ij)
        j += 1
      i += 1
    print(ans)


def mod(n):
  if n < 2019:
    return n
  else:
    return(n % 2019)


if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string changes(ll n){
	stringstream ss;
	string res;
	ss << n;
	ss >> res;
	return res;
}

ll changei(string s){
	stringstream ss;
	ll res;
	ss << s;
	ss >> res;
	return res;
}

ll n;
string s;
ll ans = 0;

int main(){
	cin >> s;
	bool f = 0;
	REP(i, s.size()){
		if (s[i] == 'C')f = 1;
		if (f){
			if (s[i] == 'F')ans = 1;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>

int main(){
    
    size_t n;
    int l;
    std::vector<int> p;

    std::cin >> n >> l;

    for(size_t i = 1; i <= n; i++){
        p.emplace_back(l + i - 1);
    }

    std::sort(p.begin(), p.end(), [](int x, int y){ return std::abs(x) < std::abs(y); });

    std::cout << std::accumulate(p.begin() + 1, p.end(), 0) << std::endl;
    
    return 0;
}


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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
    int n,k;cin>>n>>k;
    bool hash[n+1];
    mset(hash,0);
    while(k--)
    {
    	int d;cin>>d;
    	frepi(1,d,1)
    	{
    		int x;cin>>x;
    		hash[x]=true;
    	}
    }
    int ans = 0;
    frepi(1,n,1)
    {
    	if(hash[i]==false)ans++;
    }
    cout<<ans;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

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

def main():
    n, m = map(int, input().split())
    A = []
    B = [''] * m
    for i in range(m):
        p, y = map(int, input().split())
        A.append([p,y,i])
    A.sort()
    count = 0
    i, x = 1, 1
    for a in A:
        if a[0] == i:
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        else:
            i, x = a[0], 1
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        x += 1
    print('\n'.join(B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 33856
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
set<ll> s;
rep(i,0,n-1)
{
	ll x;
	cin>>x;
	s.insert(x);
}
if(s.size()==n)ol("YES");
else ol("NO");
return 0;
}



Measured memory_bytes: 9600
def f(): return map(int,raw_input().split())
n,q=f()
a0,v0=0,0
A=[0]*(n+1)
for _ in range(q):
  a,v=f()
  A[a]+=v
  if a==a0 and A[a]<v0:
    v0=max(A)
    a0=A.index(v0)
  elif A[a]>v0:
    v0=A[a]
    a0=a
  elif A[a]==v0 and a<a0: a0=a
  print a0,v0

Measured memory_bytes: 15152
#include<cstdio>
using namespace std;
int main(){
  int n,a[100000],ans=1,flag=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=1;i<n;i++){
    if(flag==1&&a[i]>a[i-1]){
      ans++;
      flag=0;
    }
    else if(flag==2&&a[i]<a[i-1]){
      ans++;
      flag=0;
    }
    else if(flag==0&&a[i]>a[i-1]){
      flag=2;
    }
    else if(flag==0&&a[i]<a[i-1]){
      flag=1;
    }
  }
  printf("%d\n",ans);
}
      

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    int k = N%10;
    if( k == 3 ) printf ("bon\n");
    else if( k == 0 || k == 1 || k == 6 || k == 8 ) printf ("pon\n");
    else printf ("hon\n");

    return 0;
}



Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
  int i = 1;
  int N;
  int answer = 0;
  int result = 0;
  cin >> N;
  while(i <= N){
    int count = 0;
    if(i % 2 != 0){
      result = i;
      for(int j = 1; j <= result; j++){
        if(result % j == 0){
          count++;
        }
      }
      if(count == 8) answer++;
    }
    i++;
  }
  cout << answer << 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();
    int min = 0;
    int max = 0;
    int[] X = new int[N];

    for (int i = 0; i < N; i++) {
      X[i] =sc.nextInt();
      if(min > X[i] || min ==0){
        min = X[i];
      }
      if(  X[i] > max){
        max = X[i];
      }
    }

    int sum = 0;
    int  sum_min = 0;
    int tmp = 0;
    for (int j = min; j < max; j++) {
       for(int k = 0; k < N; k++){
         tmp = Math.abs(j -X[k]);
         sum = tmp * tmp + sum;
       }
       if(sum_min == 0 || sum <=sum_min){
        sum_min = sum;
       }
       sum = 0;
    }    
    System.out.println(sum_min);
  }
}



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

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep2(i,a,b) for(ll i=a; i<=b; i++)
#define drep2(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back

int main ()
{
  long long N;
  cin >> N;
  string S;
  cin >> S;

  long long minj = 0;
  long long minm = 0;

  long long right[N];
  long long w[N];
  rep(i,N) {
    right[i] = 0;
    w[i] = 0;
  }
  long long maxe = 0;

  rep(i,N) {
    if (i == 0) {
      if (S[i] == 'E') {
        right[i] = 1;
        w[i] = 0;
        maxe++;
      } else {
        right[i] = 0;
        w[i] = 1;
      }
        continue;
    }
      
    if (S[i] == 'E') {
      right[i] = right[i-1]+1;
      maxe++;
      w[i] = w[i-1];
    } else {
      right[i] = right[i-1];
      w[i] = w[i-1] + 1;
    }

  }


//  cout << S << endl;
//  cout << "maxe: " << maxe << endl;
  long long mmin = N;

  long long cnt;

  rep(i,N) {

//    cout << right[i] << ", " 
//      << "nokorie: " << maxe - right[i] << ", " 
//      << "now w: " << w[i] << ", " 
//      << "nokoriw: " << N - maxe - w[i] << ","
//      << "total = " << (maxe-right[i]) + ((S[i] == 'W')? (w[i]-1) : w[i]) 
//      << endl;
    cnt = (maxe-right[i]) + ((S[i] == 'W')? (w[i]-1) : w[i]) ;
    if (mmin > cnt) mmin = cnt;
  }
  cout << mmin << endl;
  
}

Measured memory_bytes: 5380
#include <stdio.h>

int main(void)
{
	int N=0,K=0,del=0;
	
	scanf("%i %i",&N,&K);
	
	if(K==1){
		printf("%i",0);
	}
	else{
	
	del=N-K;
	printf("%i",del);
	}
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int n,a,i;
	while (~fscanf(stdin, "%d", &n), n) {
		i = 9;
		while (i--)	fscanf(stdin, "%d", &a), n -= a;
		P(d, n);
	}
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int n;
	
	while(cin>>n)
	{
		cout<<((1+(n-1))*(n-1)/2)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	bool ans;
	foreach (i; 0..100)
	{
		auto remain = N - 4 * i;
		if (remain < 0) continue;
		if (remain % 7 == 0)
			ans = true;
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
int main() {
  ll N;
  cin >> N;
  
  vector<ll> V(1e5+1);
  for (int i = 0; i < N; i++) {
  	ll bi;
    cin >> bi;
    V[bi] += 1;
  }
  
  ll cur = 0;
  for (int i = 1; i <= 1e5; i++) {
    cur += V[i];
    V[i] = cur;
  }
  
  if (N % 2 == 1) {
  	cout << 0 << endl;
    return 0;
  }
 
  ll cnt = 0;
  for (int i = 1; i <= 1e5; i++) {
  	if (V[i] == (N / 2)) {
    	cnt += 1;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4020
N=int(input())
W=list(map(int,input().split()))

Wf=[W[0]]

for i in range(1,N):
    Wf.append(Wf[i-1]+W[i])

W.reverse()
Wb=[W[0]]

for i in range(1,N):
    Wb.append(Wb[i-1]+W[i])

d=10000

for i in range(N-1):
    if abs(Wf[i]-Wb[N-2-i])<d:
        d=abs(Wf[i]-Wb[N-2-i])

print(d)


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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int n;
  cin >> n;
  if(n%10==3)cout << "bon "<<endl;
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)cout << "pon" <<endl;
  else cout <<"hon"<<endl;
  
  
  
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1<<30;

int main() {
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  int ans = inf;
  for(int i = 0; i <= 1e5; i++) {
    int sum = 2*C*i + max(0, X-i)*A + max(0, Y-i)*B;
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> t(h, vector<char>(w));
    for (auto &v: t) for (auto &e: v) cin >> e;

    vector<int> cnth(h, 0), cntw(w, 0);
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
        if (t[i][j] == '#') {
            cnth[i]++;
            cntw[j]++;
        }
    }

    for (int i = 0; i < h; ++i) {
        if (cnth[i] == 0) continue;
        for (int j = 0; j < w; ++j) {
            if (cntw[j] == 0) continue;
            cout << t[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

int main() {
	string s;
  cin>>s;
	int res = 0,total =0;
	for(int i =0;i<3;i++){
		if(s[i] == 'S'){
			res = max(res,total);
			total = 0;
		}
		else total++;
	}
	res = max(res,total);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3580
/*********************************************************************
* AUTHOR : ANSHU KUMAR                                               *
* ABOUT :  IT DOESN'T MATTER HOW SLOW I GO, AS LONG AS I NEVER STOP  *
* INSTITUTION : IEM KOLKATA                                          *
**********************************************************************/

//try to think at least 30min(with full concentration).

#include <bits/stdc++.h>

using namespace std;

#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define MOD             1000000007
#define INF             1e18
#define PI              3.1415926535897932384626433832795
#define sp(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl            '\n'
#define da(arr,type,n)  type *arr=new type[n];


/********** Euclidean Algorithm for GCD **********/
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



/********** Fast Power Exponentiation ***********/
int power(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res % MOD * a % MOD) % MOD;
		a = (a % MOD * a % MOD) % MOD;
		b >>= 1;
	}
	return res;
}



/********** FAST I/O ************/
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}



/********** PROGRAM START ***********/
bool check(int ans, int A[])
{
	while (ans > 0)
	{

		if (A[ans % 10])
		{
			return false;
		}
		ans /= 10;
	}
	return true;
}
int32_t main()
{
	fastIO();
	int n, k;
	cin >> n >> k;
	int D[10] = {0};
	for (int i = 0; i < k; i++)
	{
		int x;
		cin >> x;
		D[x]++;
	}
	int res = n;
	while (true)
	{
		if (check(res, D))
		{
			break;
		}
		else
		{
			res += 1;
		}
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main(){
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int time = (H2-(H1+1))*60 + (60 - M1) + M2;
	cout << time-K;

}

Measured memory_bytes: 3588
N = int(input())
a = list(map(int, input().split()))
ans = []
s = 0
for i in range(N):
    s = s ^ a[i]

for i in range(N):
    tmp = s ^ a[i]
    ans.append(str(tmp))
    
ans = ' '.join(ans)    
print(ans)

Measured memory_bytes: 33636
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int a,b,c,d[100005] = {},n,m;
string s,t;


int main(){
    
    cin >> a;

    P(3*a * a);
    
    return  0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100

int main(){
  int i,j,k,l,n,p[N+1],m[N+1][N+1],P,b;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&p[i],&b);
  }
  p[n]=b;

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=10000000000;
      for(k=i;k<=j-1;k++){
        P=(m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
        if(m[i][j]>P) m[i][j]=P;
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2112
/*input
6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6
*/
#include<bits/stdc++.h>
#include<algorithm>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define is insert
#define rep1(i,a,b) for(long long i=a;i<=b;i++)
#define mp make_pair
#define mh make_heap
#define F first
#define S second
//#define fin cin
//#define fout cout
#define file ifstream fin("input.txt");ofstream fout("output.txt");
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr(n) for(long long i=0;i<n;i++)
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
#define lb lower_bound
#define ub uper_bound
#define bs lower_bound
//#define db(i) cout<<i<<endl;
typedef pair<ll,ll> pairs;
typedef vector<ll> vi;
typedef vector<pairs> vpair;

vi v[500000];
bool vis[500000];
void solve()
{   
    ll n,m,a,b;
    cin>>n>>m;
    fr(m)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    ll ans[n+1]={0};
    ans[1]=1;

    queue<int>q;
    q.push(1);vis[1]=1;
    while(!q.empty())
    {
        ll a=q.front();
        q.pop();
        //if(vis[a])continue;
        //vis[a]=1;
        for(int i=0;i<v[a].size();i++)
        {
            ll ch=v[a][i];
            if(!vis[ch])
            {
                vis[ch]=1;
                ans[ch]=a;
                q.push(ch);
            }
        }
    }
    for(int j=1;j<=n;j++)
    {
        if(ans[j]==0)
        {
            cout<<"No"<<endl;
            return ;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
}
int main()
{
    fast;
    solve();
}

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

int main() {
  string S, T;
  cin >> S >> T;


  if (T.substr(0, S.size()) == S && S.size() == T.size() - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
loop do
  n = gets.to_i
  break if n==0
  max = max_n = -100000
  r = 0
  n.times do
    m = gets.to_i
    max_n = [max_n, m].max
    r = [r+m, 0].max
    max = [max, r].max
  end
  puts max_n > 0 ? max : max_n
end

Measured memory_bytes: 6092
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

ABC = gets_i_list.sort

appeared = []
count = 0
c_abc = ABC
while true
  if appeared.include?(c_abc)
    puts -1
    exit
  end
  c_abc.each do |e|
    if e.odd?
      puts count
      exit
    end
  end
  count += 1
  appeared.push(c_abc)
  c_abc = [
    c_abc[0]/2 + c_abc[1]/2,
    c_abc[1]/2 + c_abc[2]/2,
    c_abc[0]/2 + c_abc[2]/2,
  ].sort
end


Measured memory_bytes: 2172
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : String = get_one();
    let si : Vec<char> = s.chars().collect();
    let mut ans = 0;
    for i in 1..(s.len() / 2) {
        let mut is_even = true;
        for j in 0..i {
            if si[j] != si[i+j] {
                is_even = false;
                break;
            }
        }
        if is_even {
            ans = i;
        }
    }
    println!("{}", ans*2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define for(i,n) for(i=0;i<n;i++)
#define ll long long
///vector<int>vec;
///sort(s.begin(),s.endl());
///sort(ara,ara+n);
int main()
{
     int i,n,t,p,j=0,a,b,c;
     string s,m;
     cin>>a>>b>>c;
     if(a==b && b==c){
        cout<<"No"<<endl;
     }
     else if(a!=b && b!=c && c!=a){
        cout<<"No"<<endl;
     }
     else{
        cout<<"Yes"<<endl;
     }

     return EXIT_SUCCESS;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int r, d, x;
    
    scanf("%d%d%d", &r, &d, &x);
    
    rep(i, 10){
        x=r*x-d;
        printf("%d\n", x);
    }
    
    return 0;
}


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

using namespace std;

const long long INF = 1e18;

int n,i,j,a[300005];
long long opt[300005];

priority_queue <int, vector<int>, greater<int> > cur;
priority_queue <int> cur1;

int main(){
	scanf("%d", &n);
	
	for(i = 0; i < 3 * n; i++)
	scanf("%d", &a[i]);
	
	long long sum = 0;
	long long sum1 = 0;
	long long kmx = 0;
	
	for(i = 3 * n - 1; i >= 0; i--){
		cur1.push(a[i]);
		sum1 += a[i];
		if(3 * n - i > n){
			kmx += cur1.top();
			cur1.pop();
		}
		opt[i] = sum1 - kmx;
	}
	
	long long kmn = 0;
	long long res = -INF;
	
	for(i = 0; i < 2 * n; i++){
		sum += a[i];
		cur.push(a[i]);
		
		if(i + 1 > n){
			kmn += cur.top();
			cur.pop();
		}
		
		if(i + 1 >= n)
		res = max(res, (sum - kmn) - opt[i + 1]);
	}
	
	printf("%lld\n", res);
}


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

using namespace std;

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

  if (s[0] == s[1] && s[1] == s[2]) {
    cout << "Yes\n";
  } else if (s[1] == s[2] && s[2] == s[3]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}

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

int main()
{
  int a, b, x,y;
  cin >> a >> b;
  x = a+b;
  y = x/2;
  if(x%2 == 0)
  cout << y << endl;
  else
  cout << y + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,k;
    cin>>n>>k;
    vector<char> d(k);
    rep(i,k) cin>>d[i];

    while(1){
        string x=to_string(n);
        bool ok=true;
        rep(i,x.size()){
            rep(j,k){
                if(x[i]==d[j]){
                    ok=false;
                    break;
                }
            }
        }
        if(ok){
            cout<<n<<endl;
            return 0;
        }

        n++;
    }

} 


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, K;
    cin >> N >> K;
    int P[N];
    rep(i, N) cin >> P[i];
    int cnt = 0;
    for(int i = 0; i < N;){
        int j = 1;
        while(i+j < N && P[i+j-1] < P[i+j]) j++;
        if(j >= K) cnt++;
        i += j;
    }
    set<int> s;
    set<int>::iterator it;
    rep(i, K) s.insert(P[i]);
    int ans = 1;
    rep2(i, K, N-1){
        s.erase(P[i-K]);
        it = s.end(), it--;
        int m = *s.begin(), M = *it;
        if(P[i-K] > m || M > P[i]) ans++;
        s.insert(P[i]);
    }
    if(cnt > 0) ans -= cnt-1;
    cout << ans << endl;
}

Measured memory_bytes: 10368
n = int(input())
b_list = list(map(int, input().split(' ')))
b_list.append(b_list[-1])

pre_b = 10**5+1  # Bのとりうる最大値+1
a_list = []
for i in range(len(b_list)):
  a_list.append(min(pre_b, b_list[i]))
  pre_b = b_list[i]
print(sum(a_list))

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define LL  long long 
#define Pi 3.14159265358979;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	LL int a[100000];
	int d = 0, i = 0, j = 0, run = 0, flag = 0;
	LL int ans = 1;

	cin >> n;

	rep(i, n) {
		cin >> a[i];
		if (a[i] == 0)flag = 1;
	}

	rep(i, n) {
		if (a[i] <= 1000000000000000000/ans) {
			ans = ans * a[i];
		}
		else {
			ans = -1;
			break;
		}
	}
	if (flag >= 1) {
		ans = 0;
	}
	cout << ans << "\n";

}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
   fastio
   int n;
   cin>>n;
   int arr[n];
   rep(i,n)cin>>arr[i];
   int ans=0;
   vector<int>v;
   for(int i=1;i<n-1;i++)
   {
     v.clear();
     v.pb(arr[i]);
     v.pb(arr[i-1]);
     v.pb(arr[i+1]);
     sort(v.begin(),v.end());
     if(v[1]==arr[i])ans++;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
import sys
from numpy import*
def main(n,k,p,c):
    m=-10**12
    for i in range(n):
        s=i
        t=1
        x=c[s]
        while p[s]-1!=i:
            s=p[s]-1
            t+=1
            x+=c[s]
        if x>0:
            a=(k//t-1)*x
            if a>m:m=a
            s=i
            for _ in range(k%t+t):
                s=p[s]-1
                a+=c[s]
                if a>m:m=a
        else:
            a=0
            s=i
            for _ in range(min(k,t)):
                s=p[s]-1
                a+=c[s]
                if a>m:m=a
    return m
if sys.argv[-1]=='ONLINE_JUDGE':
  from numba.pycc import CC
  cc=CC('my_module')
  cc.export('main','i8(i8,i8,i8[:],i8[:])')(main)
  cc.compile()
  exit()
from my_module import main
(n,k),p,c=[int_(t.split())for t in open(0)]
print(main(n,k,p,c))

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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()

const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

void showvec(vector<int> v)
{
    rep(i, v.size() - 1)
    {
        cout << v[i] << wsp;
    }
    cout << v[v.size() - 1] << rt;
}

class Unionfind
{
    vector<int> p;
    vector<int> q;

public:
    int find(int x);
    void unite(int x, int y);
    Unionfind(int n);
    vector<int> outputfriends();
};

Unionfind::Unionfind(int n)
{
    for (int i = 0; i < n; i++)
    {
        p.push_back(i);
    }
    q.resize(n);
    fill(q.begin(), q.end(), 1);
}
int Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void Unionfind::unite(int x, int y)
{
    x = Unionfind::find(x);
    y = Unionfind::find(y);
    if (x != y)
    {
        p[x] = y;
        q[x] += q[y];
        q[y] = q[x];
    }
}

vector<int> Unionfind::outputfriends()
{
    rep(i, q.size())
    {
        int j = Unionfind::find(i);
        q[i] = q[j];
    }
    rep(i, q.size()) q[i]--;
    return q;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, x;
    vector<vector<int>> bingo(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> bingo[i][j];
    cin >> n;
    rep(i, n)
    {
        cin >> x;
        rep(i, 3) rep(j, 3)
        {

            if (x == bingo[i][j])
                bingo[i][j] = -1;
        }
    }

    bool ans = false;
    rep(i, 3)
    {
        if (bingo[i][0] == bingo[i][1] && bingo[i][1] == bingo[i][2])
            ans = true;
        if (bingo[0][i] == bingo[1][i] && bingo[1][i] == bingo[2][i])
            ans = true;
    }
    if (bingo[0][0] == bingo[1][1] && bingo[1][1] == bingo[2][2])
        ans = true;
    if (bingo[0][2] == bingo[1][1] && bingo[1][1] == bingo[2][0])
        ans = true;

    cout << (ans ? "Yes" : "No") << rt;
    return 0;
}


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

using namespace std;

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

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 200000 + 5;
const int mod = 998244353;

int n;
int x[maxn], y[maxn];
int vx[maxn], vy[maxn];
int id[maxn], f[maxn];

int c[maxn];

void update(int i, int x) {
  for (; i <= n; i += i & -i) c[i] += x;
}

int query(int i) {
  int ret = 0;
  for (; i; i -= i & -i) ret += c[i];
  return ret;
}

int pow_mod(int a, int b) {
  int ret = 1;
  for (; b; a = (LL)a * a % mod, b >>= 1)
    if (b & 1) ret = (LL)ret * a % mod;
  return ret;
}

int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d%d", &x[i], &y[i]);
    vx[i] = x[i], vy[i] = y[i];
  }
  sort(vx, vx + n);
  sort(vy, vy + n);
  rep(i, n) {
    x[i] = lower_bound(vx, vx + n, x[i]) - vx + 1;
    y[i] = lower_bound(vy, vy + n, y[i]) - vy + 1;
  }
  rep(i, n) id[i] = i;
  sort(id, id + n, [](int i, int j) { return x[i] < x[j]; });
  rep(j, n) {
    int i = id[j];
    f[i] = query(y[i]);
    update(y[i], 1);
  }
  int tot = (pow_mod(2, n) - 1 + mod) % mod, ret = 0;
  rep(i, n) {
    int now = tot;
    now = (now - (pow_mod(2, x[i] - 1) - 1) + mod) % mod;
    now = (now - (pow_mod(2, n - x[i]) - 1) + mod) % mod;
    now = (now - (pow_mod(2, y[i] - 1) - 1) + mod) % mod;
    now = (now - (pow_mod(2, n - y[i]) - 1) + mod) % mod;
    int ld = f[i];
    now = (now + pow_mod(2, ld) - 1) % mod;
    int rd = y[i] - 1 - ld;
    now = (now + pow_mod(2, rd) - 1) % mod;
    int lu = x[i] - 1 - ld;
    now = (now + pow_mod(2, lu) - 1) % mod;
    int ru = n - y[i] - lu;
    now = (now + pow_mod(2, ru) - 1) % mod;
    ret = (ret + now) % mod;
  }
  printf("%d\n", ret);

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

vector< vector<int> > graph;
int ans[200002] = {0};

void DepthFirstSearch(int visit_node, int p_node=-1){
  for(int i=0; i<graph[visit_node].size(); i++){
    if( graph[visit_node][i] == p_node ) continue;
    ans[graph[visit_node][i]] += ans[visit_node];
    DepthFirstSearch(graph[visit_node][i], visit_node);
  }
}

int main(){
  int n, q;
  cin >> n >> q;
  graph.resize(n);
  for(int i=0; i<n-1; i++){
    int idx, connectedNum;
    cin >> idx >> connectedNum;
    graph[idx-1].push_back(connectedNum-1);
    graph[connectedNum-1].push_back(idx-1);
  }

  for(int i=0; i<q; i++){
    int idx, cost;
    cin >> idx >> cost;
    ans[idx-1] += cost;
  }

  DepthFirstSearch(0);

  for(int i=0; i<n; i++) cout << ans[i] << ' ';
  cout << endl;

  return 0;
}


Measured memory_bytes: 23424
import java.util.*;

public class Main {

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

        int n = sc.nextInt();

        int monster[] = new int[n + 1];
        int hero[] = new int[n];

        for (int i = 0; i < n + 1; i++) {
            monster[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            hero[i] = sc.nextInt();
        }

        long ans = 0;

        for (int i = 0; i < n; i++) {
            if (hero[i] <= monster[i]) {
                ans += hero[i];
            } else {
                ans += monster[i];
                hero[i] -= monster[i];
                if (hero[i] <= monster[i + 1]) {
                    ans += hero[i];
                    monster[i + 1] -= hero[i];
                } else {
                    ans += monster[i + 1];
                    monster[i + 1] = 0;
                }
            }
        }

        System.out.println(ans);

        sc.close();

    }

}

Measured memory_bytes: 60568