akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long

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

#define MAX_N 500005

using vint = vector<int>;
using Graph = vector<vint>;

int n;
Graph graph;

int dp1[MAX_N];
void dfs1(int u) {
  dp1[u] = 2-graph[u].size();
  for(int v : graph[u]) {
    dfs1(v);
    dp1[u] += dp1[v];
  }
}

int dp2[MAX_N];
int depth[MAX_N];
void dfs2(int u) {
  dp2[u] = dp1[u];
  for(int v : graph[u]) {
    //dp2[v] += dp2[u] + dp1[v];
    depth[v] = depth[u] + 1;
    dfs2(v);
    dp2[u] += dp2[v];
  }
}

int dp3[MAX_N];
void dfs3(int u) {
  for(int v : graph[u]) {
    dfs3(v);
  }
  if(graph[u].size() == 2) {
    int l = graph[u][0], r = graph[u][1];
    //dp3[u] = max({dp3[l]+dp3[r], dp3[l]+dp2[u]-depth[u], dp3[r]+dp2[u]-depth[u]});
    dp3[u] = min({dp3[l]+1+dp3[r]+1+depth[u], dp3[l]+1+dp2[r]+dp1[r], dp2[l]+dp1[l]+dp3[r]+1});
  } else if(graph[u].size() == 1) {
    int ch = graph[u][0];
    //dp3[u] = max({dp3[ch], dp2[u]-depth[u]});
    dp3[u] = min({dp3[ch]+1+1+depth[u], dp3[ch]+1+1, 1+dp2[ch]+dp1[ch]});
  } else {
    dp3[u] = dp1[u];//dp2[u]-depth[u];
  }
}

signed main() {
  cin >> n;
  graph.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(a != n-1) graph[i].push_back(a);
    if(b != n-1) graph[i].push_back(b);
  }
  dfs1(0);
  dfs2(0);
  dfs3(0);
  int leaf = 0;
  rep(i, n-1) leaf += 2-graph[i].size();
  /*
  int sum = leaf;
  reps(i, 1, n-1) sum += dp1[i];
  int ans = 0;
  rep(i, n-1) ans = max(ans, dp3[i]);
  //cout << sum << " " << ans << endl;
  cout << sum - ans << endl;
  */
  cout << dp3[0] << endl;

  return 0;
}



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

