akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()) cout<<x[i]<<" "; cout<<endl;

#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)

#define tc() int tcase; cin >> tcase ; rep(tc,1,tcase+1)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair

// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }

#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);

ll gcd(ll a,ll b){ return ((b==0)? a:gcd(b,a%b) ); }
#define PI acos(-1)

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

    vi sol(2*n);
    sol[0] = 1;
    int cur = 1;
    rep(i,1,2*n)
    {
        if(s[i] ==s[i-1])
            cur*= -1;
        sol[i] = cur;
    }

    if(s[0] == 'W')
    {
        cout<<0;
        exit(0);
    }

    ll cnt =0;
    ll ans =1;
    int f=0;
    rep(i,0,2*n)
    {
        if(sol[i] == 1)
            cnt++;
        else
        {
            ans = (ans*cnt)%MOD;
            cnt--;
        }
        if(cnt < 0)
            f=1;
    }

    if(f || cnt!= 0)
    {
        cout<<0;
        exit(0);
    }

    ll fac = 1;
    for(ll i=2;i<=n;i++)
        fac = (fac*i)%MOD;

    ans = (ans*fac)%MOD;
    cout<<ans;
}



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

int main() {
	int a, b;
	char op;
	cin >> a >> op >> b;
	while(op != '?') {
	if(op == '+') {
		cout << a + b << endl;
	}
	if(op == '-') {
		cout << a - b << endl;
	}
	if(op == '*') {
		cout << a * b << endl;
	}
	if(op == '/') {
		cout << a / b << endl;
	}
	cin >> a >> op >> b;
	}
}


Measured memory_bytes: 3100
n,k=int(input()),1
while k*2<=n:k*=2
p=print
if n==k:p("No");exit()
p("Yes",v:=n+1,3)
i=2
while i<n:p(1,i,i,i+1,1,v+i,v+i,n+i);i+=2
if~n&1:p(n,n+k+1,n+n,n^k)

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    for (;;) {
        c -= b;
        if (c <= 0) {
            puts("Yes");
            return 0;
        }
        a -= d;
        if (a <= 0) {
            puts("No");
            return 0;
        }
    }
}

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

#define nl                 "\n"
#define ll                 long long
#define pb                 push_back
#define pf                 push_front
#define np                 next_permutation
#define pp                 prev_permutation
#define sqr(x)             ((x)*(x))
#define pi                 acos(-1)
#define setprecision(x)    fixed<<setprecision((int)(x))
#define mem1(x)            memset(x,0,sizeof(x))
#define mem2(x)            memset(x,-1,sizeof(x))
#define all(x)             (x).begin(),(x).end()
#define sort1(x)           sort(all(x))
#define csort(x,c)         sort(all(x),c)
#define rsort(x)           sort(x.rbegin(),x.rend())
#define rep(i,n,m)         for(int i=(int)(n); i<(int)(m); i++)

//typedef map<int,int> mapii;
//typedef map<string,int> mapsi;
//typedef map<int,string> mapis;
//typedef vector<int> vi;
//typedef vector<vectori> v2d;
//typedef vector<long long> vll;


using namespace std;
void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int i=0,j=n-1,sum1=0,sum2=0;
    while(i<=j)
    {
        if(sum1<=sum2)
        {
            sum1+=a[i];
            i++;
        }
        else
        {
            sum2+=a[j];
            j--;
        }
    }
    cout<<abs(sum1-sum2)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int t; cin>>t; while(t--){solve();}
    solve();
    return 0;
}


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

int main()
{
	char a[2000],b[2000],c[2000];
	scanf("%s %s %s", a, b, c);
	int al,bl,cl;
	al=strlen(a);
		bl=strlen(b);
			cl=strlen(c);
			
	if(a[al-1]==b[0] && b[bl-1]==c[0]) printf("YES");
	else printf("NO");
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   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 MAX =200005;
const int MOD =1000000007;

signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl;
}

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

const ll mod = 1e9 + 7;
ll n, a, b, c, d;
ll dp[1010][1010];
ll fact[1010], fact_inv[1010], inv[1010];

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x * x % mod, n / 2);
    if(n & 1) res = res * x % mod;
    return res;
}

