akhauriyash/Code-Regression huggingface dataset:
# F - LIS on Tree

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
adj = {u: [] for u in range(n)}
for i in range(n - 1):
    u, v = map(int, input().split())
    adj[u - 1].append(v - 1)
    adj[v - 1].append(u - 1)

# lis[i] == 長さi+1の増加列の末尾の最小値
lis = [float('inf')] * n

lislen = [0] * n  # lislen[u] == 頂点uまでのLISの長さ
backup = [None] * n

# DFS (with an explicit stack)
stack = [(0, 0)]  # (parent, child)
while len(stack) > 0:
    p, u = stack.pop()
    if p == None:  # 帰りがけ
        l, x = backup[u]
        lis[l] = x  # 復元
    else:  # 行きがけ
        l = bisect_left(lis, a[u])  # a[u]を使って長さl+1のLISを作れる
        backup[u] = (l, lis[l])  # 後で復元するために保存
        lis[l] = a[u]  # 更新
        lislen[u] = bisect_left(lis, float('inf'))  # 現時点のLISの長さ
        stack.append((None, u))  # 帰りがけタスクをpush
        for v in adj[u]:
            if v != p:
                stack.append((u, v))

for u in range(n):
    print(lislen[u])


Measured memory_bytes: 146132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


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

	rep(i, S.length() - 8){
		cout << S[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

vvll g;
ll dp[110000][2];

void dfs(ll n, ll p = -1) {
    for(auto e : g[n]) {
        if(e == p) continue;
        dfs(e, n);
        dp[n][0] *= (dp[e][0] + dp[e][1]);
        dp[n][1] *= dp[e][0];
        dp[n][0] %= MOD;
        dp[n][1] %= MOD;
    }
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N; cin >> N;
    g.resize(N);
    rep(i,N-1) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    rep(i, N) rep(j, 2) dp[i][j] = 1;
    dfs(0);
    ll ans = (dp[0][0] + dp[0][1]) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  cout << (n+1)/2 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dfs(vector <int> &a,vector<bool> &isfind,int x);
int main(void){
    // Here your code !
    int N;cin >> N;
    vector <int> a(N);
    vector <bool> isfind(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    cout << dfs(a,isfind,1) <<"\n";
    
    
}

int dfs(vector <int> &a,vector <bool> &isfind,int x){
    int b;
    if(x==2){
        return 0;
        
    }
    else
    {
        if(isfind[x-1]){return -1;}
        isfind[x-1]=true;
        b=dfs(a,isfind,a[x-1]);
        if(b>a.size()||b==-1){return -1;}
        return 1+b;
        
    }
    
    
}

Measured memory_bytes: 2176
#include <stdio.h>
#define NIL -1
int d,P[100005];

int getDepth(int x){
    
    d = 0;
    while(P[x] != NIL){
        
        x = P[x];
        d++;
        
    }
    
    return d;
    
}

int main()
{
    int i,j,m,n,k,c,sum;
    
    scanf("%d",&m);
    
    int L[m],R[m],T[m];
    
    for(i = 0; i < m; i++){
    P[i] = NIL;
    L[i] = NIL;
    R[i] = NIL;
    }
    
    for(i = 0; i < m; i++){
        
        scanf("%d",&n);
        scanf("%d",&k);
        T[i] = k;
        
        for(j = 0; j < k; j++){
            
            scanf("%d",&c);
            P[c] = n;
            if(j==0) L[n] = c;
            else R[sum] = c;
            sum = c;
            
        }
    }
    
    for(i = 0; i < m; i++){
        
        printf("node %d: ",i);
        printf("parent = %d, ",P[i]);
        printf("depth = %d, ",getDepth(i));
        
        if(P[i] == NIL) printf("root, ");
        else if(L[i] == NIL) printf("leaf, ");
        else printf("internal node, ");
        
        printf("[");
        
        for(j = 0, c = L[i]; c != NIL; j++, c = R[c]){
            
            if(j) printf(", ");
            printf("%d",c);
            
        }
        
        printf("]\n");
        
        }
        
    return 0;
}


Measured memory_bytes: 3348
#include <iostream>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int a[200][3];
int x[101][3];

int main(){
	int n;
	cin >> n;
	rep(i,n) rep(j,3){
		cin >> a[i][j];
		x[a[i][j]][j]++;
	}
	rep(i,n){
		int ans = 0;
		rep(j,3) if(x[a[i][j]][j] == 1) ans += a[i][j];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> imos(1e5+5);
    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        imos[L]++;
        imos[R + 1]--;
    }

    for (int i = 1; i < imos.size(); i++) {
        imos[i] += imos[i - 1];
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += imos[i] == M;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int a,b;
   cin>>a>>b;
   if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12))
   {
       cout<<"Yes"<<endl;
   }
   else if((a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11))
   {
       cout<<"Yes"<<endl;
   }
   else if(a==2&&b==2)
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)

int c[200][3];
int main(void){
    int n; cin >> n;
    rep(i,n)rep(j,3) cin>>c[i][j];
    rep(i,n){
        int p = 0;
        rep(j,3){
            int num = 0;
            rep(k,n) if(c[i][j] == c[k][j]) num++;
            if(num == 1) p += c[i][j];
        }
        cout << p << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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 INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int H,W;
int A[100][100];
int B[100][100];
//dp[i][j][0]: i,jの色分けが10のときの偏りの最小値
//dp[i][j][1]: i,jの色分けが01のときの偏りの最小値
bool dp[100][100][10000];
void debug(){
    rep(i,H+1){
        rep(j,W+1){
        cerr<<dp[i][j][0]<<" ";
        }
        cerr<<endl;
    }
    cerr<<endl;
    cerr<<endl;
    rep(i,H+1){
        rep(j,W+1){
        cerr<<dp[i][j][1]<<" ";
        }
        cerr<<endl;
    }
    cerr<<endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin>>H>>W;
    rep(i,H)rep(j,W){
        cin>>A[i][j];
    }
    rep(i,H)rep(j,W){
        cin>>B[i][j];
    }
    rep(i,H)rep(j,W)rep(k,10000){
        dp[i][j][k] = false;
    }
    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    rep(i,H)rep(j,W)rep(k, 10000){
        if(dp[i][j][k]){
            dp[i+1][j][    k + abs(A[i+1][j] - B[i+1][j]) ] = true;
            dp[i+1][j][abs(k - abs(A[i+1][j] - B[i+1][j]))] = true;
            dp[i][j+1][    k + abs(A[i][j+1] - B[i][j+1]) ] = true;
            dp[i][j+1][abs(k - abs(A[i][j+1] - B[i][j+1]))] = true;
        }
    }
    /*
    rep(i,H+1)rep(j,W+1){
        cerr<<"("<<i<<", "<<j<<")"<<endl;
        rep(k, 6500){
            if(dp[i][j][k]){
                cerr<<k<<" ";
            }
        }
        cerr<<endl;
    }
    */
    ll ans = -1;
    rep(i,10000){
        if(dp[H-1][W-1][i]){
            ans = i;
            break;
        }
    }
    if(ans == -1)cerr<<"what!?"<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 79872
def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
B = input().split()
S = B[:]
B = BubbleSort(B, N)
S = SelectionSort(S, N)
mes = "Stable" if isStable(B, S, N) else "Not stable"
print(" ".join(B))
print("Stable")
print(" ".join(S))
print(mes)

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

const int INF=1e9;
int ab[123456],bc[123456],ca[123456],ans=INF;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
bool check(char a,char b){
  return (a!='?'&&b!='?'&&a!=b);
}

signed main(){
  string a,b,c;cin>>a>>b>>c;
  int A=a.size(),B=b.size(),C=c.size();
  for(int i=-4000;i<=4000;i++)//aをbに比べてi文字だけ手前に置く（a[j+i]とb[j]が重なる）
    for(int j=0;j<B;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],b[j]))
        ab[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//bをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<B&&check(b[j+i],c[j]))
        bc[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//aをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],c[j]))
        ca[5000+i]=1;
  for(int i=-4000;i<=4000;i++){//aをbに
    for(int j=-4000;j<=4000;j++){//bをcに
      if(ab[5000+i])continue;
      if(bc[5000+j])continue;
      if(abs(i+j)<=4000&&ca[5000+i+j])continue;
      chmin(ans,max({-i-j+A,-j+B,C})-min({-i-j,-j,0}));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
(defstruct p i city point)
(defun f (s)
  (let* ((n (read s))
         (ps (loop #:for i #:from 1 to n
                   #:for city = (read s)
                   #:for point = (read s)
                   #:collecting (make-p :i i :city city :point point)))
         (sorted1 (sort ps #'> :key #'p-point))
         (sorted2 (sort sorted1 #'string< :key #'p-city)))
    (loop #:for p #:in sorted2
          #:do (progn (princ (p-i p)) (terpri)))))
(f t)

Measured memory_bytes: 18404
N = gets.to_i
H = gets.split.map(&:to_i)

def calc(ar)
  if ar.empty?
    0
  elsif ar.size == 1
    ar[0]
  else  
    m = ar.min
    ar.inject([[]]) {|br, x|
      if x == m
        br << []
      else  
        br.last << x - m 
      end
      br
    }.map{|cr| calc(cr)}.inject(:+) + m
  end
end 

puts calc(H)

Measured memory_bytes: 3964
N, C, K = [int(_) for _ in input().split()]
times = sorted([int(input()) for _ in range(N)])
count = 0
while times:
    t = times.pop(0)
    count += 1
    num = 1
    while times:
        if times[0] <= t + K and num < C:
            times.pop(0)
            num += 1
        else:
            break
print(count)


Measured memory_bytes: 8280
#include <bits/stdc++.h>
#include<iostream>
#define LL long long
using namespace std;

LL gcd(LL a, LL b){
    LL x,y,z;
    if (a > b) { 
        x = a;
        y = b;
    } else {
        x = b;
        y = a;
    }
    z = x % y;
    if (z == 0) {
        return y;
    } else {
        return gcd(y,z);
    }
}


int main(void)
{
    LL n,p;
    cin >> n >> p;
    if (n == 1) {
        cout << p << endl;
    } else {
        LL ma = pow(p, 1.0/n)+1;
        for (LL l = ma; l > 0; l--){
            LL lx = pow(l, n-1);
            if (p % lx != 0) continue;
            LL ly = p / lx;
            LL lz = gcd(ly,l);
            if (lz == l) {
                cout << l << endl;
                return 0;
            }
        }
    } 


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector< int > A;
bool rec(int now,int sum){
  if(!sum) return true;
  else if(now == A.size() || sum < 0) return false;
  return rec( now + 1, sum - A[now]) || rec( now + 1, sum);
}
int main(){
  int n;
  cin >> n;
  A.resize(n);
  for(int i = 0 ; i < n ; i++ ) cin >> A[i];
  int q;
  cin >> q;
  for(int i = 0 ; i < q ; i++ ){
    int M;
    cin >> M;
    cout << ( rec(0,M) ? "yes" : "no" ) << endl;
  }
}


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

typedef long long ll;

ll gcd(ll n,ll m){
  if(m==0){
    return n;
  }
  else{
    return gcd(m,n%m);
  }
}

int main(){
  ll n,x;
  cin >> n >> x;
  cout << 3*(n-gcd(n,x)) << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    cout << x*x*x<<"\n";
    }


Measured memory_bytes: 3132
H,W=map(int,input().strip().split())

if H == 1 or W == 1:
    print(1)
elif H % 2 == 0:
    print((H//2)*W)
else:
    sets = W // 2
    sum = ((H//2)*2+1)*sets
    if W % 2 == 1:
        sum += ((H//2) + 1)
    print(sum)

Measured memory_bytes: 61856
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    ll N=0;
    string S;
    cin >> N>>S;
    ll count=0;
    
    for(ll i=0;i<N-2;i++){
        if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C')
        count++;
    }
    
    cout << count;
}

Measured memory_bytes: 256
while True:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    ans = 0
    for i in range(2**10):
        now = 0
        z = 0
        for k in range(10):
            if i >> k & 1:
                z += 1
                now += k
        if z == n and now == s:
            ans += 1
    print(ans)


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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
#define int long long

typedef pair<int,int> pii;
const int N = 1e6+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int x, y;
int fact[N], r[N], rfact[N];
void precalc(){
	fact[0] = rfact[0] = 1;
	r[1] = 1;
	for(int i=2; i<N; i++){
		r[i] = MOD - (MOD/i)*r[MOD%i] % MOD;
	}
	for(int i=1; i<N; i++){
		fact[i] = fact[i-1]*i % MOD;
		rfact[i] = rfact[i-1]*r[i] % MOD;
	}
}
int C(int n, int k){
	if (n < 0 || k < 0 || k > n) return 0LL;
	return fact[n]*rfact[k]% MOD * rfact[n-k] % MOD;
}
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> x >> y;
	if ((x+y) % 3 != 0) return 0*puts("0");
	//n: (+1, +2) m: (+2, +1)
	//n+2m = x && 2n+m = y => n, m
	int m = (2*x-y)/3;
	int n = x-2*m;
	if (n < 0 || m < 0) return 0*puts("0");
	//ans = (n+m)Cn
	precalc();
	int ans = C(n+m, n);
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
  string s;
  long long k;
  cin >> s >> k;
  if(s.size() >= k) {
    bool find = false;
    for(int i=0; i < k; i++) if(s[i] != '1') {cout << s[i] << endl; find = true; break;}
    if(!find) cout << 1 << endl;
  }
  else {
    for(int i=0; i < s.size(); i++) if(s[i] != '1') {cout << s[i] << endl; break;}
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define int long long
inline int read(){
	int x=0;char ch=getchar();
	for(;ch<48||ch>57;ch=getchar());
	for(;ch>47&&ch<58;ch=getchar())
	x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
signed main()
{
	int a=read(),b=read(),c=min(read(),min(a*4,b*2)),d=min(read(),c*2),n=read();
	printf("%lld\n",(n>>1)*d+(n&1)*c);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  int M;
  M = N;
  
  int sum = 0;
  
  int a = 100000000;

  for (int i = 0; i < 8; i++){
    
    a /= 10;
    sum += N / a;
    N -= (N / a) * a;
    
  }
  if (M % sum == 0)
    cout << "Yes" << endl;
 
  else
    cout << "No" << endl;
}


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

int main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  
  int count=0;
  for(int i=0;i<a+b+2;i++){
    if(s[i]=='-')++count;
  }
  
  if(count==1&&s[a]=='-'){
    cout<<"Yes"<<endl;}
  
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
//        int a = int.Parse(input[2]);
//        int b = int.Parse(input[3]);
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
        int a = Max(n+m,n-m);
        a = Max(a,n*m);
        WriteLine(a);
    }
}

Measured memory_bytes: 11092
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (n > 0) {
        n /= k;
        cnt++;
    }
    cout << cnt;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

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

using namespace std;

int main(){

  int n;
  bool flag = true;
  int count = 0;

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

    cin >> tmp;
    if(tmp == "A") count++;
    else if(tmp == "Un") count--;
    if(count < 0) {
      flag = false;
      break;
    }
  }
  if(count != 0) flag = false;
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}



Measured memory_bytes: 3160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.function.IntPredicate;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ELogs solver = new ELogs();
        solver.solve(1, in, out);
        out.close();
    }

    static class ELogs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = in.readIntArray(n);

            IntPredicate cuts = l -> {
                if (l <= 0)
                    return false;
                long c = 0;
                for (int x : a) {
                    c += (x - 1) / l;
                }
                return c <= k;
            };

            out.println(BinarySearch.binarySearch(cuts::test));
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }

    static class BinarySearch {
        public static int binarySearch(IntPredicate bigEnough) {
            int tooSmall = 0, tooBig;
            if (bigEnough.test(tooSmall)) {
                return tooSmall;
            }

            for (tooBig = 1; !bigEnough.test(tooBig); tooBig *= 2)
                ;

            if (!bigEnough.test(tooBig - 1)) {
                return tooBig;
            }

            while (tooBig - tooSmall > 1) {
                int center = tooSmall + (tooBig - tooSmall) / 2;
                if (!bigEnough.test(center)) {
                    tooSmall = center;
                } else {
                    tooBig = center;
                }
            }

            return tooBig;
        }

    }
}



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

int a, b, sisa;

int main () {
	cin >> a >> b;
	if (a<b){
		cout << "0" << endl;
	} else {
		sisa = a - (2*b);
		if (sisa<0){
			cout << "0" << endl;
		} else {
			cout << sisa << endl;
		}
	}
}

Measured memory_bytes: 256
fib = [0 for i in range(10**5+1)]
fib[0] = 1
fib[1] = 1
for i in range(2,10**5+1):
    fib[i] = fib[i-1] + fib[i-2] % (10**9+7)
n,m = map(int,input().split())
a = [-1]
for i in range(m):
    ai = int(input())
    if ai - a[i] == 1:
        print(0)
        exit()
    a.append(ai)
a.append(n+1)
ans = 1
for i in range(1,m+2):
    ans = (ans * fib[a[i]-a[i-1]-2]) % (10**9 + 7)
print(ans)

Measured memory_bytes: 9756
a=[0]*6+[1,0,1,0,0,0,0]*42857
p=[]
for i in range(6,300000,7):
    if a[i]:
        p+=[i]
        for j in range(i**2,300000,i):
            a[j]=0
    if a[i+2]:
        p+=[i+2]
        for j in range((i+2)**2,300000,i+2):
            a[j]=0
while 1:
    n=int(input())
    if n==1:break
    b=[x for x in p if n%x==0]
    print('{}: {}'.format(n, ' '.join(map(str, b))))

Measured memory_bytes: 12024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

bool sortby2(pair<pair<string,int>,int> &a, pair<pair<string,int>,int> &b)
{
   if(a.first.first == b.first.first)
      return a.first.second > b.first.second;
   return (a.first.first < b.first.first);
}

int main()
{
   int n;
   cin>>n;
   vector<pair<pair<string, int>,int>> v(n);
   for(int i=0;i<n;i++)
   {
      cin>>v[i].first.first;
      cin>>v[i].first.second;
      v[i].second = i+1;
   }

   sort(v.begin(), v.end(), sortby2);
   for (auto i = v.begin(); i !=v.end(); i++)
   {
      cout<<(*i).second<<endl;
   }
   
   return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int N;
int A, B, C;
int l[8] = {0};

int eval(const vector<int>& v) {
  int freq[4] = {0};
  int sum[4] = {0};

  for (int i = 0; i < v.size(); ++i) {
    freq[v[i]]++;
    sum[v[i]] += l[i];
  }

  if (freq[3] == N) {
    return numeric_limits<int>::max();
  }
  for (int i = 0; i < 3; ++i) {
    if (freq[i] == 0) {
      return numeric_limits<int>::max();
    }
  }

  return abs(sum[0] - A) + 10 * (freq[0] - 1) + abs(sum[1] - B) +
         10 * (freq[1] - 1) + abs(sum[2] - C) + 10 * (freq[2] - 1);
}

int dfs(int depth, vector<int>& v) {
  if (depth == N) {
    return eval(v);
  }
  int min_mp = numeric_limits<int>::max();
  // i = 0 => A
  // i = 1 => B
  // i = 2 => C
  // i = 3 => don't choose
  for (int i = 0; i < 4; ++i) {
    v[depth] = i;
    min_mp = min(min_mp, dfs(depth + 1, v));
  }
  return min_mp;
}

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

  cin >> N >> A >> B >> C;

  for (int i = 0; i < N; ++i) {
    cin >> l[i];
  }
  vector<int> v(N);
  cout << dfs(0, v) << endl;

  return 0;
}


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

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if ( x - r < 0 || x + r > w || y - r < 0 || y + r > h) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define SEQMAX 10001

int main(){

  int n, i, j;
  int count[SEQMAX];
  int *num1, *num2;

  scanf("%d",&n);

  num1 = malloc(sizeof(int) * n+1);
  num2 = malloc(sizeof(int) * n+1);

  for(i = 0; i <= SEQMAX; i++){
    count[i] = 0;
  }

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

  for(i = 1; i <= SEQMAX; i++){
    count[i]+=count[i-1];
  }

  for(j = 1; j <= n; j++){
    num2[count[num1[j]]] = num1[j];
    count[num1[j]]--;
    }
  
  for(i = 1; i <= n; i++){
    if(i > 1) printf(" ");
    printf("%d",num2[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17412
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //tenka1beginner 2017 a
    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        int count = 0;
        for (int i = 0; i < s.length; i++) {
            if(s[i]=='1')count++;
        }
        out.println(count);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21332
use proconio::*;
use proconio::marker::Chars;

fn main() {
    input!{
        s: Chars,
        t: Chars,
    }

    let s = s.iter().collect::<String>();
    let t = t.iter().collect::<String>();

    let mut ok = false;
    if &s == &t[0..t.len()-1] {
        ok = true;
    }

    println!("{}", if ok { "Yes" } else { "No" });
}


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

int main(){
  long long int N;
  cin >> N;
  vector<long long int> l(87);
  l.at(0)=2;
  l.at(1)=1;
  for(int i=2; i<87; i++){
    l.at(i) = l.at(i-2)+l.at(i-1);
  }
  cout << l.at(N) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int temp = N ;
		int sum =0;
		while (temp>0) {
			sum +=temp%10;
			temp/=10;
		}
		if (N%sum ==0) {
			System.out.println("Yes");
			return ;
		}
		System.out.println("No");
	}
}

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

int main(void){
  int n;
  while(true){
    cin >> n;
    if(n == 0) break;
    int sum = 0;
    while(n / 5 != 0){
      sum += n / 5;
      n = n / 5;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define N 200020
const int inf = 0x3f3f3f3f;
struct tree{
    int l, r, min, tag;
} t[N << 3];
int a[N], b[N];
int n, m;
int ls(int cur){ return cur << 1; }
int rs(int cur){ return cur << 1 | 1; }
void lazy(int cur, int k){
    t[cur].tag = k; t[cur].min = k;
}
void pushdown(int cur){
    if(!t[cur].tag) return ;
    int mid = (t[cur].l + t[cur].r) >> 1;
    lazy(ls(cur), t[cur].tag); lazy(rs(cur), t[cur].tag + mid - t[cur].l + 1); 
    t[cur].tag = 0;
    return ;
}

void build(int cur, int l, int r){
    t[cur].l = l; t[cur].r = r; t[cur].min = t[cur].tag = 0;
    if(l == r) return ;
    int mid = (l + r) >> 1;
    build(ls(cur), l, mid);
    build(rs(cur), mid + 1, r);
    return ;
}

void update(int cur, int ul, int ur, int k){
    // cout<<cur<<' '<<t[cur].l<<' '<<t[cur].r<<endl;
    pushdown(cur);
    if(t[cur].l >= ul && t[cur].r <= ur){
        lazy(cur, k); return ;
    }
    int mid = (t[cur].l + t[cur].r) >> 1;
    if(mid >= ul) update(ls(cur), ul, ur, k);
    if(mid < ur) update(rs(cur), ul, ur, k + max(0, (mid - max(t[cur].l, ul) + 1)));
    t[cur].min = min(t[ls(cur)].min, t[rs(cur)].min);
    return ;
}

int query(int cur, int ql, int qr){
    if(t[cur].l >= ql && t[cur].r <= qr) return t[cur].min;
    pushdown(cur);
    int mid = (t[cur].l + t[cur].r) >> 1;
    int res = inf;
    if(mid >= ql) res = min(res, query(ls(cur), ql, qr));
    if(mid < qr) res = min(res, query(rs(cur), ql, qr));
    return res;
}

void init(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
    return ;
}
void solve(){
    build(1, 1, m);
    for(int i = 1; i <= n; i++){
        // cout<<a[i]<<' '<<b[i]<<endl;
        int k = (a[i] == 1) ? (m + 1) : query(1, a[i] - 1, a[i] - 1) + 1;
        // cout<<k<<endl;
        update(1, a[i], b[i], k);
        if(t[1].min >= m + 1) printf("-1\n");
        else printf("%d\n", t[1].min + i);
    }
    return ;
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 21668
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N, T; cin >> N >> T;
	vector<int> c(N), t(N);
	vector<int> answer;
	for (int i = 0; i < N; ++i) {
		cin >> c[i] >> t[i];
		if (t[i] <= T) {
			answer.push_back(c[i]);
		}
	}
	if (answer.size() == 0) {
		cout << "TLE" << endl;
		return 0;
	}
	sort(answer.begin(), answer.end());
	cout << answer[0] << endl;

	cin >> N;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N,X,Y;
int A[41],B[41],C[41];
int dp[42][405][405];

signed main(){
	cin>>N>>X>>Y;
	REP(i,N){
		cin>>A[i]>>B[i]>>C[i];
	}
	REP(i,42)REP(j,405)REP(k,405){
		dp[i][j][k]=INF;
	}
	dp[0][0][0]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=400;j++){
			for(int k=0;k<=400;k++){
				if(dp[i][j][k]==INF){
					continue;
				}
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				dp[i+1][j+A[i]][k+B[i]]=min(dp[i+1][j+A[i]][k+B[i]],dp[i][j][k]+C[i]);
			}
		}
	}
	int ans=INF;
	for(int i=1;i<=400;i++){
		for(int j=1;j<=400;j++){
			if(i*Y==j*X){
				ans=min(ans,dp[N][i][j]);
			}
		}
	}
	if(ans==INF){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 54016
s = input()
x = s.split()
y = [0,0,0,0]
i = 0
for v in x:
    y[i] = int(v)
    i = i + 1
a1 = y[0] * y[1]
a2 = y[2] * y[3]
if a1 >= a2:
    print(a1)
else:
    print(a2)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

	int n = 0;			//1???????????´??°???????´????????????°
	int i = 0;			//for????????????????????????????????°
	int j = 0;
	int k = 0;			//???????????????????????????????????°
	long int sum = 0;		//????¨????
	scanf("%d", &n);

	int num[n];			//n??????????´??????????int????????????num

	for(i = 0 ; i < n ; i++){
		scanf("%d",&num[i]);	//n?????´??°???????????????
		sum += num[i];			//????¨????
	}

	/*?????????????????????*/
	for(i = 0 ; i < n ; i++){
		for(j = 0; j+1 < n; j++){

			if(num[j] < num[j+1]){
				k = num[j];
				num[j] = num[j+1];
				num[j+1] = k;
			}

		}
	}

	/*????°????????????§??????????¨??????¨???*/
		printf("%d %d %ld\n",num[n-1],num[0],sum);




	return 0;
}

Measured memory_bytes: 636
/// {{{ Author: Wang, Yen-Jen
// include
#include <bits/stdc++.h>

// using
using namespace std;

// types
typedef long long ll;
typedef pair<int,int> pii;

// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))

// input
inline bool SR(int &x) {
  return scanf("%d",&x) == 1;
}

inline bool SR(ll &x) {
  return scanf("%lld",&x) == 1;
}

inline bool SR(double &x) {
  return scanf("%lf",&x) == 1;
}

inline bool SR(char *s) {
  return scanf("%s",s) == 1;
}

inline bool RI() {
  return true;
}

template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
  return SR(x) && RI(tail...);
}

// output
inline void SP(const int x) {
  printf("%d",x);
}

inline void SP(const ll x) {
  printf("%lld",x);
}

inline void SP(const double x) {
  printf("%.16lf",x);
}

inline void SP(const char *s) {
  printf("%s",s);
}

inline void PL() {
  puts("");
}

template<typename I , typename... T> inline void PL(const I x , const T... tail) {
  SP(x);
  if(sizeof...(tail)) putchar(' ');
  PL(tail...);
}

// debug
#define WangYenJen

#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
  cerr << s << " = " << x << endl;
}

template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
  int c = 0;
  while(*s != ',' || c != 0) {
    if(*s == '(' || *s == '[' || *s == '{') c++;
    if(*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << " = " << x << " , ";
  _DOING(s + 1 , tail...);
}

#define DEBUG(...) \
do {\
  fprintf(stderr , "%s: Line %d - ",__PRETTY_FUNCTION__,__LINE__);\
  _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);

#else
#define DEBUG(...)

#endif

// constant number
const int INF = 0x3f3f3f3f;
const ll INF64 = 0x3f3f3f3f3f3f3f3fll;

// random function
inline int RAND() {
  static int x = 880301;
  return (x = x * 0xdefaced + 1) % 0x7fffffff;
}
/// }}}

const int MAX_N = 100000 + 7;

int A[MAX_N];

int main() {
  int N, M;
  RI(N, M);
  REP(i, M) RI(A[i]);
  if (M == 1) {
    PL(A[0]);
    if (N == 1) {
      PL(1);
      PL(1);
    }
    else {
      PL(2);
      PL(N - 1, 1);
    }
  }
  else {
    int odd_cnt = 0;
    REP(i, M) odd_cnt += A[i] % 2;
    if (odd_cnt > 2) PL("Impossible");
    else {
      queue<int> que;
      que.push(0);
      que.push(M - 1);
      REP(i, M) {
        if (A[i] % 2) {
          swap(A[i], A[que.front()]);
          que.pop();
          if (que.empty()) break;
        }
      }
      REP(i, M) printf("%d%c", A[i], " \n"[i == M - 1]);
      if (A[0] > 1) {
        PL(M);
        printf("%d ", A[0] - 1);
      }
      else PL(M - 1);
      REP1(i, 1, M - 1) printf("%d%c", A[i] + (i == M - 1), " \n"[i == M - 1]);
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a==b){
printf("Draw\n");
}
 else if(a==1){
printf("Alice\n");
}

else if(b==1){
printf("Bob\n");
}
else if(a>b){
printf("Alice\n");
}
else{
printf("Bob\n");
}

return 0;}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int M = input.nextInt();
        
        if (N == M){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }

        
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (st.count(x)) {
            cout << "NO\n";
            return 0;
        }
        st.insert(x);
    }
    cout << "YES\n";
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, N) for(int i = 0; i < N; i++)

using namespace std;

int main()
{
  int N, K; cin >> N >> K;
  vector<int> h(N);
  REP(i, N) cin >> h[i];
  sort(h.begin(), h.end());
  
  int ans = 1000000000;
  for (int i = 0; i <= N - K; i++) {
  	ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int x, y;
    while (1) {
		cin>>x>>y;
		if(x==0&&y==0)break;
		if(x>y)cout<<y<<' '<<x<<endl;
		else   cout<<x<<' '<<y<<endl;
	}
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
typedef long long lli;
 
string s;
string t = "2018";
 
int main(){
	cin >> s;
  	cout << t;
  	for(lli i = 4;i < s.size();i++){
		cout << s[i];
    }
  	cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n,step,a[100],end;
	int i,j,temp;

	while (1) {
		scanf("%d",&n);
		if (n ==0)break;
		step = 0;
		for (i = 0; i < n; i++)
			scanf("%d",&a[i]);
		for (end = n-1; end > 0; end--) {
			for (j = 0; j < end; j++) {
				if (a[j+1] < a[j]) {
					temp = a[j];
					a[j] = a[j+1];
					a[j+1] = temp;
					step++;
				}
			}
		}
		printf("%d\n",step);
	}
	return 0;
}

Measured memory_bytes: 600
N = int(input())
v = list(map(int, input().split()))
limit = 10 ** 18

answer = 1
if 0 in v:
  answer = 0
else:
  for i in v:
    answer = answer * i
    if answer <= limit:
      continue
    else:
      answer = -1
      break
print(answer)

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



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    
    int a,b;
    cin>>a>>b;
    if(a<b){
        for(int i=0;i<b;i++){
            cout << a;
        }
    }
    else {
        for(int i=0;i<a;i++){
            cout << b;
        }
    }
    cout << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n,m,R;
    cin>>n>>m>>R;
    vector<int> v;
    for(int i=0;i<R;i++){
        int r;
        cin>>r;
        v.push_back(r);
    }
    ll d[201][201]={};
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i!=j) d[i][j]=1e18;
        }
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        d[a][b]=d[b][a]=c;
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=1e18;
    sort(v.begin(),v.end());
    do{
        ll Kyori=0;
        for(int i=1;i<R;i++){
            Kyori+=d[v[i-1]][v[i]];
        }
        ans=min(ans,Kyori);
    }while(next_permutation(v.begin(), v.end()));
    cout<<ans<<endl;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

const int N = 1005, mod = 1e9+7;
int fac[N], ifac[N], dp[25][N];

int Pow(int a, int b)
{
	int x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b&1) x = (ll)x * a % mod;
		a = (ll)a * a % mod;
	}
	return x;
}

int comb(int n, int k)
{
	return (ll)fac[n] * ifac[n-k] % mod * ifac[k] % mod;
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

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

	fac[0] = ifac[0] = 1;
	for (int i = 1; i < N; ++i)
	{
		fac[i] = (ll)fac[i-1] * i % mod;
		ifac[i] = Pow(fac[i], mod-2);
	}

	int n, k;
	cin >> n >> k;
	vector<int> a(k);
	for (auto &i : a) cin >> i;

	dp[0][0] = 1;
	for (int d = 0; d < k; ++d)
		for (int i = 0; i <= n; ++i)
			for (int j = 0; i+j <= n && j <= a[d]; ++j)
				dp[d+1][i+j] = (dp[d+1][i+j] + (ll)dp[d][i] * comb(n-i, j) % mod * comb(n-j, a[d]-j)) % mod;

	cout << dp[k][n] << "\n";

	return 0;
}


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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

string S;
signed main() {
    cin >> S;
    rep(i, S.length()) {
        if (((~i & 1) && (S[i] == 'L')) || ((i & 1) && (S[i] == 'R'))) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>

using namespace std;

#define ll long long
// #define rep(i, n) for (ll i = 1; i < (n+1); i++)
// #define rep(j, n) for (ll j = 1; j < (n+1); j++)
// #define rep(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    string S;
    cin >> S;
    if (S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}



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

int main(){
  string S;
  cin >> S;
  int L = S.size();
  
  string ans = "AC";
  if(S[0]!='A') ans = "WA";
  
  int cnt = 0;
  rep(i,1,L){
    if(isupper(S[i])){
      if(i==1 or i==L-1 or S[i]!='C')  ans = "WA";
      cnt++;
    }
  }
    if(cnt != 1) ans = "WA";
  
    cout << ans << endl;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n m ->
  let vs = Array.init m (fun i ->
    Scanf.scanf " %d %d" (fun p y->(y,p,i))
  ) in
  Array.sort compare vs;
  let qs = Array.make m "" in
  let ns = Array.make n 0 in
  Array.iter (fun (y,p,i) ->
    let n = ns.(p-1)+1 in
    ns.(p-1)<-n;
    qs.(i)<-Printf.sprintf "%06d%06d\n" p n
  ) vs;
  Array.iter (Printf.printf "%s") qs
)


Measured memory_bytes: 12416
//
//  main.cpp
//  051_B_Sum_of_Three_Integers2
//
//  Created by tolemy on 2019/07/15.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    
    
    //入力の受け取り
    int k, s = 0;
    cin >> k >> s;
    
    
    //回答方針：2分探索を使用
    //３重ループにすると、計算量がO(k^3)となり、かなり遅い
    //問題を変形する
    //x + y + z = k ⇄ y + z = k - x
    //k - xを先にリスト化しておいて、y, zの２重ループ内で検索する。
    //この結果、計算量はO(k^2 * logk)となる。
    
    //2分探索用のリストを作成
    vector<int> answer;
    
    for(int x = k;x>=0; x--)
    {
        answer.push_back(s - x);
    }
    
    int count = 0;
    for(int y = 0;y <= k; y++)
    {
        for(int z = 0;z <= k; z++)
        {
            if(binary_search(answer.begin(), answer.end(), y + z)) count++;
        }
    }
    
    cout << count;
    
    return 0;
}


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

int vis[1005][1005];

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  queue<array<int, 3>> q;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (c == '#') {
        q.push({i, j, 0});
      }
    }
  }
  int sol = 0;
  while (q.size()) {
    int x = q.front()[0];
    int y = q.front()[1];
    int z = q.front()[2];
    q.pop();
    if (!x || !y || x > n || y > m) continue;
    if (vis[x][y]) continue;
    q.push({x + 1, y, z + 1});
    q.push({x - 1, y, z + 1});
    q.push({x, y + 1, z + 1});
    q.push({x, y - 1, z + 1});
    vis[x][y] = 1;
    sol = z;
  }
  cout << sol << '\n';
}


Measured memory_bytes: 53832
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
 
void solve(){
  int n,k; cin >>n >>k;
  string s; cin >>s;
  int cnt=0;
  for(int i=0; i<n-1; i++){
    if(s[i]!=s[i+1]) cnt++;
  }
  if(cnt%2){    
    if(k<=cnt/2) cout <<n-1-cnt+2*k;
    else cout <<n-1;
  }
  else{
    k=min(cnt/2,k);
    cout <<n-1-cnt+2*k;
  }
}

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

Measured memory_bytes: 3740