int main(){
  int N;
  int count = 0;
  int temp0 = 1;
  int temp1 = 1;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  while (temp1 != -1 && temp1 != 2) {
    temp1 = a.at(temp0-1);
    a.at(temp0-1) = -1;
    temp0 = temp1;
    count++;
    if (temp1 == -1)
      count = -1;
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long h;
  cin >> h;
  long long i = 1;
  int count = 0;
  long long ans;
  for (count; i <= h; count++) {
    i *= 2;
  }

  ans = pow(2, count) - 1;
  cout << ans;

  return 0;
}


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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<pair<int, int>> primeFact(int n) {
  vector<pair<int, int>> res;
  for (int i = 2; i * i <= n; i++) {
    int divcnt = 0;
    if (n % i == 0) {
      do {
        divcnt++;
        n /= i;
      } while (n % i == 0);
      res.emplace_back(i, divcnt);
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int powMod(int n, int p) {
  int res = 1;
  while (p) {
    if (p & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
    p >>= 1;
  }
  return res;
}
int invMod(int n) {
  return powMod(n, MOD - 2);
}

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  map<int, int> m;
  REP(i, N){
    auto v = primeFact(A[i]);
    for(auto p : v){
      chmax(m[p.first], p.second);
    }
  }

  int l = 1;
  for(auto p : m){
    (l *= powMod(p.first, p.second)) %= MOD;
  }

  int ans = 0;
  REP(i, N){
    (ans += l*invMod(A[i])) %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 896
k = int(input())
a_b = input()
a = int(a_b.split(" ")[0])
b = int(a_b.split(" ")[1])

for i in range(1, 1000):
  if a<= (i* k) <= b:
    print("OK")
    break
  elif (i* k) > b:
    print("NG")
    break
else:
    print("NG")



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

int main(void){
    int N,M,X,left=0,right=0,j=0;
    cin>>N>>M>>X;
    int n[N+1],A[M];

    for(int i=0;i<M;i++){
        cin>>A[i];
    }
    for(int i=0;i<=N;i++){
        n[i]=0;
        if(i==A[j]){
            n[i]++;
            j++;
        }
    }

    for(int i=X;i<=N;i++){
        right+=n[i];
    }
    for(int k=X;k>=0;k-=1){
        left+=n[k];
    }

    cout<<(right>left?left:right)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Integer q,i,t,f,t1;
		String ans,start;
		Scanner sc = new Scanner(System.in);

		t1=0;
		start="";
		ans=sc.next();
		q=sc.nextInt();
		
		StringBuffer ans_buf = new StringBuffer(ans);
		StringBuffer start_buf = new StringBuffer(start);

		for (i=0;i<q;i++){
			t=sc.nextInt();
			if(t==1){
				t1++;
			} else{
				f=sc.nextInt();
				if((t1+f)%2==0){
					ans_buf.append(sc.next());
				} else {
					start_buf.append(sc.next());
				}
			}
		}

		if(t1%2==1){
			ans=ans_buf.reverse().toString() + start_buf.toString();
		}else{
			ans=start_buf.reverse().toString() + ans_buf.toString();
		}
				System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 129392
from sys import stdin, stdout
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	MOD = 10**9 + 7
	x = []
	for c in rll()[0]:
		x.append(int(c))
	d = int(rl())
	ans = 0

	dp = [[[0]*2 for j in range(d)] for i in range(len(x)+1)]
	dp[0][0][1] = 1
	for i in range(len(x)):
		for digsum in range(d):
			for tight in range(2):
				for dig in range(x[i]+1 if tight else 10):
					ns = (digsum + dig) % d 
					ntight = 1 if tight and dig == x[i] else 0
					dp[i+1][ns][ntight] += dp[i][digsum][tight]
					dp[i+1][ns][ntight] %= MOD

	ans = (dp[len(x)][0][0] + dp[len(x)][0][1] - 1) % MOD
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 130012
#include <bits/stdc++.h>
using namespace std;
int a[100000][3];
int main()
{
	int f=1,i,j,n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		if((a[i][2]+a[i][1]>a[i][0])||a[i][0]%2!=(a[i][1]+a[i][2])%2)
		f=0;
	}
	if(f==1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
 } 

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, double> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  int n, ma, mb;
  cin >> n >> ma >> mb;

  int dp[401][401];
  rep(i, 401) {
    rep(j, 401) {
      dp[i][j] = INF;
    }
  }

  int ans = INF;
  rep(k, n) {
    int a, b, c;
    cin >> a >> b >> c;
    repr(i, 401) {
      repr(j, 401) {
        if (dp[i][j] != INF) {
          minch(dp[i + a][j + b], dp[i][j] + c);
          if ((i + a) * mb == (j + b) * ma) minch(ans, dp[i + a][j + b]);
        }
      }
    }
    minch(dp[a][b], c);
    if(a * mb == b * ma) minch(ans, dp[a][b]);
  }

  print(((ans != INF) ? ans : -1));

  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
    int x, y;
    int small, large;

    while (1){
        scanf("%d %d",&x, &y);
        if (x == 0 && y == 0) {
            break;
        } else {
            if (x <= y) {
                small = x;
                large = y;
            } else {
                small = y;
                large = x;
            }
            printf("%d %d\n", small, large);
        }
    }

    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;


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

	vector<int> kuro_sum(n, 0);		// その番号までの黒石の合計
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if (s[i] == '#') {
				kuro_sum.at(i) = 1;
			} else {
				kuro_sum.at(i) = 0;
			}
		} else {
			if (s[i] == '#') {
				kuro_sum.at(i) = kuro_sum.at(i - 1) + 1;
			} else {
				kuro_sum.at(i) = kuro_sum.at(i - 1);
			}
		}
	}

	vector<int> ans(n + 1, n);
	// 全部黒
	ans.at(0) = n - kuro_sum.at(n - 1);

	// i個めから全部黒(1 <= i <= n - 1)
	for (int i = 1; i < n; i++) {
		ans.at(i) = kuro_sum.at(i - 1) + ((n - i) - (kuro_sum.at(n - 1) - kuro_sum.at(i - 1)));
	}

	// 全部白
	ans.at(n) = kuro_sum.at(n - 1);

	sort(ans.begin(), ans.end());
	cout << ans.at(0) << endl;
}

Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int num[410][410] = {};
long long int DP[410] = {};

int main(){
	int N, C;
	cin >> N >> C;
	long long int A[410], B[410];
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = 0; i < N; i++){
		cin >> B[i];
	}
	for(int i = 0; i < 410; i++){
		num[i][0] = 1;
	}
	for(int i = 0; i < 410; i++){
		for(int j = 1; j < 410; j++){
			num[i][j] = num[i][j - 1] * i % MOD;
		}
	}
	for(int i = 1; i < 410; i++){
		for(int j = 0; j < 410; j++){
			num[i][j] += num[i - 1][j];
			num[i][j] %= MOD;
		}
	}
	DP[0] = 1;
	for(int i = 0; i < N; i++){
		for(int pos = C; pos >= 0; pos--){
			DP[pos] *= B[i] - A[i] + 1 + MOD;
			DP[pos] %= MOD;
			for(int j = 1; j <= pos; j++){
				long long int P = num[B[i]][j] - num[A[i] - 1][j] + MOD;
				DP[pos] += DP[pos - j] * P;
				DP[pos] %= MOD;
			}
		}
	}
	cout << DP[C] << endl;
  return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main{
	Scanner sc = new Scanner(System.in);
	String [] name;
	int [] s,w;
	String ans;
	int n, value;
	boolean [] used;
	
	private void doit(){
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			name = new String[n];
			s = new int[n];
			w = new int[n];
			for(int i = 0; i < n; i++){
				name[i] = sc.next();
				w[i] = sc.nextInt();
				s[i] = sc.nextInt();
			}
			used = new boolean[n];
			ans = "";
			value = 1 << 24;
			dfs(0,0,0, new StringBuilder());
			for(int i = ans.length() - 1; i >= 0; i--){
				int ind = ans.charAt(i) - '0';
				System.out.println(name[ind]);
			}
		}
	}

	private void dfs(int deep, int wsum, int gsum,  StringBuilder order) {
		if(deep == n){
			if(gsum < value){
				value = gsum;
				ans = new String(order.toString());
			}
			return;
		}
		for(int i = 0; i < n;i++){
			if(! used[i] && s[i] >= wsum){
				used[i] = true;
				order.append(i);
				dfs(deep + 1, wsum + w[i], gsum + w[i] * (n - deep),order);
				order.deleteCharAt(order.length() - 1);
				used[i] = false;
			}
		}
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 23096
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

ll lcm(ll a, ll b){
  return a * b / gcd(a,b);
}

ll solve(ll x, ll val) {
  ll ret = x/val;
  return ret;
}

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

  ll a,b,c,d;
  cin >> a >> b >> c >> d;

  ll lcmval = lcm(c, d);
  a--;


  cout << b-solve(b, c)-solve(b, d)+solve(b, lcmval) - (a-solve(a, c)-solve(a, d)+solve(a, lcmval)) << endl;
  /* 
  cerr << solve(a, lcmval) << endl;
  cerr << (a-solve(a, c)-solve(a, d)) << endl;
  cerr << b-solve(b, c)-solve(b, d)+solve(b, lcmval) << endl;
  cerr << (a-solve(a, c)-solve(a, d)+solve(a, lcmval)) << endl;

  cerr << a << endl;
  cerr << solve(a, c) << " " << solve(a,d) << " " << solve(a, lcmval);
  */
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int H, W, K;
    cin >> H >> W >> K;
    vector<string> A;
    int diff = 1000000;
    vector<vector<bool>> visited(H, vector<bool>(W, false));

    P start;
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        A.push_back(s);
        for (int j = 0; j < W; ++j) {
            if (s[j] == 'S') {
                start = {i, j};
                diff = min(min(i, H - 1 - i), min(j, W - 1 - j));
                visited[i][j] = true;
            }
        }
    }
    deque<P> queue;
    queue.push_back(start);

    while (!queue.empty()) {
        P q = queue.front();
        queue.pop_front();
        for (int i = 0; i < 4; ++i) {
            int x = dx[i];
            int y = dy[i];
            int a = q.first;
            int b = q.second;
            if (abs(a - start.first) + abs(b - start.second) > K) {
                continue;
            }
            int tmp = min(min(a, H - 1 - a), min(b, W - 1 - b));
            if (tmp < diff){
                diff = tmp;
            }
            if ((0 <= a + y && a + y <= H - 1) && 0 <= b + x && b + x <= W - 1) {
                if (visited[a + y][b + x] || A[a + y][b + x] != '.') {
                    continue;
                } else {
                    queue.push_back({a + y, b + x});
                    visited[a + y][b + x] = true;
                }
            }
        }
    }
    int ans = 1;
    if (diff == 0) {
        cout << ans << endl;
    } else {
        cout << ans + ((K - 1) + diff) / K << endl;
    }


}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int cnt = 0;
    for(int i=1; i<=s.size()-2; ++i) {
        cnt++;
    }
    string ss = to_string(cnt);
    cout << s[0] << ss << s[s.size()-1] << "\n";
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
typedef std :: pair <int, int> pii;
typedef std :: pair <int, pii> piii;
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
const int N = 1e5 + 5;
int n, m, Q, id[N], dist[N], col[N];
int tot, first[N], next[N << 1], end[N << 1];
int dep[N], val[N];
inline void AddEdge(int x, int y) {
	next[++tot] = first[x], first[x] = tot, end[tot] = y;
	next[++tot] = first[y], first[y] = tot, end[tot] = x;
}
void solve(int u, int dist, int col) {
	if (!val[u]) val[u] = col;
	if (dep[u] >= dist) return;
	
	dep[u] = dist;
	for (int k = first[u], v; v = end[k], k; k = next[k]) solve(v, dist - 1, col);
}
int main() {
	n = Get(), m = Get();
	for (int i = 1; i <= m; ++i) AddEdge(Get(), Get());
	
	Q = Get();
	for (int i = 1; i <= Q; ++i) id[i] = Get(), dist[i] = Get(), col[i] = Get();
	
	for (int i = Q; i; --i) solve(id[i], dist[i], col[i]);
	
	for (int i = 1; i <= n; ++i) printf("%d\n", val[i]);
	
	return 0;
}

Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	if ((h == b && w != a) || (h != b && w == a)) {
		cout << "No\n";
		return 0;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i < b && j < a || i >= b && j >= a) {
				cout << 1;
			}
			else cout << 0;
		}
		cout << endl;
	}
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int NA = N * A;
  
  if (NA > B){
    cout << B << endl;
  }else{
    cout << NA << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	ll a = 0; ll b = 0;
	for(int i = 0; i < n; i++)
	{
		ll x, y; cin >> x >> y;
		if(i == 0)
		{
			a = x; b = y;
		}
		else
		{
			ll sum = a + b;
			while(sum%(x+y) != 0)
			{
				sum++;
			}
			ll z1 = sum/(x+y)*x; ll z2 = sum/(x+y)*y;
			ll change = max((a - z1 + x - 1)/x, (b - z2 + y - 1)/y);
			change = max(change, 0LL);
			a = z1 + change*x; b = z2 + change*y;
		}
		//cerr<<a<<' '<<b<<'\n';
	}
	cout << a + b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int a[3];
    int sum=0;
    rep(i,3){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){  
  int A, B;
  char S[10], T[10], U[10];
  
  scanf("%s%s%d%d%s",S,T,&A,&B,U);
  if(strcmp(S,U) == 0){
    A--;
  }else{
    B--;
  }
  printf("%d %d",A,B);
  
  return(0);
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; ++i) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        System.out.println(solve(l, r, S));

        sc.close();
    }

    static String solve(int[] l, int[] r, String S) {
        int[] prefixCounts = new int[S.length()];
        int prefixCount = 0;
        for (int i = 1; i < prefixCounts.length; ++i) {
            if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C') {
                ++prefixCount;
            }

            prefixCounts[i] = prefixCount;
        }

        return IntStream.range(0, l.length)
                .mapToObj(i -> String.valueOf(prefixCounts[r[i] - 1] - prefixCounts[l[i] - 1]))
                .collect(Collectors.joining("\n"));
    }
}