long long combination(long long n, long long k){
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod;
}

int main(){
    cin >> n >> a >> b >> c >> d;
    
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < 1010; i++) dp[i][0] = 1;

    fact[0] = fact_inv[0] = 1;
    for(int i = 1; i < 1010; i++){
        inv[i] = mod_pow(i, mod - 2);
        fact[i] = fact[i - 1] * i % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }

    for(int i = a; i <= b; i++){
        for(int j = 0; j <= n; j++){
            if(dp[i][j] == 0) continue;
            if(j != 0) (dp[i + 1][j] += dp[i][j]) %= mod;
            ll p = 1;            
            for(int k = 1; k <= d; k++){
                if(j + i * k > n) break;
                p = p * combination(n - j - i * (k - 1), i) % mod * inv[k] % mod;
                if(c <= k && k <= d){
                    (dp[i + 1][j + i * k] += dp[i][j] * p % mod) %= mod;
                }
            }
        }
    }
    cout << dp[b + 1][n] << endl;
}

Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	
	ll ans = 1000-N % 1000;
	if (ans == 1000) {
		ans = 0;
	}
	std::cout << ans << endl;

	return 0;
}


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

using ll=long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    
    bool flag=true;
    int i=1;
    while(flag){
        if(pow(2,i)>n){
            i--;
            flag=false;
            continue;
        }
        i++;
    }
    
    cout<<pow(2,i)<<endl;
    return 0;
}

Measured memory_bytes: 4084
#include<stdio.h>
int main(){
  int n,m,id,i,j,l;
  char c;
  while(scanf("%d %d",&n,&m),n||m){
    int w[110]={0};
    w[n]=-1;
    while(m--){
      scanf(" %c",&c);
      if(c=='s'){
	scanf("%d %d",&id,&l);
	id++;
	for(i=0;i<n;i++){
	  if(w[i])continue;
	  for(j=0;w[i+j]==0;j++);
	  if(j<l){
	    i+=j;
	    continue;
	  }
	  printf("%d\n",i);
	  for(j=0;j<l;j++)w[i+j]=id;
	  break;
	}
	if(i>=n)printf("impossible\n");
      }
      else{
	scanf("%d",&id);
	id++;
	for(i=0;w[i]-id;i++);
	for(;w[i]==id;i++)w[i]=0;
      }
      //for(i=0;i<n;i++)printf("%d",w[i]);printf("\n");
    }
    printf("END\n");
  }
  return 0;
}

Measured memory_bytes: 612
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [K - i for i in A]
dpB = [0]*N
dpA = [0]*N
# dpA = [A[i+1] - A[i] for i in range(N-1)]
dpA[0] = A[0] + B[N-1]
dpB[0] = B[0] + A[N-1]

for i in range(N):
    if i>0:
        dpA[i] = A[i] - A[i-1]
for i in range(N):
    if i>0:
        dpB[i] = A[i] - A[i-1]
MAXA = max(dpA)
MAXB = max(dpB)
SUMA = sum(dpA) - MAXA
SUMB = sum(dpB) - MAXB
# print(dpA)
# print(dpB)
# print(SUMA)
# print(SUMB)
print(min(SUMA, SUMB))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x; cin >> x;
  int ans;
  if(x>=400 && x<600) ans = 8;
  else if(x>=600 && x<800) ans = 7;
  else if(x>=800 && x<1000) ans = 6;
  else if(x>=1000 && x<1200) ans = 5;
  else if(x>=1200 && x<1400) ans = 4;
  else if(x>=1400 && x<1600) ans = 3;
  else if(x>=1600 && x<1800) ans = 2;
  else ans = 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
//https://atcoder.jp/contests/abc117/tasks/abc117_c
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};


