akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  int N=S.length();
  if(N==1){
    cout<<S<<endl;
    return 0;
  }
  lint ans=0;
  int m[N];
  m[0]=1;
  m[1]=1;
  for(int i=2;i<N;i++)m[i]=m[i-1]*2;
  for(int i=0;i<N;i++){
    lint M=0;
    for(int j=0;j<N;j++){
      M+=m[j]*(lint)pow(10,N-j-1);
    }
    ans+=M*(lint)(S[i]-'0');
    if(i<N-1)m[i+1]+=m[i];
    m[i]=0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;


int main() {
	ll x;
	cin >> x;
	ll ans = floor(x / 11) * 2;
	ll mod = x % 11;
	if (mod > 0 && mod <= 6) {
		ans += 1;
	}
	else if (mod > 6) {
		ans += 2;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
w,h,n = map(int,input().split())
l = []
for i in range(n):
  l.append(list(map(int,input().split())))
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
  if l[i][-1] == 1:
    xmin = max([xmin,l[i][0]])
  elif l[i][-1] == 2:
    xmax = min([xmax,l[i][0]])
  elif l[i][-1] == 3:
    ymin = max([ymin,l[i][1]])
  else:
    ymax = min([ymax,l[i][1]])
if ymax <= ymin or xmax <= xmin:
  S = 0
else:
  S = (ymax-ymin)*(xmax-xmin)
print (S)


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

int main() {
    ll n;
    cin>>n;
    ll a[n],i;
    ll d[64]={0};
    ll u,p,uu=0;
    for(i=0;i<n;i++){
    cin>>a[i];
    p=a[i];
    uu=0;
    while(p>0)
    {
        u=p%2;
        if(u==1)
        d[uu]++;
        uu++;
        p/=2;
    }
    }
    // for(i=0;i<10;i++)
    // cout<<d[i]<<" ";
    // cout<<endl;
    ll ans=0;
    ll g;
    for(i=0;i<n-1;i++)
    {
        ll d1[64]={0};
        p=a[i];
        uu=0;
        while(p>0)
        {
            u=p%2;
            if(u==1)
            d1[uu]++;
            uu++;
            p/=2;
            
        }
        for(ll j=0;j<62;j++)
        {
            // cout<<d[j]<<" "<<d1[j]<<endl;
            if(d1[j]==0)
            {
                  g=d[j];
                u=pow(2,j);
                u%=1000000007;
                u*=g;
                  u%=1000000007;
                ans+=u;
                 ans%=1000000007;
               
            }
            else
            {
                                 d[j]--;

                   g=n-1-i-d[j];
                u=pow(2,j);
                u%=1000000007;
                u*=g;
                  u%=1000000007;
                ans+=u;
                 ans%=1000000007;

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

Measured memory_bytes: 2560
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n[] = new int[3];
    for (int i = 0; i < 3; i++){
      n[i] = sc.nextInt();
    }
    Arrays.sort(n);
    System.out.println(n[0]+n[1]+n[2]*10);
  }
}


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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x;
    cin >> x;
    if (x <= 599) {
        cout << 8;
    } else if (x <= 799) {
        cout << 7;
    } else if (x <= 999) {
        cout << 6;
    } else if (x <= 1199) {
        cout << 5;
    } else if (x <= 1399) {
        cout << 4;
    } else if (x <= 1599) {
        cout << 3;
    } else if (x <= 1799) {
        cout << 2;
    } else {
        cout << 1;
    }
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(){
  int n,max=0,i,j;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  int str[27][2];
  for(i=0;i<26;i++){
    str[i][0]=-1;
    str[i][1]=-1;
  }
  for(i=0;i<n;i++){
    if(str[s[i]-'a'][0]==-1)
      str[s[i]-'a'][0]=i+1;
    else
      str[s[i]-'a'][1]=i+1;
  }
  for(i=1;i<n;i++){
    int count=0;
    for(j=0;j<26;j++){
      if(str[j][0]<i && i<=str[j][1])
        count++;
    }
    if(max<count)
      max=count;
  }
  printf("%d\n",max);
  return 0;
}


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

typedef long long ll;

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

    ll mod = pow(10, 9) + 7;

    ll H, W, K;
    cin >> H >> W >> K;
    K--;

    vector<vector<ll> > dp(H + 1, vector<ll>(W, 0));

    vector<ll> t(W);
    vector<ll> y(W - 1);

    for(int i = 0; i < W; i++) {
        for (int bit = 0; bit < (1 << (W - 1)); bit++) {
            vector<ll> S;
            for (ll j = 0; j < (W - 1); j++) {
                if (bit & (1 << j)) {
                    S.push_back(j);
                }
            }

            bool checker = false;
            for(int j = 0; j < S.size(); j++) {
                if(S[j] == i || S[j] == i - 1) {
                    checker = true;
                    break;
                }
                if(j > 0) {
                    if(S[j] - 1 == S[j - 1]) {
                        checker = true;
                        break;
                    }
                }
            }
            if(checker) continue;
            t[i]++;
        }
    }

    for(int i = 0; i < W - 1; i++) {
        for (int bit = 0; bit < (1 << (W - 1)); bit++) {
            vector<int> S;
            for (int j = 0; j < (W - 1); j++) {
                if (bit & (1 << j)) {
                    S.push_back(j);
                }
            }

            bool checker = false;
            bool flag = true;

            for(int j = 0; j < S.size(); j++) {

                if(S[j] == i) flag = false;
                if(j > 0) {
                    if(S[j] - 1 == S[j - 1]) {
                        checker = true;
                        break;
                    }
                }
            }
            if(checker || flag) continue;
            y[i]++;
        }
    }
    
    dp[0][0] = 1;

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(dp[i][j] == 0) continue;

            if(j > 0) {
                ll x = dp[i][j] * y[j - 1];
                x %= mod;
                dp[i + 1][j - 1] += x;
                dp[i + 1][j - 1] %= mod;
            }
            if(j < W - 1) {
                ll x = dp[i][j] * y[j];
                x %= mod;
                dp[i + 1][j + 1] += x;
                dp[i + 1][j + 1] %= mod;
            }
            ll x = dp[i][j] * t[j];
            x %= mod;
            dp[i + 1][j] += x;
            dp[i + 1][j] %= mod;
        }
    }
/*
    for(int i = 0; i < W; i++) {
        cerr << dp[H][i] << endl;
    }
*/
    cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node {
    int u, v;
};
string s;
int main() {
    cin>>s;
    int n=s.size();
    if(s[0]=='0'||s[n-1]=='1') {
        cout<<"-1"<<endl;
        return 0;
    }
    for(int i=0; i<n-1; i++) {
        if(s[i]!=s[n-i-2]) {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    //cout<<"yes"<<endl;
    queue<node>ans;
    int pre=1,now=2;
    for(int i=1; i<n; i++) {
        if(s[i]=='1') {
            ans.push({pre,now});
            int d=now;
            pre=now;
            for(int j=now;j<=i;j++){
                d++;
                ans.push({now,d});
            }
            now=d+1;
        }
    }
    ans.push({pre,now});
    while(!ans.empty()){
        cout<<ans.front().u<<" "<<ans.front().v<<endl;
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;

int base = 0;

int N, W;
int w[105], v[105];

int dp[105][305][105]; //[i][j][k] i番目以降の荷物から重さがW - jになるように選ぶ

int rec(int i, int j, int k){
    if(dp[i][j][k] >= 0){
        return dp[i][j][k];
    }

    int res;
    if(i == 0){
        if(W - j < base){
            res = rec(i + 1, j, k);
        }else{
            res = max(rec(i + 1, j, k), rec(i + 1, j + w[i], k + 1) + v[i]);
        }
    }else{
        if(i == N){
            res = 0;
        }else if(W - k * base - j < w[i] + base){
            res = rec(i + 1, j, k);
        }else{
            res = max(rec(i + 1, j, k), rec(i + 1, j + w[i], k + 1) + v[i]);
        }
    }
    return dp[i][j][k] = res;
}
int rec(int i, int j){
    int k = 0;
    if(dp[i][j][k] >= 0){
        return dp[i][j][k];
    }
    int res;
    if(i == N){
        res = 0;
    }else if(W - j < w[i]){
        res = rec(i + 1, j);
    }else{
        res = max(rec(i + 1, j), rec(i + 1, j + w[i]) + v[i]);
    }
    return dp[i][j][k] = res;
}

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

    rep(i,N){
        cin >> w[i] >> v[i];
        if(base == 0) base = w[i];
    }
    rep(i,N) w[i] -= base;
    //rep(i,N) show(w[i])

    //rep(i,N){ rep(j,8){ rep(k,N){ cout << i << ' ' << j << ' ' << k << endl; if(dp[i][j][k] != 0) cout << dp[i][j][k] << endl; } } }

    memset(dp, -1, sizeof(dp));
    //printf("%d\n", rec(0,0));
    printf("%d\n", rec(0,0,0));
}


Measured memory_bytes: 13440
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    long long r, d, x;
    cin >> r >> d >> x;

    int cnt = 0;
    while (cnt < 10)
    {
        cout << r*x-d << endl;
        x = r*x - d;
        cnt++;
    }
}

Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {

	static int[] a;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		a = new int[10001];
		for(int i = 2 ; i <= n ; i++) {
			for(int j = 2 ; j <= i ; j++) {
				boolean isPrime = true;
				for(int k = 2 ; k * k <= j ; k++) {
					if(j % k == 0) isPrime = false;
				}
				// jが素数なら割り切れるまで割る
				if(isPrime) {
					int temp = i;
					int ret = 0;
					while(temp % j == 0) {
						temp /= j;
						ret++;
					}
					a[j] += ret;
				}
			}
		}
//		System.out.println(Arrays.toString(a));
		long ans = 1;
		for(int i = 0 ; i <= n ; i++) {
			ans = (ans * (a[i] + 1)) % 1000000007;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m, V, p;
    cin >> n >> m >> V >> p;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(rall(a));

    // 判定問題「a[x]が採用される可能性はあるか？」を二分探索で解く
    ll left = -1;
    ll right = n;
    while(right - left > 1) {
        ll x = (left + right)/2;
        if(x < p) {
            left = x;
            continue;
        }
        if(a[x] + m < a[p-1]) {
            right = x;
            continue;
        }
        ll cnt = m*(p-1+n-x);
        exrep(i, p-1, x-1) {
            cnt += a[x] + m - a[i];
        }
        if(cnt < m*V) {
            right = x;
        }
        else {
            left = x;
        }
    }
    
    out(right);
    re0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	long long x, y;
	x = y = 1;
	rep(i,n) {
		int t, a;
		cin >> t >> a;
		/*int c = gcd(t, a);
		t /= c;
		a /= c;*/
		long long m = max((x + t - 1) / t, (y + a - 1) / a);
		x = m * t;
		y = m * a;
	}
	cout << x + y << endl;

	return 0;
}

Measured memory_bytes: 256
//
//  main.c
//  A_CookieExchanges
//
//  Created by user1 on 2017/05/06.
//  Copyright © 2017年 user1. All rights reserved.
//

#include <stdio.h>

#define PERSONS 3
#define LOGNUM 10000

int pocket[PERSONS] = {0};

typedef struct LOG {
    int log_pocket[3];
}Log;

Log logs[LOGNUM];
int logInd = 0;

//過去にこの状態を経験したことがないかをチェックする
int validCheck(){
    int ind_pocket;
    int ind_log;
    int ind_log_pocket;
    int hitCount = 0;
    
    int ret = 1;
    
    for(ind_pocket=0; ind_pocket< PERSONS; ind_pocket++){
        for(ind_log = 0; ind_log < logInd; ind_log++){
            for (ind_log_pocket=0; ind_log_pocket<PERSONS; ind_log_pocket++) {
                if(pocket[ind_pocket] == logs[ind_log].log_pocket[ind_log_pocket]){
                    hitCount++;
                    goto find;
                }
            }
        }
    find:
        //一通りみてカブリがなかったら一度も来ていない状態
        if(hitCount == 0){ ret = 1; break;}
        //二つヒットがあったんなら、その時点で、3つしかない上に和は固定なので一度は来た状態だとわかる。
        else if(hitCount >= 2){ ret = -1; break;}
    }
    
    //登録
    logs[logInd].log_pocket[0] = pocket[0];
    logs[logInd].log_pocket[1] = pocket[1];
    logs[logInd].log_pocket[2] = pocket[2];
    logInd ++;
    
    return ret;
}

//クッキー交換して次の状態にする
int exchange(){
    int i;
    int next[3]={0};
    
    //奇数がないかチェックする
    for (i=0; i<PERSONS; i++) {
        if(pocket[i]%2 == 1){
            //printf("break! ODD_NUM\n");
            return -1;
        }
    }

    //次の状態を計算
    next[1] += pocket[0]/2;
    next[2] += pocket[0]/2;
    
    next[0] += pocket[1]/2;
    next[2] += pocket[1]/2;
    
    next[0] += pocket[2]/2;
    next[1] += pocket[2]/2;
    
    pocket[0] = next[0];
    pocket[1] = next[1];
    pocket[2] = next[2];
    
    //正常終了
    return 1;
}


void solve(){
    int count=0;
    validCheck();
    while(exchange() == 1){
        if(validCheck() == -1){
            printf("%d\n", -1);
            return;
        }
        count ++;
    
    }
    
    printf("%d\n", count);
}

int main(int argc, const char * argv[]) {
    scanf("%d %d %d", &pocket[0], &pocket[1], &pocket[2]);
    solve();
    return 0;
}


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

#define INF 0x3f3f3f3f
#define MAXN 100010
#define endl "\n"
#define abs(a, b) ((a > b) ? a-b : b-a)

typedef long long int ll;

/* End */

int n;
ll a[MAXN];
ll b[MAXN];
ll c[MAXN];
ll pd[MAXN][3];

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];

	pd[n][0] = max(b[n], c[n]);
	pd[n][1] = max(a[n], c[n]);
	pd[n][2] = max(a[n], b[n]);

	for (int i = n-1; i >= 0; i--) {
	        pd[i][0] = max(b[i] + pd[i+1][1], c[i] + pd[i+1][2]);
		pd[i][1] = max(a[i] + pd[i+1][0], c[i] + pd[i+1][2]);
		pd[i][2] = max(a[i] + pd[i+1][0], b[i] + pd[i+1][1]);
	}

	cout << max(pd[1][0], max(pd[1][1], pd[1][2])) << endl;

	return 0;
}


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

int main() {
  
  int n, l;
  
  cin >> n;
  
  for (int i  = 1 ;i<10; i++){
    l = i * 111;
    if(n <= l){
      cout << i << i << i << endl;
      break;
    }
  }
  
      
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    bool p = (s.size()%2 == 0) ^ (*(s.begin()) == *(s.end() - 1));
    if(p) {
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<vector>
int main(){
    int max=0;
    int cnt=0;
    int N;
    std::cin>>N;
    std::vector<int> H;
    for(int i=0;i<N;++i){
        int Hi;
        std::cin>>Hi;
        H.push_back(Hi);
    }
    int last =0;
    for(int i=0;i<N;++i){
        if(last>=H[i]){
            cnt++;
        }else{
            if(cnt>max){
                max=cnt;
            }
            cnt=0;
        }
        last = H[i];
    }
    if(cnt>max){
        max=cnt;
    }
    std::cout<<max<<std::endl;
}

Measured memory_bytes: 1020
# include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {

	
	int N,mem;
	cin >> N ;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		
			mem = (int)S.at(i) + N;
		
			if (mem > 90) {
				mem -= 26;
		}
			
		
		cout << (char)mem;
	}
	cout << endl;


}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int a[N+1];
  for (int i = 1; i < N+1; i++)
  {
    scanf("%d",&a[i]);
  }

  int i=a[1],j=1,counter=1;
  while (i!=2&&j<N+1)
  {
    i=a[i];
    counter++;
    j++;
  }
  
  counter > N ? puts("-1"): printf("%d",counter);

  return 0;
}

Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const double pi=acos(-1);


int main ()
{
    int a,b;
    sint2(a,b);
    if(a>9||b>9)
        cout<<-1<<endl;
    else
        cout<<a*b<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		vector<int> p(n), j(n - 1);
		for (int i = 0; i < n; i++) cin >> p[i];
		for (int i = 0; i < n - 1; i++) cin >> j[i];

		//sort(p.rbegin(), p.rend());
		sort(j.rbegin(), j.rend());

		long long ans = 0;
		long long num = n;
		long long sum = 0;
		for (long long i = 0; i < n; i++) sum += p[i];
		// i は用いるジョイントの数
		ans = sum * num;
		for (long long i = 1; i < n; i++) {
			sum += j[i - 1];
			ans = max(ans, sum * (num - i));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3368
n = int(input())

res = "No"
for cake in range(0, int(n/4) + 1):
    for dornut in range(0, int(n/7) + 1):
        if 4 * cake + 7 * dornut == n:
            res = "Yes"
            break
    else:
        continue
    break

print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    int n,i;
    long long S;
    double A,m;
    while (cin >> n && n) {
        int s[n];
        S = 0L;
        for (i=0;i<n;i++) {
            cin >> s[i];
            S += s[i];
        }
        m = (double) S/n;
        A = 0.0f;
        for (i=0;i<n;i++) {
            A += (s[i] - m) * (s[i] - m);
        }
        printf("%.8lf\n", sqrt(A/n));
    }
    return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2254 : Fastest Route **/
const int MAX_N = 16;

int time_list[MAX_N+1][MAX_N];
int dp[1<<MAX_N];
int N;

int rec(int S)
{
	if (dp[S]>=0)
		return dp[S];
	
	if (S==(1<<N)-1) {
		return dp[S] = 0;
	}
	
	int res=INF;
	rep(u, N) {
		if (!(S>>u&1)) {
			int cost=INF;
			
			// 装備なし
			res = min(res, rec(S|1<<u) + time_list[0][u]);
			
			// 装備あり
			rep(j, N) {
				if (S>>j&1)
					res = min(res, rec(S|1<<u) + time_list[j+1][u]);
			}
		}
	}

	return dp[S] = res;
}

int main()
{
	while (cin>>N, N) {
		memset(dp, -1, sizeof(dp));
		
		rep(j, N) rep(i, N+1) cin>>time_list[i][j];
		
		cout << rec(0) << endl;
	}
}

Measured memory_bytes: 1424
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn acc_vec(v: &[i64]) -> Vec<i64>{
    let mut res = vec![0;v.len()+1];
    let mut acc: i64 = 0;
    for i in 0..v.len(){
        acc += v[i];
        res[i+1] = acc;
    }
    res
}

//search the best position to cut equally
//return $pos: sum of [left..pos) and sum of [pos..right) are the nearest
fn cut_equally(v: &[i64], left: usize, right: usize) -> usize {
    if right > v.len() || right - left <= 1{
        panic!("wrong params");
    }

    let (mut l, mut r) = (left, right);

    let mut cur_res = (0 as usize, std::i64::MAX);
    while l < r {
        //println!("l = {}, r = {}", l, r);
        let mid = (l+r)/2;
        // left sum = [left..mid)
        // right sum = [mid..right)
        let left_sum = v[mid-1] - v[left-1];
        let right_sum = v[right-1] - v[mid-1];
        //println!("left sum = {}, right sum = {}", left_sum, right_sum);
        if (right_sum - left_sum).abs() < cur_res.1{
            cur_res = (mid, (right_sum - left_sum).abs());
        }
        if right_sum > left_sum{
            l = mid+1;
        }else{
            r = mid;
        }
    }

    return cur_res.0;
}

fn sumup(v: &[i64], left: usize, right: usize, mid: usize) -> (i64, i64){
    return (v[mid-1] - v[left-1], v[right-1] - v[mid-1]);
}

fn main(){
    let n = read_as_vec::<usize>()[0];

    let a = read_as_vec::<i64>();
    let a = acc_vec(&a);

    let mut ans = std::i64::MAX;
    for i in 3..n{
        //split to [0..i) and [i..n)

        //binary search for each left and right
        //cut the vector equally as possible
        //left side
        let left_border = cut_equally(&a, 1, i);

        //right side
        let right_border = cut_equally(&a, i, n+1);

        let pq = sumup(&a, 1, i, left_border);
        let rs = sumup(&a, i, n+1, right_border);
        let (p, q) = (pq.0, pq.1);
        let (r, s) = (rs.0, rs.1);

        let max_val = cmp::max(p, cmp::max(q, cmp::max(r, s)));
        let min_val = cmp::min(p, cmp::min(q, cmp::min(r, s)));

        if (max_val - min_val).abs() < ans{
            ans = (max_val - min_val).abs();
        }
    }

    println!("{}", ans);
}


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

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

class Sol{
	public void Solve(){
		int N = ri();
        string[] strs = {
            "pon",
            "pon",
            "hon",
            "bon",
            "hon",
            "hon",
            "pon",
            "hon",
            "pon",
            "hon",
        };

		Console.WriteLine(strs[N % 10]);
		Console.ReadLine();
	}

	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));}
    static int[] generateNums(int num, int N){return Enumerable.Repeat(num, N).ToArray();}
    static int[] generateSuretsu(int N){return Enumerable.Range(0, N).ToArray();}
}

public static class Combination {
	//使い方:int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
    public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
        if (k == 1) {
            foreach (var item in items)
                yield return new T[] { item };
            yield break;
        }
        foreach (var item in items) {
            var leftside = new T[] { item };

            // item よりも前のものを除く （順列と組み合わせの違い)
            // 重複を許さないので、unusedから item そのものも取り除く
            var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

            foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }
}


Measured memory_bytes: 27400
#include <bits/stdc++.h>
using namespace std;
#define ll
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define forl(i,a,n) for(   long long int  i=a;i<n;i++)
#define rfor(i,n,a) for(   long long int  i=n;i>=a;i--)
#define fore(i,a,n) for(   long long int  i=a;i<=n;i++)
//---------------------------------------------------------------------
 int main()
{

  long long int n;
  cin>>n;
  long long int a[n+1];
  a[0]=0;
  long long int b[n+1];
  forl(i,0,n+1)
  {
    b[i]=0;
  }

  
  forl(i,1,n+1)
  {
    cin>>a[i];
    b[a[i]]++;
  }

  long long int m[n+1];
  forl(i,1,n+1)
  {
      m[i]=b[i]*(b[i]-1)/2;  
  }

  long long int ans=0;
  forl(i,1,n+1)
  { 
    ans=ans+m[i];
  }
long long int t;

  forl(i,1,n+1)
  { t=a[i];
    if(m[t]==0)
    {
      cout<<ans<<endl;
    }
    else if(m[t]==1)
    {
      cout<<ans-1<<endl;
      
    }
    else if(m[t]>1)
    {
        cout<<ans-m[t]+(b[t]-1)*(b[t]-2)/2<<endl;
    }
    
    
    
  }

  
/*   forl(i,1,n+1)
   {
       cout<<a[i]<<" ";
   }
   cout<<endl;
   
    forl(i,1,n+1)
   {
       cout<<b[i]<<" ";
   }
   cout<<endl;
    
     forl(i,1,n+1)
   {
       cout<<m[i]<<" ";
   }
   cout<<endl;
   
   cout<<ans;*/
    
    
	return 0;
}


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

const int N = 110;
typedef long long ll;
typedef std::pair <int, ll> pil;

std::vector <int> e[N];
int dep[N];

void dfs(int u, int dep, int fa){
    ::dep[dep] = std::max(::dep[dep], (int) e[u].size() - (fa ? 1 : 0));
    for (auto v : e[u]){
        if (v == fa) continue;
        dfs(v, dep + 1, u);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    if (n == 2){
        puts("1 2");
        return 0;
    }
    for (int i = 0, u, v; i < n - 1; ++ i){
        scanf("%d%d", &u, &v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    pil ans = {INT_MAX, 0};
    for (int i = 1; i <= n; ++ i){
        int max = 0;
        ll prod = 1;
        memset(dep, 0, sizeof(dep));
        dfs(i, 0, 0);
        for (int j = 0; j < N; ++ j){
            if (dep[j]){
                max = j;
                prod *= dep[j];
            }
        }
        ans = std::min(ans, {max + 2, prod});
    }
    for (int i = 1; i <= n; ++ i){
        for (auto u : e[i]){
            memset(dep, 0, sizeof(dep));
            if (i < u) continue;
            int max = 0;
            ll prod = 1;
            dfs(i, 0, u);
            dfs(u, 0, i);
            for (int j = 0; j < N; ++ j){
                if (dep[j]){
                    max = j;
                    prod *= dep[j];
                }
            }
            ans = std::min(ans, {max + 2, prod * 2});
        }
    }
    printf("%d %lld\n", ans.first, ans.second);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int n;  cin >> n;
  vector<int> v(n);
  int d[n];
  rep(i,0,n){
    d[i] = 0;
  }
  rep(i,0,n){
    cin >> v[i];
  }
  int cnt = 0;
  while(true){
    if(*max_element(all(v))==0) break;
    int i=0;
    while(i<n){
      if(v[i]==0) i++;
      else{
        cnt++;
        while(v[i]>0 && i<n){
          v[i]--;
          i++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  ll H;
  cin >> H;

  ll attacks = 0;
  ll monsters = 1;

  while (H>0) {
    H /= 2;
    attacks += monsters;
    monsters *= 2;
  }

  cout << attacks << endl;


  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
 
 
    void solve()
    {
        var S = cin.next;
        if ((S[0] == S[1] && S[1] == S[2]) || (S[1] == S[2] && S[2] == S[3]))
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>


int main(){
  int a, b;
  std::cin >> a >> b;
  if(std::min((int)std::ceil(12.5*(a+1.0)), 10*(b+1)) > std::max((int)std::ceil(12.5*a), 10*b))
  {
    std::cout << std::max((int)std::ceil(12.5*a), 10*b) << std::endl;
    return 0;
  }
  std::cout << -1 << std::endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		s := make([]string, n)
		for i := 0; i < n; i++ {
			s[i] = io.NextLine()
		}
		w := [5]int{5, 7, 5, 7, 7}
		ans := 0
	OUTER:
		for i := 0; i < n; i++ {
			cnt, wc := 0, 0
			for j := i; j < n; j++ {
				wc += len(s[j])
				if wc == w[cnt] {
					cnt++
					wc = 0
					if cnt == 5 {
						ans = i + 1
						break OUTER
					}
				} else if wc > w[cnt] {
					break
				}
			}
		}
		io.Println(ans)
	}
}

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

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

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

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

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

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

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

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

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll x;
  cin>>x;
  rep(i,361){
    if(!i) continue;
    if(i*x%360==0){
      COUT(i);
      return 0;
    }
  }
}

Measured memory_bytes: 3632
#include<stdio.h>

struct Dice
{
	int mae;
	int ue;
	int migi;
	int hidari;
	int sita;
	int usiro;
};

struct Dice ROLL_E(struct Dice dice)
{
	
	int a = dice.ue;
	dice.ue = dice.hidari;
	dice.hidari = dice.sita;
	dice.sita = dice.migi;
	dice.migi = a;
	
	return dice;
}

struct Dice ROLL_N(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.mae;
	dice.mae = dice.sita;
	dice.sita = dice.usiro;
	dice.usiro = a;
	
	return dice;
}
struct Dice ROLL_S(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.usiro;
	dice.usiro = dice.sita;
	dice.sita = dice.mae;
	dice.mae = a;
	
	return dice;
}
struct Dice ROLL_W(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.migi;
	dice.migi = dice.sita;
	dice.sita =dice. hidari;
	dice.hidari = a;
	
	return dice;
}

struct Dice ROLL_TOP(struct Dice dice,int top)
{
	if(top == dice.mae){
		dice =  ROLL_N(dice);
	}else if(top == dice.migi){
		dice =  ROLL_W(dice);
	}else if(top == dice.hidari){
		dice =  ROLL_E(dice);
	}else if(top == dice.usiro){
		dice =  ROLL_S(dice);
	}else if(top == dice.sita){
		dice =  ROLL_W(dice);
		dice =  ROLL_W(dice);
	}
	return dice;
}

struct Dice ROLL_FRONT(struct Dice dice,int front)
{
	dice = ROLL_TOP(dice,front);
	dice = ROLL_N(dice);
	return dice;
}

struct Dice ROLL(struct Dice dice,int front,int top)
{
	dice = ROLL_FRONT(dice,front);
	dice = ROLL_TOP(dice,top);
	return dice;
}

struct Dice scan()
{
	struct Dice dice;
	
	scanf("%d\n",&dice.ue);
	scanf("%d\n",&dice.mae);
	scanf("%d\n",&dice.migi);
	scanf("%d\n",&dice.hidari);
	scanf("%d\n",&dice.usiro);
	scanf("%d\n",&dice.sita);
	
	return dice;
}
int main()
{
	int i,n,front,top;
	struct Dice dice;

	dice = scan();
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d%d",&front,&top);
		dice = ROLL(dice,front,top);
		printf("%d\n",dice.migi);
	}
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
template <typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
int main()
{
    int N;
    std::cin >> N;
    ll W;
    std::cin >> W;
    std::vector<int> ind(N);
    std::vector<ll> v(N), w(N), m(N);
    for (int i = 0; i < N; i++) { std::cin >> v[i] >> w[i] >> m[i]; }
    std::iota(ind.begin(), ind.end(), 0);
    std::sort(ind.begin(), ind.end(), [&](const int i, const int j) { return v[i] * w[j] > v[j] * w[i]; });
    const int L = 50;
    const int LIMIT = L * L * L;
    std::vector<ll> subdp(LIMIT + 1, INF<ll>());
    subdp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = LIMIT; j >= 0; j--) {
            for (int k = 0; k <= std::min((ll)L, m[ind[i]]) and j + v[ind[i]] * k <= LIMIT; k++) {
                subdp[j + v[ind[i]] * k] = std::min(subdp[j + v[ind[i]] * k], subdp[j] + w[ind[i]] * k);
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i <= LIMIT; i++) {
        if (subdp[i] > W) { continue; }
        ll V = i, WRES = W - subdp[i];
        for (int i = 0; i < N; i++) {
            const ll use = std::min(std::max(0LL, m[ind[i]] - L), WRES / w[ind[i]]);
            V += use * v[ind[i]], WRES -= use * w[ind[i]];
        }
        ans = std::max(ans, V);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3944
using namespace std;
#include<bits/stdc++.h>
#define debug(x) clog<<#x<<" = "<<x<<'\n'
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define sz(c) ((int)c.size())
#define all(c) (c).begin(),(c).end()
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define fn "C"  /// ___FILE_NAME_HERE___
#define rep(c,it) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define __rep(c,it) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();it++)

template <class T,class U>
void maximize(T &x,U y)
{
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y)
{
    if(x > y)x=y;
}
template <class T>
T Abs(T x)
{
    return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x)
{
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD)
{
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD)
{
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD)
{
    return (ll)x*y%MOD;
}
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

const ll inf=1e18;
const int N=1e5+5;
int a[N];
ll s[N];
int n;
ll ans=inf;

ll calc(int val)
{
    fill(s+1,s+1+n,0);
    s[1]=val;
    ll ret=0;
    for(int i=2;i<=n;++i)
    {
        s[i]=s[i-1] + 1ll*a[i];
        if(s[i] * s[i-1] >= 0)
        {
            if(s[i] < 0)ret+=Abs(s[i])+1,s[i]=1;
            else if(s[i] > 0)ret+=s[i] + 1,s[i]=-1;
            else
            {
                ret++;
                if(s[i-1] < 0)s[i]=1;
                else s[i]=-1;
            }
        }
    }
    return ret;
}

void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    minimize(ans,min(calc(1) + Abs(1-a[1]),calc(-1) + Abs(-1-a[1])));
    if(a[1])minimize(ans,calc(a[1]));
    printf("%lld\n",ans);
}}

int main(void)
{

    task::solve();
}


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

#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define ll long long
#define mp make_pair
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define all(x)   (x.begin(),x.end())

const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
const int inf = 1e9 + 7;

int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}

int main()
{
	
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<int>dp(3);
for(int days=0;days<n;days++)
{
	vector<int>c(3),new_dp(3,0);
	for(int j=0;j<3;j++)
		cin>>c[j];
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{   if(i!=j)
			new_dp[j]=max(new_dp[j],dp[i]+c[j]);
		}
	}
	dp=new_dp;
	
}
cout<<max(dp[0],max(dp[1],dp[2]))<<'\n';
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
static const int MAX = 1000;

void trace(int data[], int n) {
  cout << data[0];
  for (int i = 1; i < n; i++) {
    cout << " " << data[i];
  }
  cout << endl;
}

void insertionSort(int A[], int N) {
  for (int i = 1; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

int main() {
  int data[MAX + 1];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> data[i];

  trace(data, n);
  insertionSort(data, n);
}

Measured memory_bytes: 3080
import sys
readline = sys.stdin.readline
V, E = map(int, readline().split())
g = [[] for i in xrange(V)]
cost = {}
to = [0]*V
for i in xrange(E):
    s, t, d = map(int, readline().split())
    g[s].append((t, d))
    cost[s,t] = d
    to[s] |= 1 << t
get = cost.get
INF = 10**9
ALL = 2**V-1
dp = {}
start = 0
def dfs(state, v):
    key = (state, v)
    if key in dp: return dp[key]
    if state == ALL:
        dp[key] = res = get((v, start), INF)
        return res
    dp[key] = res = min((dfs(state | (1 << t), t) + d for t, d in g[v] if not state & (1 << t))) if state & to[v] != to[v] else INF
    return res
res = dfs(1, 0)
print res if res<INF else -1

Measured memory_bytes: 26032