Measured memory_bytes: 68140
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}
func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

// ax+by=gcd(a,b)
func extgcd(a, b int) (x, y int) {
	y = 1
	x = 0
	for u, v := 1, 0; a != 0; {
		q := b / a
		u, x = x - q * u, u
		v, y = y - q * v, v
		a, b = b - q * a, a
	}

	return
}

func modinv(a, m int) int {
	x, _ := extgcd(a, m)
	return (m + x % m) % m
}

func fact(n, mod int) int {
	ret := 1
	for n > 1 {
		ret = ret * n % mod
		n--
	}
	return ret
}

type P struct {
	w,p int
}

func main() {
	io := NewIo()
	defer io.writer.Flush()

	//n := io.NextInt()
	//k := io.NextInt()
	//
	//vp := make([]P, n, n)
	//for i := 0; i < n; i++ {
	//	vp[i].w = io.NextInt()
	//	vp[i].p = io.NextInt()
	//}

	n := io.NextInt()
	io.Printf("%d\n", 48 - n);
}


Measured memory_bytes: 640
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <unordered_set>
#include <unordered_map>

#include <cctype>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <ctime>
using namespace std;
 
#define FIND(c, e) (c).find(e) != (c).end()
#define NFIND(c, e) (c).find(e) == (c).end()
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
 