int main(){
    int N,M;
    cin>>N>>M;
    N=min(N,M);
    vector<LL> X(M),Y;
    cin>>X;
    sort(ALL(X));
    for(int i:range(M-1)){
        Y.push_back(X[i+1]-X[i]);
    }
    sort(ALL(Y));
    LL ret=0;
    for(int i:range(M-N)){
        ret+=Y[i];
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n,k;
    string s,output;
    cin >> n;
    cin >> s;
    cin >> k;

    for(int i = 0;i < n;i++){
        if(s[i] == s[k-1])output += s[i];
        else output += "*";
    }
  
  	cout << output << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,ans=0;
vp p1,p2,p;
vl used(100000,0);
string s;
ll par[110000];//親の頂点
ll size[110000];
ll parx[110000];//親の頂点
ll sizex[110000];
ll pary[110000];//親の頂点
ll sizey[110000];
ll root(ll x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
}
bool same(ll x,ll y){
    return root(x)==root(y);
}
void unite(ll x,ll y){
    if(same(x,y))return;
    size[root(y)]+=size[root(x)];
  par[root(x)]=y;
}
ll rootx(ll x){
    if(parx[x]==x)return x;
    return parx[x]=rootx(parx[x]);
}
bool samex(ll x,ll y){
    return rootx(x)==rootx(y);
}
void unitex(ll x,ll y){
    if(samex(x,y))return;
    sizex[rootx(y)]+=sizex[rootx(x)];
  parx[rootx(x)]=y;
}
ll rooty(ll x){
    if(pary[x]==x)return x;
    return pary[x]=rooty(pary[x]);
}
bool samey(ll x,ll y){
    return rooty(x)==rooty(y);
}
void unitey(ll x,ll y){
    if(samey(x,y))return;
    sizey[rooty(y)]+=sizey[rooty(x)];
  pary[rooty(x)]=y;
}
ll solve(){
	//cout<<n<<endl;
    rep(i,n-1){
        if(p1[i].first==p1[i+1].first){
            a=p1[i].second;
            b=p1[i+1].second;
            unite(a,b);
            unitey(p[a].second,p[b].second);
            //cout<<"R"<<p[a].first<<" "<<p[b].first<<endl;
            //cout<<"O"<<p[a].second<<" "<<p[b].second<<" "<<sizey[rooty(p[a].second)]<<endl;
        }
    }
 
    rep(i,n-1){
        if(p2[i].first==p2[i+1].first){
            a=p2[i].second;
            b=p2[i+1].second;
            unite(a,b);
            unitex(p[a].first,p[b].first);
            //cout<<p[a].first<<" "<<p[b].first<<endl;
        }
    }
 
    rep(i,n){
        if(used[root(i)]==0){
            ans+=sizex[rootx(p[i].first)]*sizey[rooty(p[i].second)]-size[root(i)];
            //cout<<sizex[rootx(p[i].first)]<<" "<<sizey[rooty(p[i].second)]<<" "<<size[root(i)];
            used[root(i)]=1;
        }
    }
 
    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<110000;i++){//初期化
        par[i]=i;
        size[i]=1;
        parx[i]=i;
        sizex[i]=1;
        pary[i]=i;
        sizey[i]=1;
    }
    rep(i,n){
        cin>>a>>b;
        p1.emplace_back(a,i);
        p2.emplace_back(b,i);
        p.emplace_back(a,b);
    }
    sort(all(p1));
    sort(all(p2));
    cout<<solve()<<endl;
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define mp(a, b) make_pair(a, b)
#define lowbit(x) ((x) & -(x))
typedef pair<int, int> pii;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
	int n;
	cin >> n;
	cout << ((n + 1) >> 1) << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
ans=0
leftover=0
for i in range(N):
  if q[i]+leftover>p[i]:
    ans+=p[i]
    leftover=min(q[i]+leftover-p[i],q[i])
  else:
    ans+=q[i]+leftover
    leftover=0
ans+=min(p[N],leftover)
print(ans)

Measured memory_bytes: 18476
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

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;
}

int main(void) {
    int N, K;
    cin >> N >> K;

    map<int, ll> m;
    for (int i = 1; i <= N; i++) {
        m[i % K]++;
    }

    ll ans = m[0] * m[0] * m[0];
    if (K % 2 == 0) {
        ans += m[K / 2] * m[K / 2] * m[K / 2];
    }

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


Measured memory_bytes: 6528
#include <stdio.h>

int main()
{
    int A, B, C, area;
    
    scanf ("%d%d%d", &A, &B, &C);
    
    int maior = A;
    
    if (A > B && A > C)
        area = (B*C)/2;
        
    else if (A < B && B > C)
        area = (A*C)/2;
    
    else if (A < C && B < C)
        area = (A*B)/2;
        
    printf ("%d", area);
    

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int main(){
	string s;
	cin >> s;
	bool flag=0,flag1=0;
	for(int i=0;i<s.size();i++){
		if(flag){
			if(s[i]=='A'){
				flag = 1;
			}
			if(s[i]=='C'){
				flag1 = 1;
			}
		}
		if(s[i]=='A'){
			flag = 1;
		}
		if(s[i]!='A'){
			flag = 0;
		}
	}
	if(flag1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

    char in[5];
    cin>>in;
    Yes((in[0]==in[1] && in[1]==in[2])||(in[1]==in[2] && in[2]==in[3]));
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = list(input())
a = 0 # 予選通過人数
b = 0 # 海外
for i in range(N):
    ans = 'No'
    if S[i] == 'a':
        if a < A + B:
            ans = 'Yes'
            a += 1
    elif S[i] == 'b':
        if a < A + B and b < B:
            ans = 'Yes'
            a += 1
            b += 1
    print(ans)

Measured memory_bytes: 9924
n = int(input())
a = [ int(x) for x in input().split() ]
b = [ int(x) for x in input().split() ]
c = [ int(x) for x in input().split() ]

k = 0
i = -1

for e in a:
    k += b[e - 1]
    if i == e-1:
        k += c[i - 1]

    i = e

print(k)


Measured memory_bytes: 9088
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MaxN = 1e5 + 5;
ll cnt1[MaxN + 5],cnt2[MaxN + 5],n;
int a[MaxN],b[MaxN],c[MaxN];

int cmp1(int x,int y){
	return x < y;
}

int cmp(int x, int y){
	return x > y;
}

int main()
{
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
	for(int i = 1; i <= n; i++) scanf("%d",&b[i]);
	for(int i = 1; i <= n; i++) scanf("%d",&c[i]);
	sort(a + 1,a + n + 1,cmp1);
	sort(b + 1,b + n + 1,cmp1);
	sort(c + 1,c + n + 1,cmp);
	ll p = 1;
	for(int i = 1;i <= n; i++){
		while(p <= n){
			if(a[p] < b[i]) p++;
		    else break;
		}
		cnt1[i] = p - 1;
	}
	p = 1;
	for(int i = n;i >= 1; i--){
		while(p <= n){
			if(c[p] > b[i]) p++;
			else break;
		}
		cnt2[i] = p - 1;
	}	
	long long sum = 0;
	for(int i = 1; i <= n;i++){
		sum += cnt1[i] * cnt2[i];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int L=2000010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
bitset<L>S;
int sum,n;
int main()
{
	int x;
	file();
	read(n);
	S[1000000]=1;
	For(i,1,n)
	{
		read(x);
		S=(S<<x)|(S>>x);
		sum+=x;
	}
	For(i,1000000,2000000)if(S[i]){printf("%d\n",(i-1000000+sum)/2);exit(0);}
	return 0;
}


Measured memory_bytes: 1536
using System;
public class Hello{
    public static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        int[] num = new int[input.Length];
        int max = 0;
        int sum = 0;
        
        for(int x = 0;x < input.Length;x++){
            num[x] = int.Parse(input[x]);
            if(num[x] > max){
                max = num[x];
            }
            sum = sum + num[x];
        }
        
        Console.WriteLine(sum - max);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 2005
#define MOD 99994711
#define ba 47
//define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M;
int a[105];
vector<int> v,ans[2];
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= M ; ++i) read(a[i]);
    for(int i = 1 ; i <= M ; ++i) {
	if(a[i] & 1) v.pb(a[i]);
    }
    if(v.size() > 2) {puts("Impossible");return;}
    if(v.size()) {
	int t = v.back();
	ans[0].pb(t);
	v.pop_back();
    }
    for(int i = 1 ; i <= M ; ++i) {
	if(a[i] % 2 == 0) {
	    ans[0].pb(a[i]);
	}
    }
    if(v.size()) {
	int t = v.back();
	ans[0].pb(t);
	v.pop_back();
    }
    
    for(int i = 0 ; i < ans[0].size() ; ++i) {
	if(i == 0) {
	    if(ans[0][i] != 1) ans[1].pb(ans[0][i] - 1);
	}
	else if(i == ans[0].size() - 1){
	    ans[1].pb(ans[0][i] + 1);
	}
	else ans[1].pb(ans[0][i]);
    }
    if(ans[0].size() == 1) ans[1].pb(1);
    for(auto t : ans[0]) {
	out(t);space;
	
    }
    enter;
    out(ans[1].size());enter;
    for(auto t : ans[1]) {
	out(t);space;
    }
    enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int modi = 1e9+7;

void solve(){
	ll n,k;
	cin >> n >> k;
	ll maxbit = 0;
	ll ck= k;
	while(ck>0){
		
		maxbit++;
		ck>>=1;
	}
	ll a[n];
	map<ll,ll> cnt;
	ll sum = 0;
	for(ll i =0;i<n;i++){
		cin >> a[i];
		ll ca = a[i];
		ll bit =0;
		while(ca>0){
			if(ca&1)
				cnt[bit]++;
			bit++;
			ca>>=1;
		}
		sum+=a[i];
		// maxbit = max(maxbit,bit);
	}
	vvl dp(maxbit+1,vl(2,-1));

	function<ll(ll,ll)> digit_dp =[&](ll bit, ll smaller){
		// cout << bit << endl;
		if(bit == -1){
			return sum;
		}

		if(dp[bit][smaller]!=-1){
			return dp[bit][smaller];
		}
		ll &ans = dp[bit][smaller];
		ans = 0;
		ll limit=0;
		if(smaller)
			limit=1;
		if(limit == 1){
			ans = max(ans,max(digit_dp(bit-1,1),(1ll<<(bit))*(-2*cnt[bit]+ n) + digit_dp(bit-1,1)));
		}
		else{
			// ll i = 0;
			if((k>>bit)&1){
				ans = max(ans,digit_dp(bit-1,1));
				ans= max(ans,(1ll<<(bit))*(-2*cnt[bit] +n)+digit_dp(bit-1,0));

			}
			else{
				ans = max(ans,digit_dp(bit-1,0));
			}
		}
		return ans;
	};
	ll ans = digit_dp(maxbit-1,0);
	dbg(dp);
	cout << ans << endl;

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> l = new ArrayList<Integer>();
		while(sc.hasNext()){
			String[] s = sc.next().split(",");
			double w = Double.parseDouble(s[1]);
			double h = Double.parseDouble(s[2]);
			if(w/(h*h)>=25)l.add(Integer.parseInt(s[0]));
		}
		if(l.isEmpty())System.out.println("該当なし");
		else for(Integer i:l)System.out.println(i);
	}
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;

int N;
vector<int> prime;
bool used[MAX_N];

int p[MAX_N];
int dp[MAX_N][1<<3];

signed main()
{
  FOR(n,2,MAX_N) {
    if(!used[n]) {
      prime.push_back(n);
      for(int i = 2; i*n < MAX_N; i++) {
        used[i*n] = true;
      }
    }
  }
  cin >> N;

  FOR(nnn,2,N+1) {
    int n = 0;
    int nn = nnn;
    while(nn > 1) {
      while(nn%prime[n] == 0) {
        p[n]++;
        nn /= prime[n];
      }
      n++;
    }
  }

  //2,4,4
  dp[0][0] = 1;
  REP(n,N+1) {
    REP(j,(1<<3)) {
      //使わない
      dp[n+1][j] += dp[n][j];
      if(p[n]>=2 && (j&1) == 0) {
        dp[n+1][j|1] += dp[n][j];
      }
      if(p[n]>=4) {
        if((j&2) == 0) {
          dp[n+1][j|2] += dp[n][j];
        } else if((j&4) == 0) {
          dp[n+1][j|4] += dp[n][j];
        }
      }
    }
  }
  int ans = dp[N+1][7];

  //14,4
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  REP(n,N+1) {
    REP(j,(1<<2)) {
      //使わない
      dp[n+1][j] += dp[n][j];
      if(p[n]>=14 && (j&1) == 0) {
        dp[n+1][j|1] += dp[n][j];
      }
      if(p[n]>=4) {
        if((j&2) == 0) {
          dp[n+1][j|2] += dp[n][j];
        }
      }
    }
  }
  ans += dp[N+1][3];

  //24,2
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  REP(n,N+1) {
    REP(j,(1<<2)) {
      //使わない
      dp[n+1][j] += dp[n][j];
      if(p[n]>=24 && (j&1) == 0) {
        dp[n+1][j|1] += dp[n][j];
      }
      if(p[n]>=2) {
        if((j&2) == 0) {
          dp[n+1][j|2] += dp[n][j];
        }
      }
    }
  }
  ans += dp[N+1][3];

  //74
  REP(n,N+1) {
    if(p[n] >= 74) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int[][] memo;

	public static int hoge(int current, int n, String last) {
		return 0;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		long a,b,c,d,e,n,ans = 0;
		String str;
		str = bf.readLine();
		n = Long.parseLong(str);
		str = bf.readLine();
		a = Long.parseLong(str);
		long temp = a;
		str = bf.readLine();
		b = Long.parseLong(str);
		if(temp > b) {
			temp = b;
		}
		str = bf.readLine();
		c = Long.parseLong(str);
		if(temp > c) {
			temp = c;
		}
		str = bf.readLine();
		d = Long.parseLong(str);
		if(temp > d) {
			temp = d;
		}
		str = bf.readLine();
		e = Long.parseLong(str);
		if(temp > e) {
			temp = e;
		}
		ans = n/temp + 4;
		if(n%temp != 0) {
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
from collections import deque

n = int(input())
color = [0] * n
watch = [False] * n
tree = [[] for _ in range(n)]

for _ in range(n-1):
    a, b, w = map(int, input().split())
    tree[a-1].append([b-1, w])
    tree[b-1].append([a-1, w])

q = deque()
q.append(0)
watch[0] = True

while q:
    i = q.popleft()
    for x,y in tree[i]:
        if watch[x]: continue
        watch[x] = True
        if y % 2 == 0:
            color[x] = color[i]
        else:
            color[x] = color[i]^1
        q.append(x)

for c in color:
    print(c)


Measured memory_bytes: 84128
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int MOD=1000000007;
	int n,m;
	cin>>n>>m;
	vi dp(n+2);
	dp[0]=1;
	vi in(n);
	rep(i,m){
		int a;cin>>a;
		in[a]=1;
	}
	rep(i,n)if(!in[i]){
		rep(j,2)(dp[i+j+1]+=dp[i])%=MOD;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	const int p = 31;
	vector<long long> p_pow(sz(s));
	p_pow[0] = 1;
	for (int i = 1; i < sz(p_pow); i++)
		p_pow[i] = p_pow[i - 1] * p;
	vector<long long> h(sz(s));
	for (int i = 0; i < sz(s); i++)
	{
		h[i] = (s[i] - 'a' + 1LL) * p_pow[i];
		if (i)
			h[i] += h[i - 1];
	}

	int res = 0;
	int l = 1, r = sz(s) / 2;
	//for (int l = 1; l <= sz(s) / 2; l++)
	while (l <= r)
	{
		int mid = l + (r - l) / 2;
		map<long long, int> cnt;
		bool found = false;
		for (int i = 0; i + mid <= sz(s); i++)
		{
			long long cur_h = h[i + mid - 1];
			if (i)
				cur_h -= h[i - 1];
			long long curhash = cur_h * p_pow[sz(s) - mid - i];
			if (cnt.find(curhash) == cnt.end())
			{
				cnt[curhash] = i;
			}
			else
			{
				if (cnt[curhash] + mid <= i)
				{
					res = mid;
					found = true;
					break;
				}
			}
		}
		if (found)
		{
			res = max(res, mid);
			l = mid + 1;
		}
		else
			r = mid - 1;

	}
	cout << res;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	int k,s;
	scanf("%d%d",&k,&s);
	int cnt=0;
	for(int x=0;x<=k;++x)
	{
		for(int y=0;y<=k;++y){
			int z;
			z=s-(x+y);
			if((z<=k)&&(z>=0))
			++cnt;
		}
	
	}
	printf("%d",cnt);
}

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

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
        return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if (x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        #rnkが大きい方に結合
        elif (self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
        # rnkが同じ（深さに差がない場合）は1増やす
        if(self.rnk[x] == self.rnk[y]):
            self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

uni=UnionFind(N)

for i in range(M):
    a,b=map(int, input().split())
    a-=1
    b-=1
    uni.Unite(a,b)

ans=0
for i in range(N):
    ans=max(ans, uni.Count(i))

print(ans)


Measured memory_bytes: 14504
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

vint v(1500010);

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		rep(i,1500010) v[i]=0;
		vint h(n);
		rep(i,n){
			cin>>h[i];
		}
		rep(i,n){
			ll S=0;
			for(int j=i;j<n;j++){
				S+=h[j];
				v[S]++;
			}
		}
		vint w(m);
		rep(i,m){
			cin>>w[i];
		}
		ll ans=0;
		rep(i,m){
			ll S=0;
			for(int j=i;j<m;j++){
				S+=w[j];
				//cout<<"S v[S] "<<S<<" "<<v[S]<<endl;
				ans+=v[S];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

const ll MX = 1e18;
 
int main(){
  int n;
  cin >> n;
  ll ans = 1;
  bool x = false;
 
  rep(i, n){
    ll a;
    cin >> a;
    
    if(a == 0){
      cout << 0 << endl;
      return 0;
    }
    if(x || MX / ans < a){
      x = true;
    }
    ans *= a;
  }
  if(x) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def main():
    s = srl()
    print "A" + s[1][0] + "C"


if __name__ == '__main__':
    main()


Measured memory_bytes: 2572
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int min = (int) 1e9;
		for(int i=1;i<N;i++){
			int a = i;
			int b = N - i;
			int x = 0;
			while(a != 0){
				x += a % 10;
				a /= 10;
			}
			while(b != 0){
				x += b % 10;
				b /= 10;
			}
			min = Math.Min(min,x);
		}
		Console.WriteLine(min);
		
		
	}
	int N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	int ans=1000000007;
	cin>>a>>b;
	for (int i=0;i<a.size()-b.size()+1;i++)
	{
		int need=0;
		for (int n=0;n<b.size();n++)
		{
			if (a[i+n]!=b[n])
				need++;
		}
		ans=min(ans,need);
	}
	cout<<ans<<endl;
	return 0;
}


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



int main() {

    int x,y;
    cin>>x>>y;
int a=0;
bool flag=false;
    for(int i=0;i<=x;i++)
        { //int j=x-i;
        a= 4*i +2*(x-i);
        if(a==y)
            flag=true;
        }
        
        
            if(flag==true)
        cout<<"Yes";
            else if(flag==false)
        cout<<"No";

        return 0;

}


Measured memory_bytes: 3636
l=[]
m=[]
s=0
for i in range(20):
    a=int(input())
    if s<10:
        l.append(a)
    else:
        m.append(a)
   
    s=s+1
    
l=sorted(l,reverse=True)
m=sorted(m,reverse=True)





print(l[0]+l[1]+l[2],m[0]+m[1]+m[2])
    


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

int main() {
    long long int N, A, B;
    cin >> N >> A >> B;
    
    long long int ans=(N/(A+B))*A;
    if(N%(A+B)<A) {
        ans += N%(A+B);
    } else {
        ans += A;
    }
    
    cout << ans << endl;


    return 0;
    
}


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

#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();



void selectionsort(long long N,long long A[]){
    long long minj,count = 0;
    REP(i,N){
        minj = i;
        REP2(j,i,N){
            if(A[j]<A[minj]){
                minj = j;
                
            }
        }
        if(A[i]!=A[minj]){
            swap(A[i],A[minj]);
            count++;
        }
    }
    REP(k,N-1){printf("%lld ",A[k]);}
    printf("%lld\n",A[N-1]);
    printf("%d\n",count);
}


int main(){
    long long n;
    scanf("%lld",&n);
    long long A[n];
    REP(i,n){scanf("%lld ",&A[i]);}
    selectionsort(n,A);

    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <cstring>

using namespace std;

bool estePalindrom(char s[])
{
    int n = strlen(s);
    if( n == 1 ){
        return true;
    }
    for( int i = 0; i <= n / 2 - 1; i++ ){
        if( s[i] != s[n - i - 1] ){
            return false;
        }
    }
    return true;
}

int main() {
    char s[100], a[100], *b;
    int n;
    cin.getline(s, 100);
    n = strlen(s);
    strcpy(a, s);
    a[n/2] = '\0';
    b = s + (n/2+1);
    if( estePalindrom(s) && estePalindrom(a) && estePalindrom(b) ){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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


int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;

  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        int total = 500 * a + 100 * b + 50 * c;
        if (total == X) cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)      cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int N = 300000 , mod = 1000000007;
int main()
{
    fastio;
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;

    if(a==b)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    ll d = abs(a-b);
    if(w>=v)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    ll u = v-w;
    if(d<=1LL*t*u)
    {
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3648
#094 B
N,M,X= map(int,input().split())
A = [int(j) for j in input().split()]
left =0
right = 0

for i in range(1,X):
    if i in A:
        left+=1
for i in range(X+1,N):
    if i in A:
        right+=1
print(min(left,right))

Measured memory_bytes: 3064
import math
A, B, R = map(int, input().split())
rad = math.radians(R)
S = A * B * math.sin(rad) / 2
C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad))
h = S / (0.5 *A)
print(S)
print(A+B+C)
print(h)


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
	if(ch=='A') return 1;
	if(ch=='C') return 2;
	if(ch=='G') return 3;
	if(ch=='T') return 4;
	else return 0;
}

long long getKey(char str[]){
	long long sum=0,p=1;
	for(int i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}
int h2(int key){
	return 1+(key%(M-1));
} 

int find(char str[]){
	long long key,h;
	key = getKey(str);
	for(int i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1;
		else if(strlen(H[h])==0) return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key,h;
	key = getKey(str);
	for(int i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int n,h;
	char str[L],com[9];
	for(int i=0;i<M;i++) H[i][0]=0; 
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}

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

int H, W;
char S[22][22];
bool s[22][22] = {false};
int ans = 0;

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

int bfs(int i,int j){
  vector<vector<int>> dist(H,vector<int>(W,-1));
  queue<pair<int,int>> que;

  int res = 0;
  que.push({i,j});
  dist[i][j] = 0;
  while(!que.empty()){
    i = que.front().first, j = que.front().second;
    res = max(res,dist[i][j]);
    que.pop();
    for(int dir = 0;dir < 4;dir++){
      int nx = i+dx[dir],ny = j+dy[dir];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W || S[nx][ny] == '#') continue;
      if(dist[nx][ny] == -1){
        dist[nx][ny] = dist[i][j] + 1;
        que.push({nx, ny});
      }
    }
  }
  return res;
}

signed main(){
  cin >> H >> W;
  rep(i,H)rep(j,W)cin >> S[i][j];
  rep(i,H)rep(j,W){
    if(S[i][j] == '.')ans = max(ans,bfs(i,j));
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  int tmp=x%100;
  if(tmp%5) tmp+=5;

  if(tmp/5>x/100) cout<<0;
  else cout<<1;
}

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

int main() {
  int N, M, X, Y;
  scanf("%d %d %d %d", &N, &M, &X, &Y);

  int x;
  int max_x = -1e9;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &x);
    if (x > max_x) max_x = x;
  }

  int y;
  int min_y = 1e9;
  for (int i = 0; i < M; ++i) {
    scanf("%d", &y);
    if (y < min_y) min_y = y;
  }

  int Z = max(max_x, X);

  if (Y > Z && min_y > Z) printf("No War\n");
  else printf("War\n");
  return 0;
}


Measured memory_bytes: 256
N = int(input())
P = [int(p) for p in input().split()]
P_sorted = sorted(P)

count = 0
for n in range(N):
    p_dif = P[n] - P_sorted[n]
    if p_dif != 0:
        count += 1
    if count > 2:
        break

if count <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064