akhauriyash/Code-Regression huggingface dataset:
N,M = map(int, input().split())

# 繋がっている点を記載する二重リストを準備する。
adj_matrix = [[0]* N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

# 点を通ったかを記録するリスト
used = [False] * N
used[0] = True


# 深さ探索を行うため再帰関数を定義する。
# 現在いる点をvとしての再帰
def dfs(v, used):
    # 再帰を繰り返してusedの中身が全てTrueになったときのみ1を返すようにする。
    if not False in used:
        return 1

    ans = 0
    for i in range(N):
        if adj_matrix[v][i] != 1:
            continue
        if used[i]:
            continue
        used[i] = True
        ans += dfs(i, used)
        used[i] = False
    # usedの中にFalseがあるとき用のreturn(再帰で用いられるようのreturn)
    return ans

print(dfs(0, used))

        



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define MAX_N 10000+5

//Begin
#define MAX_E MAX_N * MAX_N / 2 + 1
int parent[MAX_N];
int height[MAX_N];

void init(const int& n){
	for (int i = 0; i < n; ++i){
		parent[i] = i;
		height[i] = 0;
	}
}

int find(const int& x){
	return parent[x] == x ? x : parent[x] = find(parent[x]);
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (height[x] < height[y]){
		parent[x] = y;
	}
	else
	{
		parent[y] = x;
		if (height[x] == height[y]){
			++height[x];
		}
	}
}

bool same(const int& x, const int& y){
	return find(x) == find(y);
}
//End of 

struct edge{
	int u, v;
	double cost;
	edge(int u = 0, int v = 0, double cost = 0.0)
		: u(u), v(v), cost(cost) {}
	bool operator < (const edge & e2) const{
		return cost > e2.cost;
	}
};

edge es[MAX_E];
int V, E;
double kruskal()
{
	sort(es, es + E);//按照&#26435;排序
	init(V);
	double res = 0;
	for (int i = 0; i < E; ++i){
		edge e = es[i];
		if (!same(e.u, e.v)){
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}
typedef pair<int, int>ip;
ip dis[MAX_N];
int main()
{
	cin >> V >> E;
	for (int i = 0; i < V; ++i){
		cin >> dis[i].first >> dis[i].second;
	}
	double sum = 0.0;
	for (int i = 0; i < E; ++i){
		cin >> es[i].u >> es[i].v;
		--es[i].u; --es[i].v;
		int dx = dis[es[i].u].first - dis[es[i].v].first;
		int dy = dis[es[i].u].second - dis[es[i].v].second;
		es[i].cost = sqrt(dx * dx + dy * dy);
		sum += es[i].cost;
	}
	printf("%.3lf", sum - kruskal());
	return 0;
}

Measured memory_bytes: 2288
import math
A, B, H, M = map(int, input().split())
D = [(30*H) + (0.5*M), 6*M]
N = max(D) - min(D)
C = math.cos(math.radians(N))
sans = (A**2 + B**2) - (2*A*B*C)
ans = math.sqrt(sans)
print(ans)


Measured memory_bytes: 9276
import java.util.Scanner
import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val n: Int = sc.nextInt
    val words = List.fill(n+1)(sc.nextLine).slice(1, n+1)
    val acc: mutable.Set[String] = mutable.Set(words.head)

    val finalJudge: Boolean = words.slice(1, words.length).foldLeft((words.head, acc, true)) {
      case ((word, wordSet, temporarilyJudge), _) if !temporarilyJudge => (word, wordSet, temporarilyJudge)
      case ((word, wordSet, _), nextWord) if (word.last == nextWord.head) && (!wordSet.contains(nextWord)) =>
        wordSet += nextWord
        (nextWord, wordSet, true)
      case ((word, wordSet, _), _) =>
        (word, wordSet, false)
    }._3

    if (finalJudge) println("Yes")
    else println("No")
  }
}


Measured memory_bytes: 27296
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
ll l , a[500001];
int main(){
    string s;
    ll ans = 0; 
	cin >> s;
	s = " " + s;
	l = s.length() - 1;
	for(int i = 1; i <= l; i++){
        (s[i] == '<') ? (a[i + 1] = a[i] + 1) : (a[i + 1]);
    }
	for(int i=l;i>=1;i--){
        (s[i] == '>') ? (a[i] = max(a[i] , a[i + 1] + 1)) : (a[i]);
    }
	for(int i = 1; i <= l + 1; i++){
        ans+=a[i];
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7780
n, m = map(int, input().split())
apple = []
for _ in range(m):
    apple.append(list(map(int, input().split())))
cat = []
dog = []
for i in apple:
    cat.append(i[0])
    dog.append(i[1])

if min(dog) - max(cat) >= 0:
    print(min(dog) - max(cat) + 1)
else:
    print(0)

Measured memory_bytes: 29076
#include <bits/stdc++.h>
using namespace std;
int main() {
   long long A,B,ans=0;
   cin >> A >> B;
  for(int i=A; i<=B; i++){
    if((i%10 == i/10000) &&(i/1000 - (i/10000*10)) == ((i%100-i%10)/10)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
    string n; cin >> n ;
    ll sum =0;
    for(char x:n){
        sum+=x-'0';
    }
    if(sum%9==0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3720
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int exponential(int bottom, int top);

int main(void){
  int X,i,j,top,bottom,max;
  char str[10];
  
  fgets(str,sizeof(str),stdin);
  X=atoi(str);
  
  if(X==1){
    printf("1\n");
    return 0;
  }
  
  for(i=1;;i++){
    if(exponential(i,2)>X){
      break; 
    }
  }
  bottom=i-1;
  
  for(j=2;;j++){
    if(exponential(2,j)>X){
      break;
    }
  }
  top=j-1;
  
  max=0;
  
  for(i=1;i<=bottom;i++){
    for(j=2;j<=top;j++){
      if(exponential(i,j)>max && exponential(i,j)<=X){
        max=exponential(i,j); 
      }
    }
  }
  
  printf("%d\n",max);
  
 return 0; 
}


int exponential(int bottom, int top){
  int i,j,ex=1;
  
  for(i=1;i<=top;i++){
   ex*=bottom; 
  }
  
 return ex; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;

	int A[1001][1000];
	rep1(i, N) {
		rep(j, N - 1) cin >> A[i][j];
		A[i][N - 1] = 0;
	}

	int k[1001] = {}, k2[1001] = {};
	vector<int> V;
	rep1(i, N) V.pb(i);

	int kotae = 0;
	while (V.size()) {
		kotae++;
		vector<int> kari;
		for (auto v : V) {
			if (k2[v] < kotae) {
				int a = A[v][k[v]];
				if (A[a][k[a]] == v) {
					kari.pb(v);
					k2[v] = kotae;
					kari.pb(a);
					k2[a] = kotae;
				}
			}
		}
		swap(V, kari);
		for (auto v : V) k[v]++;
	}

	int OK = 1;
	rep1(i, N) if (k[i] != N - 1) OK = 0;
	if (OK) co(kotae - 1);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int d , n;

void solve(){
  int ans;
  if(n < 100) ans = pow(100,d) * n;
  else ans = pow(100,d) * (n+1) ;
  cout << ans << endl;
  return;
}
int main(){
  cin >> d >> n ;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define RANGE_R(i,a,b) for(int i=(int)b-1,_a=(int)(a);(i)>=_a;--i)
#define MIN_UPDATE(target, value) target = min(target, value)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT(v) __builtin_popcountll((ll)(v))
#define IN_RANGE(v, a, b) ((a)<=(v) && (v)<(b))
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }


/*

*/
int main() {
	ll N;
	cin>>N;
	string s(N, '0');
	REP(i, N) {
		int v;
		cin>>v;
		s[i]=v+'0';
	}
	REP(i, 10000) {
		stringstream ss;
		ss<<i;
		string pat(ss.str());
		if(s.find(pat)==s.npos) {
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

// numをboarder以下にするために何回切る必要があるかを返す
ll f(ll num, ll boarder)
{
    if (num <= boarder)
    {
        return 0;
    }
    return ((num + boarder - 1) / boarder) - 1;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> as(n);
    ll maxi = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        maxi = max(maxi, as[i]);
    }
    // 二分探索
    ll left = 0;
    ll right = 1000000000;
    while (right - left > 1)
    {
        ll cnt = 0;
        bool flag = true;
        ll mid = (right + left) / 2;
        // cout << mid << endl;
        for (int i = 0; i < n && flag; i++)
        {
            cnt += f(as[i], mid);
            if (cnt > k)
            {
                flag = false;
            }
        }
        if (flag)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }
    cout << right << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 4764
// 6/25 解き直し
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(3000000);

int main() {
    int X, Y;
    cin >> X >> Y;

    // 3の倍数でなければNG。
    if ((X+Y)%3) {
        cout << "0" << endl;
        return 0;
    }

    int N = (X + Y) / 3;  // N = 移動回数
    X -= N;
    Y -= N;
    if (X<0 || Y<0) {
        cout << "0" << endl;
        return 0;
    }
    // if (X + Y))

    cout << comb(X+Y, X) << endl;
}

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

int main(){
  int n;cin>>n;
  vector<int> x(n,0);
  REP(i,n) cin>>x.at(i);
  sort(x.begin(),x.end());
  cout<<x.back()-x.at(0);
}

Measured memory_bytes: 256
import itertools


WAIT, PRESORT, SORTED = 0, 1, 2
cost = 0

def swap(w1, w2):
    global cost
    cost += w1[WAIT] + w2[WAIT]
    w1[PRESORT], w2[PRESORT] = w2[PRESORT], w1[PRESORT]
    

n = input()
w = [[wi, i, None] for i, wi in enumerate(map(int, input().split()))]
s = sorted(w)
minw = s[0]
for i, wi in enumerate (s):
    wi[SORTED] = i
    
for si in s:
    tmp = si
    t = []
    while tmp[SORTED] != si[PRESORT]:
        tmp = w[tmp[SORTED]]
        t += [tmp]

    if len(t ) and minw != si and si[WAIT] * (len(t) - 2) > minw[WAIT] * (len(t) + 2):
        swap(minw, si)
        for ti in t[::-1]:
            swap(minw, ti)
        swap(minw, si)
    else:
        for ti in t[::-1]:
            swap(si, ti)
    
print(cost)

Measured memory_bytes: 6856
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        int a, b, c;
        cin >> a >> b >> c;
        cout << c << " " << a << " " << b << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <time.h>
#include <ctime>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int d, c[28], s[370][28], t[370], b[370][28];

int score() {
    int i, j, ans;

    for (i = 0; i < 26; i++) {
        b[0][i] = 1;
    }

    ans = 0;
    for (i = 0; i < d; i++) {
        ans += s[i][t[i]];
        b[i][t[i]] = 0;
        for (j = 0; j < 26; j++) {
            ans -= c[j] * b[i][j];
            b[i + 1][j] = b[i][j] + 1;
        }
    }

    return ans;
}

int delta(int chd, int cht) {
    int i, res;

    res = s[chd][cht] - s[chd][t[chd]];

    i = chd + 1;
    while (i < d && t[i] != t[chd]) {
        i++;
    }

    if (chd == 0) {
        res -= (i - chd) * c[t[chd]];
    }
    else {
        res -= (b[chd - 1][t[chd]] + 1) * (i - chd) * c[t[chd]];
    }

    i = chd;
    while (i < d && t[i] != cht) {
        i++;
    }

    res += b[chd][cht] * (i - chd) * c[cht];

    return res;
}

void change(int chd, int cht) {
    int i;

    i = chd;
    while (i < d && (i == chd || t[i] != t[chd])) {
        if (chd == 0) {
            b[i][t[chd]] = i + 1;
        }
        else {
            b[i][t[chd]] = b[i - 1][t[chd]] + 1;
        }
        i++;
    }

    i = chd;
    while (i < d && t[i] != cht) {
        b[i][cht] = i - chd;
        i++;
    }

    t[chd] = cht;
}

int main(void) {
    int i, j;

    clock_t start = clock(), end;
    double rtime;

    scanf("%d", &d);
    for (i = 0; i < 26; i++) {
        scanf("%d", &c[i]);
    }
    for (i = 0; i < d; i++) for (j = 0; j < 26; j++) {
        scanf("%d", &s[i][j]);
    }

    int scmax, scmi;

    for (i = 0; i < d; i++) {
        scmax = 0;
        scmi = 0;
        for (j = 0; j < 26; j++) {
            if (scmax < s[i][j]) {
                scmax = s[i][j];
                scmi = j;
            }
        }
        t[i] = scmi;
    }

    int before = score(), after, chd, cht;

    srand(time(nullptr));

    while (1) {
        end = clock();
        rtime = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (rtime > 1950) {
            break;
        }

        chd = rand() % d;
        cht = rand() % 26;

        while (t[chd] == cht) {
            cht = rand() % 26;
        }

        after = before + delta(chd, cht);

        if (after > before) {
            change(chd, cht);
            before = after;
        }
    }

    for (i = 0; i < d; i++) {
        printf("%d\n", t[i] + 1);
    }
    
    return 0;
}

Measured memory_bytes: 3920
import numpy as np
H, W = map(int, input().split())
red_map = np.array([input().split() for i in range(H)], dtype="int")
blue_map = np.array([input().split() for i in range(H)], dtype="int")
sub_map = abs(red_map - blue_map)
dp = [[2020]*W for i in range(H)]
max_deviation = 2**(80*(H+W))

for i in range(H):
  for j in range(W):
    if not i and not j:
      dp[i][j] = (max_deviation<<sub_map[i][j] | max_deviation>>sub_map[i][j])
    if i > 0:
      dp[i][j] |= (dp[i-1][j]<<sub_map[i][j] | dp[i-1][j]>>sub_map[i][j])
    if j > 0:
      dp[i][j] |= (dp[i][j-1]<<sub_map[i][j] | dp[i][j-1]>>sub_map[i][j])
      
pre_ans = dp[H-1][W-1]>>80*(H+W)
pre_ans_bit = format(pre_ans&-pre_ans, "b")
ans = len(pre_ans_bit)-1
print(ans)

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

int main() {
	int n, m, l, r, lmax=0, rmin=100001;
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>l>>r;
		if(lmax<l) lmax=l;
		if(rmin>r) rmin=r;
	}
	
	if(rmin>=lmax) cout<<rmin-lmax+1;
	else cout<<0;
	
	return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n,u,v=map(int, input().split())
u-=1
v-=1
es=[[] for i in range(n)]
for i in range(n-1):
    a0,b0=map(int, input().split())
    es[a0-1].append(b0-1)
    es[b0-1].append(a0-1)
aoki=[-1]*n
aoki[v]=0
choku=[-1]*n
choku[u]=0
from collections import deque
que=deque([])
que.append(u)
while que:
    now=que.popleft()
    step=choku[now]
    for e in es[now]:
        if choku[e]==-1:
            choku[e]=step+1
            que.append(e)

que=deque([])
que.append(v)
while que:
    now=que.popleft()
    step=aoki[now]
    for e in es[now]:
        if aoki[e]==-1:
            aoki[e]=step+1
            que.append(e)

end=None
for i in range(n):
    if len(es[i])==1: 
        if choku[i]==0 and aoki[i]==1:
            print(0)
            exit()
        elif end==None and aoki[i]>choku[i]:
            end=(i, aoki[i])
        elif aoki[i]>choku[i] and end[1]<aoki[i]:
            end=(i, aoki[i])
print(end[1]-1)

Measured memory_bytes: 84972
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

//#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

#define NMAX 500010

struct QUARR{
    int l;
    int r;
    int index;
    int type;
    int ans;
    bool operator<(QUARR q) const{
        if(type==1){
            if(q.r==r) return q.l>l;
            return q.r>r;
        }
        else{
            return q.index>index;
        }
    }
};

int ft_bit[NMAX];
void ft_add(int a,int w,int N){
    for(int x=a;x<=N;x+=x&-x){
        ft_bit[x]+=w;
    }
}

int ft_sum(int a){
    int ret=0;
    for(int x=a;x>0;x-=x&-x){
        ret+=ft_bit[x];
    }
    return ret;
}

signed main(){
    //ios::sync_with_stdio(false);
    cin.tie(nullptr);
    QUARR qu[NMAX];
    int last[NMAX];
    int c[NMAX];
    int N,Q;

    cin>>N>>Q;
    for(int i=1;i<=N;i++){
        cin>>c[i];
        last[i]=-1;
    }

    for(int i=1;i<=Q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        qu[i].l=l;
        qu[i].r=r;
        qu[i].index=i;
        qu[i].type=1;
        qu[i].ans=0;
    }

    sort(qu+1,qu+Q+1);

    for(int i=1;i<=qu[1].r;i++){
        if(last[c[i]]==-1){
            ft_add(i,1,N);
            last[c[i]]=i;
        }
        else{
            ft_add(last[c[i]],-1,N);
            ft_add(i,1,N);
            last[c[i]]=i;
        }
    }

    qu[1].ans=ft_sum(qu[1].r)-ft_sum(qu[1].l-1);
    qu[1].type=2;
    for(int i=2;i<=Q;i++){
        for(int j=qu[i-1].r+1;j<=qu[i].r;j++){
            if(last[c[j]]==-1){
                ft_add(j,1,N);
                last[c[j]]=j;
            }
            else{
                ft_add(last[c[j]],-1,N);
                ft_add(j,1,N);
                last[c[j]]=j;
            }
        }
        qu[i].ans=ft_sum(qu[i].r)-ft_sum(qu[i].l-1);
        qu[i].type=2;
    }

    sort(qu+1,qu+Q+1);

    for(int i=1;i<=Q;i++){
        printf("%d\n",qu[i].ans);
    }
}


Measured memory_bytes: 19420
// ===== 2018/06/16 21:05:25 =====

// ../../../lib/template/includes.hpp

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

// ../../../lib/template/const_value.hpp

namespace sub {
  template <typename T>
  constexpr typename std::enable_if<std::is_integral<T>::value, T>::type
  inf_sub() {
    return std::numeric_limits<T>::max() / 2 - 1000;
  }

  template <typename T>
  constexpr typename std::enable_if<std::is_floating_point<T>::value, T>::type
  inf_sub() {
    return std::min(std::numeric_limits<T>::max() / 2 - 1000, T(1e50));
  }
}

template <typename T> constexpr T inf() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return sub::inf_sub<T>();
}

template <typename T> constexpr T zero() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return T(0);
}

const long double pi = acos(-1.0);

// ../../../lib/template/initialize.cpp

struct yes_no : std::numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

struct Initialize {
  Initialize() {
    std::locale loc(std::locale(), new yes_no);
    std::cout << std::boolalpha << std::setprecision(11) << std::fixed;
    std::cout.imbue(loc);
  }
};

const Initialize init;

// ../../../lib/template/macros.hpp

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

// ../../../lib/template/misc.hpp

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }

template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// ../../../lib/template/range.hpp

class range {
  class index_type {
    int x;

  public:
    index_type(int x_) : x(x_) {}
    int operator*() const { return x; }
    bool operator!=(index_type &r) { return x < r.x; }
    void operator++() { ++x; }
  };
  index_type i, n;

public:
  range(int n_) : i(0), n(n_) {}
  range(int i_, int n_) : i(i_), n(n_) {}
  index_type &begin() { return i; }
  index_type &end() { return n; }
};

// ../../../lib/template/typedef.hpp

using ll = long long;
using ld = long double;
using Point = std::complex<ld>;

// ../../../lib/template/template.cpp

using namespace std;

// C.cpp

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

void solve(ll N, vector<ll> a) {
  ll cnt = 0;
  for (ll x: a) {
    while (x % 2 == 0) {
      x /= 2;
      ++cnt;
    }
  }
  cout << cnt << endl;
}

int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}
// ===== 2018/06/16 21:05:25 =====



Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int n,i;
  scanf("%d",&n);
  int l;
  int total = 0;
  int tempmax = 0;
  for(i=0;i<n;i++) {
    scanf("%d",&l);
    total += l;
    if(tempmax < l) {
      tempmax = l;
    }
  }
    if(2*tempmax < total) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
}


Measured memory_bytes: 128
from collections import defaultdict


def main():
    N, W = map(int, input().split())
    items = []
    for _ in range(N):
        v, w = map(int, input().split())
        items.append((v, w))

    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i in range(N):
        v, w = items[i][0], items[i][1]
        for j in range(W + 1):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            if j + w < len(dp[0]):
                dp[i][j + w] = max(dp[i][j + w], dp[i][j] + v)

    print(dp[-1][-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 18116
n=int(input())
w=list(map(int,input().split()))

sf=[w[0]]*(n-1)
sr=[w[-1]]*(n-1)

for i in range(n-2):
    sf[i+1]=sf[i]+w[i+1]
    sr[i+1]=sr[i]+w[-i-2]

d=[sf[i]-sr[n-i-2] for i in range(n-1)]

for i in range(n-1):
    if d[i]<0:
        d[i]*=-1

print(min(d))

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    long long a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if (2 * c < a + b) {
        if (x == y) {
            cout << c * (x + y);
        } else if (x < y) {
            if (2 * c < b) {
                cout << 2 * c * x + 2 * c * (y - x);
            } else {
                cout << 2 * c * x + b * (y - x);
            }
        } else {
            if (2 * c < a) {
                cout << 2 * c * y + 2 * c * (x - y);
            } else {
                cout << 2 * c * y + a * (x - y);
            }
        }
    } else {
        cout << a * x + b * y;
    }
}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;

int main()
{
	int a,b;cin>>a>>b;
	cout<<max(0,a-2*b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int w, h;
bool visited[50][50] = {};
int m[50][50];

void solve(int y, int x){
  
  m[y][x] = 0;
  for(int i = 0; i < 8; ++i){
    int nx = x + dx[i], ny = y + dy[i];
    if(nx >= 0 && nx < w && ny >= 0 && ny < h && m[ny][nx] == 1){
      solve(ny, nx);
    }
  }
}

int main(){

  while(true){
  cin >> w >> h;
  
  if(w == 0 && h == 0) break;

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> m[i][j];
    }
  }

  

  int ans = 0;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(m[i][j] == 1){
        solve(i, j);
        ans++;
      }
    }    
  }

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



Measured memory_bytes: 3144
import fractions

N,M = map(int, input().split())
l_a = list(map(int, input().split()))
l_num = []
lcm = 1

flg = True
for a in l_a:
  a //= 2
  if not a in l_num:
    l_num.append(a)
  lcm = lcm * a // fractions.gcd(lcm, a)
  if lcm > M:
    flg = False
    break
if flg:
  for num in l_num:
    if lcm > num and lcm // num % 2 == 0:
      flg = False
if flg:
  print((M // lcm + 1) //2)
else:
  print(0)

Measured memory_bytes: 16324
N,K=map(int,input().split())
S=[0]*N
for _ in[0]*K:a,b=map(int,input().split());S[a-1]=b
dp=[0]*9
st,nd=S[:2]
if st:
 if nd:dp[~-st*3+~-nd]=1
 else:dp[~-st*3:st*3]=[1]*3
elif nd:dp[~-nd::3]=[1]*3
else:dp=[1]*9
for i in range(2,N):
 cur=S[i]-1;tmp=[0]*9
 if cur+1:
  for k in range(3):tmp[k*3+cur]=sum(dp[k::3])-dp[cur*4]*(k==cur)
 else:
  for cur in range(3):
   for k in range(3):tmp[k*3+cur]=sum(dp[k::3])-dp[cur*4]*(k==cur)
 dp=tmp[:]
print(sum(dp)%10000)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  ll n;
  cin >> n;
  rep(i, n) cout << "ACL";
  cout << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	int ans = A - B * 2;
	if (ans < 0) ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	s+='.';
	long long ans=0;
	int anum=0;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='A')
			anum++;
		else if(s[i]=='B'&&s[i+1]=='C'){
			ans+=anum;
			i++;
		}else
			anum=0;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int ReadInt(void) {
  int c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = 10 * x + c - '0';
    c = getchar();
  }
  return x;
}

void WriteInt(int x) {
  char buf[10];
  int len = 0;
  while (x) {
    buf[len++] = (char)('0' + x % 10);
    x /= 10;
  }
  while (len--) {
    putchar(buf[len]);
  }
}

const int maxn = 1e6;

int n, a[maxn];
vector<int> g[maxn];
bool down[maxn];
bool ans[maxn];

void Dfs1(int u, int p) {
  down[u] = false;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == p) {
      continue;
    }
    Dfs1(v, u);
    if (a[u] > a[v] && !down[v]) {
      down[u] = true;
    }
  }
}

void Dfs2(int u, int p, bool up) {
  ans[u] = down[u];
  if (p != -1 && a[u] > a[p] && !up) {
    ans[u] = true;
  }
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == p) {
      continue;
    }
    Dfs2(v, u, ans[u]);
  }
}

int main(void) {
  n = ReadInt();
  for (int i = 0; i < n; ++i) {
    a[i] = ReadInt();
  }
  for (int i = 0; i < n - 1; ++i) {
    int u = ReadInt() - 1, v = ReadInt() - 1;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  Dfs1(0, -1);
  Dfs2(0, -1, false);
  for (int i = 0; i < n; ++i) {
    if (ans[i]) {
      WriteInt(i + 1);
      putchar(' ');
    }
  }
  putchar('\n');
  return 0;
}


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

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

    string ans;

    for (int i = 0; i < ty - sy; ++i) ans += 'U';
    for (int i = 0; i < tx - sx; ++i) ans += 'R';
    
    for (int i = 0; i < ty - sy; ++i) ans += 'D';
    for (int i = 0; i < tx - sx; ++i) ans += 'L';

    ans += 'L';
    for (int i = 0; i <= ty - sy; ++i) ans += 'U';
    for (int i = 0; i <= tx - sx; ++i) ans += 'R';
    ans += 'D';
    
    ans += 'R';
    for (int i = 0; i <= ty - sy; ++i) ans += 'D';
    for (int i = 0; i <= tx - sx; ++i) ans += 'L';
    ans += 'U';

    cout << ans << endl;
}


Measured memory_bytes: 256
grid = [list(map(int,input().split())) for _ in range(3)]
a1 = min(grid[0])
a2 = min(grid[1])
a3 = min(grid[2])


flag = False

while True:
    if a1 < 0 or a2 < 0 or a3 < 0:
        break
    b1 = grid[0][0] - a1
    c1 = grid[1][0] - a2
    d1 = grid[2][0] - a3
    
    b2 = grid[0][1] - a1
    c2 = grid[1][1] - a2
    d2 = grid[2][1] - a3
    
    b3 = grid[0][2] - a1
    c3 = grid[1][2] - a2
    d3 = grid[2][2] - a3

    if b1 == c1 == d1 and b2 == c2 == d2 and b3 == c3 == d3:
        flag = True
        break
    a1 -= 1
    a2 -= 1
    a3 -= 1
    
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N, A, B, C, D = gets.split.map(&:to_i)

n = N - 2

n.times do |i|
  max = A - (i * C) + (n - i + 1) * D
  min = A - (i * D) + (n - i + 1) * C
  
  if min <= B && B <= max
    puts 'YES'
    exit
  end
end

puts 'NO'


Measured memory_bytes: 3836
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    set<int> st;
    multiset<int> mst;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        st.insert(a);
        mst.insert(a);
    }
    auto itr = mst.end();
    itr--;
    if(st.size() == 1 && *mst.begin() == 0)
    {
        cout << "Yes\n";
    }
    else if(n % 3 == 0 && st.size() == 2 && mst.count(0) == n / 3)
    {
        cout << "Yes\n";
    }
    else if(n % 3 == 0 && st.size() == 3 && mst.count(*mst.begin()) == n / 3 && mst.count(*itr) == n / 3)
    {
        auto st_itr = st.begin();
        int x = *st_itr;
        st_itr++;
        int y = *st_itr;
        st_itr++;
        int z = *st_itr;
        if(!(x ^ y ^ z))
        {
        cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }
    else
    {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 7552
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,m;
  int atari,hazure;
  vector<int> result;
  int total=0;
  
  cin>>n>>m;

  for(int i=0;i<m;++i){
    cin>>atari>>hazure;
    if(atari>=n)
      result.push_back(0);
    else
      result.push_back((hazure-atari)/2);
  }

  sort(result.begin(),result.end());

  for(int i=0;i<m-1;++i)
    total+=result[i];

  cout<<total<<endl;
}

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

int main() {
	char g[8],c[6]={'R','Y','B','M','G','C'};
	int n,m,i,j,k,s,h,ic[6],cd[6],d[30],a[6][4]={{2,3,5,4},{6,3,1,4},{2,6,5,1},{2,1,5,6},{1,3,6,4},{2,4,5,3}};
	while(cin >> n) {
		if (n==0) break;
		for (i=0;i<30;i++) d[i]=0; h=0;
		for (i=0;i<n;i++) {
		     for (j=0;j<6;j++) {	
                  cin >> g;
                  for (k=0;k<6;k++) if (g[0]==c[k]) break;
                  ic[j]=k; if (k==0) s=j;
	              }
	    for (m=0,j=0;j<4;j++) { cd[j]=ic[a[s][j]-1]; if (cd[j]<cd[m]) m=j; }
	    d[i]=cd[m]*1000+cd[(m+1) % 4]*100+cd[(m+2) % 4]*10+cd[(m+3) % 4];
	    for (k=1,j=0;j<i;j++) if (d[i]==d[j]) { k=0; break;}
	    h+=k;
        }
        cout << n-h << endl;
	}   			
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main(){
  unsigned long long int a,b,x;
  cin>>a>>b>>x;
  
  unsigned long long int count=0;
  if(a==0){
    a+=1;
    count=b/x-(a-1)/x;
    count++;
  }else count=b/x-(a-1)/x;
  
  cout<<count<<endl;
  
  return 0;
}


Measured memory_bytes: 256
def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

h,w = gsmi
ass = Array.new(h){ gsmi }

cnt = 0
ans = []
for y in 1..h
	for x in 1..w
		next if ass[y-1][x-1].even?
		cnt += 1 if y!=h && x!=w
		if y!=h
			ans << [y,x,y+1,x].join(" ")
			ass[y][x-1] += 1
		elsif x!=w
			ans << [y,x,y,x+1].join(" ")
			ass[y-1][x] += 1
		end
	end
end

puts ans.size
puts ans

Measured memory_bytes: 35932
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
for i in range(n):
    a[i+1] += a[i]
for i in range(m):
    b[i+1] += b[i]
B = m
ans = 0
for i in range(n+1):
    while a[i] + b[B] > k and B > 0:
        B -= 1
    if a[i] + b[B] <= k:
        ans = max(ans,i+B)
print(ans)

Measured memory_bytes: 119628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

//map<tuple<int, int, int, int, int>, double> dp;
//int table[4][4];
//int v[101];
//
//double EPS = 1e-9;
//
//int L, A, B;
//double rec(int n, int acc, int prv, int comb, int pnt){
//	if (n == L) return pnt == 100;
//
//	auto t = make_tuple(n, acc, prv, comb, pnt);
//	if (dp.count(t)) return dp[t];
//	double &res = dp[t];
//
//	res = 0;
//
//	res = rec(n + 1, 0, 4, v[n] ? 0 : comb, pnt);
//	if(v[n] != 0) for (int i = 0; i < 4; ++i){
//		if (v[n] == 2 && i < 2) continue;
//		if (v[n] == 1 && i >= 2) continue;
//		int ip;
//		if (prv == 4) ip = 10;
//		else ip = max(0, (table[prv][i] - 10) + acc);
//		double p = ip / 10.;
//
//		double tmp = 0;
//		if(p > EPS) tmp += p*rec(n + 1, ip, i, comb+1, min(100, pnt+A+B*min(comb, 10)));
//		if(1-p > EPS) tmp += (1 - p)*rec(n + 1, ip, i, 0, pnt);
//		res = max(res, tmp);
//	}
//
//	return res;
//}

int table[4][4];
int v[101];

double EPS = 1e-9;
int L, A, B;

double dp[2][11][5][11][101]; // i, prv_acc, prv_pos, combo, point

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while (1){
		rep(i, 4) rep(j, 4){
			cin >> table[i][j];
			if (table[i][j] < 0) goto end;
		}
		cin >> L;
		rep(i, L) cin >> v[i];
		cin >> A >> B;
		A /= 100, B /= 100;

		int cur = 0, nxt = 1;
		rep(i, 11) rep(j, 5) rep(k, 11) rep(l, 101) dp[cur][i][j][k][l] = l == 100;
		for (int n = L - 1; n >= 0; --n){
			rep(acc, 11) rep(prv, 5) rep(comb, 11) rep(pnt, 101){
				double &res = dp[nxt][acc][prv][comb][pnt];
				res = 0;
				
				res = dp[cur][0][4][v[n] ? 0 : comb][pnt];
				if(v[n] != 0) for (int i = 0; i < 4; ++i){
					if (v[n] == 2 && i < 2) continue;
					if (v[n] == 1 && i >= 2) continue;
					int ip;
					if (prv == 4) ip = 10;
					else ip = max(0, (table[prv][i] - 10) + acc);
					double p = ip * .1;
				
					double tmp = 0;
					tmp += p*dp[cur][ip][i][min(10, comb+1)][min(100, pnt+A+B*min(comb, 10))];
					tmp += (1 - p)*dp[cur][ip][i][0][pnt];
					res = max(res, tmp);
				}
			}
			swap(cur, nxt);
		}
		cout << dp[cur][0][4][0][0] << endl;
	}

end:
	return 0;
}

Measured memory_bytes: 2192
N = int(input())
A = list(map(int, input().split()))

ans = 1
flg = True
z_flg = False
for i in range(N):
    if A[i] == 0:
        z_flg = True

if z_flg:
    print(0)
    exit()

for i in range(N):
    ans = ans * A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 21704
#include <iostream>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> f(100001, 0);
  vector<int> s(100001, 0);
  rep(i, n)
  {
    int x;
    cin >> x;
    if(i&1)
      s[x]++;
    else
      f[x]++;
  }
  auto maxf = max_element(f.begin(), f.end());
  auto maxs = max_element(s.begin(), s.end());
  int idxf = distance(f.begin(), maxf);
  int idxs = distance(s.begin(), maxs);

  int ans;
  if(idxf != idxs)
  {
    ans = n - *maxf - *maxs;
  }
  else
  {
    sort(f.begin(), f.end(), greater<int>());
    sort(s.begin(), s.end(), greater<int>());
    if(f[1] > s[1])
    {
      ans = n - f[1] - s[0];
    }
    else
    {
      ans = n - f[0] - s[1];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    int K; string S; cin >> K >> S;
    if(S.length() <= K){
        cout << S << endl;
    }else{
        cout << S.substr(0, K) + "..." << endl;
    };

}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int cnt=0;
vector<int>ed[200005];
int vis[200005];
void dfs(int i){
	cnt++;
	vis[i]=1;
	for(int j:ed[i]){
		if(vis[j])continue;
		dfs(j);
	}
}
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		cnt=0;
		dfs(i);
		ans=max(ans,cnt);
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 10000005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long

#define mod  1000000007



int main()
{
	FAST;
	string t, s;
	cin >> s >> t;
	cout << t << s ;
	return 0;
}

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

int main() {
	string in;
	int a_count = 0, b_count = 0;
	cin >> in;
	for(int i = 0; i < 3; i++){
	    if(in[i] == 'A' ) {
	        a_count++;
	    }else {
	        b_count++;
	    }
	}
	cout << ( a_count == 3 || b_count == 3 ? "No" : "Yes") << "\n";
	
	return 0;
}


Measured memory_bytes: 256
kn = list(map(int,input().split()))
a = list(map(int,input().split()))

k = kn[0]
n = kn[1]


dis = []

for i in range(n):
    if i == 0:
        dis.append(min((a[n-1] - a[0]), (k - a[n-1] + a[0])))
    else:
        dis.append(min((a[i] - a[i-1]), (k - a[i] + a[i-1])))

del dis[dis.index(max(dis))]

print(sum(dis))

'''
dis = [[0]*n]

for i in range(n):
    for j in range(n):
        if i+j+1 >= n-1:
            dis[i][j] = k - a[i+j+1-(n-1)] + a[i+j+1-(n-1)-1]
        else:
            dis[i][j] = a[i+j+1] - a[i+j]

    dis.append([0]*n)
    print(dis)

print(dis)
'''

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

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


Measured memory_bytes: 3632
N = int(input())
S = []
for i in range(N):
    S.append(input())

names = {}
for s in S:
    initial = s[0]
    if initial not in names:
        names[initial] = 0
    names[initial] += 1

initial_keys = set(names.keys()).intersection({"M", "A", "R", "C", "H"})
if len(initial_keys) < 3:
    print(0)
else:
    initials = ["M", "A", "R", "C", "H"]
    count = 0
    for i in range(len(initials)-2):
        for j in range(i+1, len(initials)-1):
            for k in range(j+1, len(initials)):
                count += (names.get(initials[i], 0) * names.get(initials[j], 0) * names.get(initials[k], 0))
    print(count)


Measured memory_bytes: 56280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, m;

	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s.at(i);
	}

	cin >> m;
	vector<string> t(m);
	for (int i = 0; i < m; i++) {
		cin >> t.at(i);
	}

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());

	int max_num = 0;

	for (const auto& str : s) {
		int s_num = count(s.begin(), s.end(), str);
		int t_num = count(t.begin(), t.end(), str);
		max_num = max(max_num, (s_num - t_num));
	}

	cout << max_num << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
  int h,count,x,y;
  
  
  while(1){
    count=0;
    scanf("%d %d",&x,&y);
    if(x<y)
      {
	h=x;
	x=y;
	y=h;
      }    

    if(x==0 && y==0){ break;}
    
    while(1)  
      {
	x=x%y;  

	h=x;   
	x=y;  
	y=h; 
	
	if(y==0){break;} 	
	count++;
      }
    
    
    printf("%d %d\n",x,(count+1));
  }
  return 0; 
}

Measured memory_bytes: 0
import java.util.Scanner;

/**
 * Created by Reopard on 2014/07/03.
 */
public class Main{
    public static void main(String[] args){
        int x, y, z, m, min, e;

        Scanner scan = new Scanner(System.in);
        while((e = scan.nextInt()) != 0){
            min = Integer.MAX_VALUE;
            for(z = 0; z*z*z <= e; ++z){
                int z3 = z*z*z;
                for(y = 0; y*y + z3 <= e; ++y){
                    int y2 = y*y;
                    x = e - y2 - z3;
                    m = x + y + z;
                    min = Math.min(m, min);
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 24820