const int N = int( 1e5 ) + 1;
const int Q = int( 1e5 ) + 1;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1.0e-6;

void __answer()
{
	string s;
	cin >> s;
	set<char> v(ALL(s));
	cout << (v.size() == s.size() ? "yes" : "no");
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
		// freopen("data.txt", "w", stdout);
		// freopen("log.txt", "w", stderr);
    #endif
    __answer();
    return 0;
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    double ans = 0;
    for(ll i = 1; i <= N; i++) {
        if(K <= i) {
            ans += 1;
        } else {
            double n = (ll)ceil(log2(K * 1.0 / i));
            ans += pow(0.5, n);
        }
    }
    cout << setprecision(15) << ans / N << endl;
    return 0;
}

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

const int mod = 1e9 + 7;

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

void upd(int &x, int y) {
    if ((x += y) >= mod) x -= mod;
}

int main() {
    int n, K;
    cin >> n >> K;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    static int dp[101][101][256];
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 100; j++) {
            for (int k = 0; k < 256; k++) {
                upd(dp[i + 1][j][k], dp[i][j][k]);
                upd(dp[i + 1][j + 1][k ^ a[i]], dp[i][j][k]);
            }
        }
    }
    int ans = 0;
    int fact = 1;
    for (int i = 1; i <= n; i++) {
        fact = mul(i, fact);
        upd(ans, mul(fact, dp[n][i][K]));
    }
    cout << ans << endl;
}

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


int main()
{
	int x[5];
	int c;
	for (int i = 0; i < 5; ++i)
	{
		cin >> x[i];
		if (!x[i]) c = i + 1;
	}
	cout << c << endl;
}



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

typedef long long ll;
using namespace std;

#define REP(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin>>a>>b;
    cout << max(max(a+b,a-b),a*b) << endl;
    return  0;
}


Measured memory_bytes: 256
# ref https://black-thunder.hatenablog.com/entry/20200610/1591774050

def solve():
    base = []
    for a, s in zip(A[::-1], map(int, S[::-1])):
        x = a
        for b in base:
            x = min(x, x ^ b)
        if x:
            if s ^ 1:
                base.append(x)
            else:
                return 1
    return 0


t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int, input().split()))
    S = input()
    print(solve())


Measured memory_bytes: 9172
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadInts();
	}

	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}

	public static void Main(string[] args)
	{
		var input = Console.In.ReadInts()[0];
		var sum = 0L;
		for (var i = 1; i <= input; ++i)
		if (i%3 > 0 && i%5 > 0) sum += i;
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 19116
import java.nio.file.FileSystemLoopException;
import java.text.DecimalFormat;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static class P {
        int x;
        int y;

        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            P p = (P) o;
            return x == p.x &&
                    y == p.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }

    static void solve(Scanner scanner) {
        String s = scanner.next();
        for(char c: s.toCharArray()) {
            if (c == '1') {
                System.out.print('9');
            } else if (c == '9') {
                System.out.print('1');
            } else {
                System.out.print(c);
            }
        }
        System.out.println();
    }

}


Measured memory_bytes: 21716
#include <stdio.h>
#include <string.h>
int main(){
  int n;  scanf("%d", &n);
  char siri[103][13];
  int flag = 0;
  for(int i=0; i<n; i++){
    scanf("%s", siri[i]);
    for(int j=0; j<i; j++)
      if(strcmp(siri[i], siri[j])==0){
	flag = 1;
	break;
      }
    if(flag || (i>0 && siri[i][0]!=siri[i-1][strlen(siri[i-1])-1])){
	flag = 1;
	break;
    }
  }
  if(flag)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
      


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	n--;
	for (int i=0;i<=n;i++)
	{
		int j=n-i;
		long long x=c*i,y=d*i,xx=c*j,yy=d*j;
		if (y-xx>=b-a && x-yy<=b-a){
		printf("YES\n");
		return 0;
	}
	}
	printf("NO\n");
	return 0;
}


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

int main() {
	int n;
  	cin>>n;
  	
  	int ans=1000-n%1000;
  
  if(n%1000==0){
  	cout<<0<<endl;
  }
  else{
  cout<<ans<<endl;
  }
}

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

using namespace std;

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

      vector<int> a(n);
      for(int i=0; i<n; i++) cin>>a[i];

      int mn=a[0],mx=a[0];

      for(int i=1; i<n; i++){
            if(mn>a[i]) mn=a[i];
            if(mx<a[i]) mx=a[i];
      }

      cout<<mx-mn<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while (scan.hasNextLine()) {
			// 入力した文字列を格納
			String charStr = scan.nextLine();

			// ループ終了条件
			if (charStr.equals("-")) {
				break;
			}
			// アルファベットを格納するリストを作成
			List<Character> alpha = new ArrayList<>();

			// 入力された文字列をリストに格納する
			for (int i = 0; i < charStr.length(); i++) {
				alpha.add(charStr.charAt(i));
			}
			// 入力したシャッフル回数を格納
			int shuffle = scan.nextInt();

			for (int i = 0; i < shuffle; i++) {
				// 上に持っていく枚数を格納
				int choiceNum = scan.nextInt();
				// 先頭のアルファベットを新たに追加して、削除するループ
				for (int addI = 0; addI < choiceNum; addI++) {
					// 先頭のアルファベットを追加
					alpha.add(alpha.get(0));
					// 先頭のアルファベットを削除
					alpha.remove(0);
				}
			}
			// 並び替えたアルファベットを出力
			for (int i = 0; i < charStr.length(); i++) {
				System.out.print(alpha.get(i));
			}
			System.out.println("");
			charStr = scan.nextLine();
		}
		scan.close();
	}
}



Measured memory_bytes: 26428
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    float x, y, a=0;
    cin >> x >> y;
    while( a <= 1000 ){
        a++;
        if( floor(a * 0.08) == x && floor(a * 0.1) == y ){
            cout << a;
            return 0;
        }
    }
    cout << -1;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long nopen, nback, mopen, mback;
    if(m > 3){
        mopen = 2;
        mback = m - mopen;
    }
    if(m == 3){
        mopen = 2;
        mback = 1;
    }
    if(m == 2){
        mopen = 2;
        mback = 0;
    }
    if(m == 1){
        mopen = 0;
        mback = 1;
    }
    if(n > 3){
        nopen = 2;
        nback = n - nopen;
    }
    if(n == 3){
        nopen = 2;
        nback = 1;
    }
    if(n == 2){
        nopen = 2;
        nback = 0;
    }
    if(n == 1){
        nopen = 0;
        nback = 1;
    }
    cout << mback * nback << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void buildmaxheap(void);
void maxheapfy(int);
void swap(int,int);

int n,i;
int *tree;

int main(){


  scanf("%d",&n);
  tree = malloc((n+1) * sizeof(int));
  for(i=1;i<n+1;i++)
    scanf("%d",&tree[i]);
  buildmaxheap();
  
  for(i=1;i<n+1;i++)
    printf(" %d",tree[i]);
  printf("\n");
  
  return 0;
}


void buildmaxheap(void){

  int i;
  for(i = n / 2;i > 0;i--) maxheapfy(i);

}

void maxheapfy(int i){
  int l,r,larger;
  l = 2 * i;
  r = l + 1;

  if( l <= n && tree[l] > tree[i]) larger = l;
  else larger = i;
  if( r <= n && tree[r] > tree[larger]) larger = r;

  if(larger != i){
    swap(larger,i);
    maxheapfy(larger);
  }
  else return;
}

void swap(int larger,int i){
  int box;
  box = tree[larger];
  tree[larger]=tree[i];
  tree[i]=box;
}

Measured memory_bytes: 2556
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    while (cin >> s)
    {
        if (s[0] == s[1] && s[2] == s[3] && s[0] == s[2])
        {
            cout << "No\n"; continue;
        }
        else if (s[0] == s[1] && s[2] == s[3])
        {
            cout << "Yes\n"; continue;
        }
        else if (s[0] == s[2] && s[1] == s[3])
        {
            cout << "Yes\n"; continue;
        }
        else if (s[0] == s[3] && s[2] == s[1])
        {
            cout << "Yes\n"; continue;
        }
        else cout << "No\n";
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Os") 
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#define ll long long
#define FOR(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF = (int)1e9,mxN = (int)1e5,MOD= INF+7;

void solve()
{
	ll n;
	cin >> n;
	ll ans = 0;
	ll pref[n],a[n];
	FOR(i,n)
	{
		cin >> a[i];
		if(!i)pref[i] = a[i];
		else pref[i] = (a[i]+pref[i-1])%MOD;
	}

	FOR(i,n-1)
		ans = (ans+(a[i]%MOD*(pref[n-1]-pref[i]+MOD)%MOD)%MOD)%MOD;
	cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
}


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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii >

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){out << q.F << " " << q.S; return out;}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){return {p1.F-p2.F, p1.S-p2.S};}


void solve() {
    int n;
    cin >> n;
    int cur = 1;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0)cur = 0;
    }
    if(cur == 0){
        cout << cur << endl;
        return;
    }
    for(int i = 0; i < n; i++){
        if(inf/cur >= a[i]){
            cur *= a[i];
        } else {
            cout << -1 << endl;
            return;
        }
    }
    if(cur > inf){
        cout << -1 << endl;
        return;
    }
    cout << cur << endl;
}

signed main(){

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

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    // cin >> t;
    
    for(int i = 1; i <= t; ++i){
        solve();
    }
    //cerr << time(start);
    return 0;
}


Measured memory_bytes: 4440
#include<stdio.h>
int main(void)
{
    int a,b,ans;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        if(op=='+') ans=a+b;
        else if(op=='-') ans=a-b;
        else if(op=='*') ans=a*b;
        else if(op=='/') ans=a/b;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 2044
s = input()
d = [0] * 3
for a in s:
    if a == "a": d[0] += 1
    if a == "b": d[1] += 1
    if a == "c": d[2] += 1

if max([n - min(d) for n in d]) >= 2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか
int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 2; i < s.size(); i++) {
		if (s[i] == 'C' && s[i - 1] == 'B' && s[i - 2] == 'A') {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    set<int> s;
    rep(i, n) {
        int e;
        cin>>e;
        s.insert(e);
    }

    int m;
    cin>>m;
    set<int> t;
    rep(i, m) {
        int e;
        cin>>e;
        t.insert(e);
    }

    set<int> res;
    set_difference(s.begin(), s.end(), t.begin(), t.end(), inserter(res, res.end()));
    set_difference(t.begin(), t.end(), s.begin(), s.end(), inserter(res, res.end()));

    for (auto e : res) cout<<e<<endl;
}


Measured memory_bytes: 40688
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
static const int N=114514;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<ll>h(n);
  vector<ll>a(n);
  ll temp=0;
  ll ans=0;
  rep(i,n){
    cin>>h[i];
  }
  for(int i=0;i<n-1;i++){
    if(h[i]>=h[i+1]){
      a[i+1]=a[i]+1;
    }
    else{
      a[i+1]=0;
    }
  }
  sort(a.begin(),a.end());
  cout<<a[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a,b,azb,abb,amb;
    cin>>a>>b;
    azb=a*b;
    abb=a+b;
    amb=a-b;
    cout << fmax(fmax(azb,abb),amb);
}


Measured memory_bytes: 3680
#include<stdio.h>

 int main(void){
 

    int x;

    scanf("%d",&x);
 
    if(1 <= x <= 3000){
       if( x < 1200 ){
       printf("ABC");     
       }
   
       else {
       printf("ARC");
       }
     
    }else{
         printf("error");
     }
 }


Measured memory_bytes: 128
#include<stdio.h>
int main(){





int A,B,a;
scanf("%d %d",&A,&B);


a=(A+B)/2;
if(A%2==0 && B%2==0 || A%2!=0 && B%2!=0 ){
    printf("%d\n",a);
}

else{
    printf("IMPOSSIBLE\n");

}

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a % 2 != 0 || b % 2 != 0 || c % 2 != 0) cout << 0 << endl;
    else if(a == b && b == c) cout << -1 << endl;
    else {
        int ans = 0;
        while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
            int d = (b + c) / 2;
            int e = (a + c) / 2;
            int f = (a + b) / 2;
            a = d;
            b = e;
            c = f;
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	int tot=0,t,ans=0;
	cin>>n;
	while(n){
		t=n%10;
		ans+=t;
		n/=10;
		tot++;
	}
	ans=max(ans,(tot-1)*9+t-1);
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ios()                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)

signed main()
{
    string s;
    cin >> s;
    char prev = 'a';
    for (int i = 0; i < s.length(); i++) {
        if(prev == s[i]) {
            cout  << "Bad" << endl;
            return 0;
        }
        prev = s[i];
    }
    cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  string s1;
  int N;
  string c1;
  string c2;

  cin>> N;
  cin>>s1;


  for(int i=0;i<N;i++){
    if(i < N/2) {
      c1 += s1[i];
    }else{
      c2 += s1[i];
    }
  }

  if(c1 == c2){
    cout << "Yes"<< endl;
  }else{
    cout << "No"<< endl;
  }

  return 0;
}

Measured memory_bytes: 256
# 簡単なんだけど

n = int(input())
a = list(map(int, input().split()))
even_p = [0]
odd_p = [0]
for i in range(n):
    if i%2 == 0:
        even_p.append(even_p[-1]+a[i])
        odd_p.append(odd_p[-1])
    else:
        even_p.append(even_p[-1])
        odd_p.append(odd_p[-1]+a[i])


l = []
for i in range(n):
    ans = 0
    if i % 2 == 0:
        ans += even_p[-1] - even_p[i]
        ans -= odd_p[-1] - odd_p[i]
        ans -= even_p[i]
        ans += odd_p[i]
        l.append(ans)
    else:
        ans += odd_p[-1] - odd_p[i]
        ans -= even_p[-1] - even_p[i]
        ans -= odd_p[i]
        ans += even_p[i]
        l.append(ans)
print(*l)

Measured memory_bytes: 71908