akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, l, a, b, p[100005], ans[2][100005], cur;
pi h, k;
bool diam[100005];
vector<int> adj[100005], v;

void dfs(int x, int par, int d) {
	k = max(k, pi(d, x));
	p[x] = par;
	for (auto it:adj[x]) {
		if (it == par) continue;
		dfs(it, x, d+1);
	}
}

int main() {
	fastio; cin >> n;
	FOR(i, 1, n-1) {
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1, -1, 0); swap(h, k);
	dfs(h.s, -1, 0);
	a = h.s, b = k.s; //endpoints of diam are a, b
	
	v.pb(adj[b].size()-1);
	diam[b] = 1;
	while (b != a) {
		b = p[b]; diam[b] = 1;
		v.pb(adj[b].size()-2);
		if (b == a) v.back()++;
	}
	FOR(i, 1, n) if (!diam[i]) {
		bool ok = false;
		for (auto it:adj[i]) if (diam[it]) ok = 1;
		if (!ok) {cout << -1; return 0;}
	}
	
	l = v.size();
	FOR(i, 1, n) ans[0][i] = ans[1][i] = i;
	FOR(i, 0, l-1) {
		if (v[i] == 0) continue;
		FOR(j, 0, v[i]-1) swap(ans[0][cur+i+1+j], ans[0][cur+i+1+j+1]);
		//shift cur + i + 1 to v[i] positions to the right
		cur += v[i];
	}
	reverse(all(v)); cur = 0;
	FOR(i, 0, l-1) {
		if (v[i] == 0) continue;
		FOR(j, 0, v[i]-1) swap(ans[1][cur+i+1+j], ans[1][cur+i+1+j+1]);
		//shift cur + i + 1 to v[i] positions to the right
		cur += v[i];
	}
	FOR(i, 1, n) if (ans[0][i] != ans[1][i]) {
		FOR(j, 1, n) cout << ans[(ans[0][i] < ans[1][i] ? 0 : 1)][j] << " ";
		return 0;
	}
	FOR(i, 1, n) cout << ans[0][i] << " ";
}


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

struct pos{
    int x;
    int y;
    int dis;
};

int main(){
    int w, h;
    while(cin >> w >> h, w != 0 && h != 0){
        int map[65][65];
        for(int i = 0; i < 65; i++){
            for(int j = 0; j < 65; j++){
                map[j][i] = 1;
            }
        }

        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                map[i*2-1][j*2-1] = 0;
            }
        }

        int l = 1;
        for(int i = 1; i <= h*2-1; i++){
            if(i % 2 == 1){
                for(int j = 1; j <= w-1; j++){
                    int input;
                    cin >> input;
                    map[l*2-1][j*2] = input;
                }
            }else{
                for(int j = 1; j <= w; j++){
                    int input;
                    cin >> input;
                    map[l*2][j*2-1] = input;
                }
                l++;
            }
        }

        queue<pos> q;
        map[1][1] = 1;
        pos p;
        p.x = 1;
        p.y = 1;
        p.dis = 1;
        q.push(p);
        int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
        while(!q.empty()){
            p = q.front();
            q.pop();
            for(int i = 0; i < 4; i++){
                pos p1 = p;
                p1.x += x1[i]; p1.y += y1[i];
                if(!map[p1.x][p1.y]){
                    //p1.x += x1[i]; p1.y += y1[i];
                    p1.dis++;
                    map[p1.x][p1.y] = p1.dis;
                    q.push(p1);
                }
            }
        }

        int ans = (map[h*2-1][w*2-1] + 1) /2;

        cout << ans << endl;

    }
}

Measured memory_bytes: 1232
//#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int main(){
  string s;
  cin >> s;
  
  if( s=="SUN" ){
    cout << 7;
  }else if( s=="MON" ){
    cout << 6;
  }else if( s=="TUE" ){
    cout << 5;
  }else if( s=="WED" ){
    cout << 4;
  }else if( s=="THU" ){
    cout << 3;
  }else if( s=="FRI" ){
    cout << 2;
  }else if( s=="SAT" ){
    cout << 1;
  }
  return 0;
}


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

using namespace std;

#define X first
#define Y second
#define ll long long
#define inf (ll)1e18
#define all(x) x.begin(), x.end()

const int MX = 200020;
const int N = 1000060;
const int mod = (int)1e9 + 7;

int n, m;
int in[555];
std::vector<int> g[555];
std::vector<int> topo_res;

void topo(){

	queue<int> q;
	for(int i = 1; i <= n; ++i){
		if(in[i] == 0){
			q.push(i);
		}
	}

	while(q.size()){
		int x = q.front(); q.pop();
		topo_res.push_back(x);
		for(auto y : g[x]){
			in[y]--;
			if(in[y] == 0)
				q.push(y);
		}
	}

}

bool test(int x){

	std::vector<int> res;
	queue<int> q;

	int inx[555];
	memcpy(inx, in, sizeof(in));

	if(inx[x] == 1){ // if it is part of one cycle, remove that cycle
		inx[x]--;
		q.push(x);
	}

	while(q.size()){
		int v = q.front(); q.pop();
		res.push_back(v);
		for(auto u : g[v]){
			if(u != x){ // ignore that edge that caused this cycle
				inx[u]--;
				if(inx[u] == 0)
					q.push(u);
			}
		}	
	}

	return (int) res.size() + (int) topo_res.size() == n;
}

int main(){
/*
     ___     ___
    (^_^)   (^_^)
   /( | )\ /( | )\
     | |     | |
*/
    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

  	int k;
  	cin >> k;

  	int a[k];
  	for(int i = 0; i < k; ++i){
  		cin >> a[i];
  	}

  	if(a[k - 1] != 2){
  		puts("-1");
  		return 0;
  	}

  	ll resL, resR;

  	ll l = 2, r = 1e18;
  	while(l <= r){
  		ll mid = (l + r) / 2;
  		ll N = mid;
  		for(int i = 0; i < k; ++i){
  			N = (N / a[i]) * a[i];
  		}
  		if(N >= 2){
  			r = mid - 1;
  		}
  		else{
  			l = mid + 1;
  		}
  	}

  	resL = l;

	l = 2, r = 1e18;
  	while(l <= r){
  		ll mid = (l + r) / 2;
  		ll N = mid;
  		for(int i = 0; i < k; ++i){
  			N = (N / a[i]) * a[i];
  		}
  		if(N > 3){
  			r = mid - 1;
  		}
  		else{
  			l = mid + 1;
  		}
  	}
  	
  	resR = r;

  	if(resL > resR) puts("-1");
  	else
  		cout << resL << " " << resR << endl;

	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
#include <numeric> //accumulate
using namespace std;

int main(){
    cout << fixed << setprecision(6);
    int h,n; cin >>h>> n;
    vector<int> o(n);
    for (int i = 0; i < n; i++)
    {
        cin >> o[i];
    }
    if(h <= accumulate(o.begin(),o.end(),0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3144
// A. 

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	int ans = 1<<30;
	for (int a = 1; a < n; ++a) {
		int sum = 0;
		for (char c : to_string(a)) {
			sum += c - '0';
		}
		for (char c : to_string(n - a)) {
			sum += c - '0';
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  vector<int> A(n);
  rep(i, n){
    cin >> A[i];
  }
  A.push_back(A[0] + k);
  int l = 0;
  rep(i, n){
    l = max(l, A[i + 1] - A[i]);
  }
  ans = k - l;
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>

using namespace std;


int main() {
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	if (A*B < C*D) {
		A = C;
		B = D;
	}
	cout << A*B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define f first
#define s second
using namespace std;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
	fast();
	ll h,n,ans=0;
	cin>>h>>n;
	while(n--){
		ll x;
		cin>>x;
		ans+=x;
	}
	if(ans>=h)cout<<"Yes";
	else
	cout<<"No";
}

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

int main(){
  string str;
  string kizyun = "abcdefghijklmnopqrstuvwxyz";
  vector<int> vec(kizyun.size(),0);
  bool chk = false;
  
  cin >> str;
  
  for(int i = 0; i < str.size(); i++){
    for(int j = 0; j < 26; j++){
      if(str.at(i) == kizyun.at(j)){
        vec.at(j) = 1;
      }
    }
  }
  
  for(int i = 0; i < vec.size(); i++){
    if(vec.at(i) == 0){
      cout << kizyun.at(i);
      chk = true;
      break;
    }
  }
  
  if(chk == false) cout << "None";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string Stones(vector<int> &v,int k)
{
    int dp[k+1];
    memset(dp,0,sizeof dp);
    for(int i=0;i<=k;i++)
    {
        for(auto jump: v)
        {
            if(jump > i)
                continue;
            if(dp[i - jump] == 0)
                dp[i] = 1;
        }
    }

    return dp[k]? "First": "Second";
}

int main()
{   
    int n,k,p;
    vector<int> v;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>p;
        v.push_back(p);
    }
    cout<<Stones(v,k);
    return 0;
}

Measured memory_bytes: 640
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, l; cin >> n >> l;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    int id = -1;
    rep(i, n - 1) {
        if(a[i] + a[i + 1] >= l) {
            id = i;
            break;
        }
    }
    if(id == -1) {
        cout << "Impossible" << endl;
        return;
    }
    cout << "Possible" << endl;
    rep(i, id) {
        cout << i + 1 << endl;
    }
    per(i, n - 1) {
        cout << i + 1 << endl;
        if(i == id) break;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 1664
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	String S = sc.next();

	int preans = 0;

	for(int i=0; i<N-1; i++){

	if(S.charAt(i)==S.charAt(i+1)){

	preans ++;

   }	

  }

	System.out.println(N-preans);

 }
}

Measured memory_bytes: 24264
#include <iostream>
using namespace std;
int main(void){

  int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x-r<0||y-r<0||x+r>W||y+r>H)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3088
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
flag=0
for i in range(X+1,Y+1):
  if max(x)<i and min(y)>=i:
    flag =1
print(['War','No War'][flag])

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		as[i] = tmp
	}
	bs := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		bs[i] = tmp
	}
	arr := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		tmp := as[i] - bs[i]
		arr[i] = tmp
		sum += tmp
	}
	if sum < 0 {
		fmt.Println("-1")
		return
	}
	sort.Sort(sort.IntSlice(arr))
	idx, cur, count := n - 1, 0, 0
	for i := 0; i < n; i++ {
		a := arr[i]
		if a >= 0 {
			break
		}
		cur += a
		for cur < 0 {
			aa := arr[idx]
			if aa < 0 {
				panic("err")
			}
			cur += aa
			count++
			idx--
		}
		count++
	}
	fmt.Println(count)
}

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

#define ARRAY_MAX 114514
typedef pair<long long int,long long int> P;

int main(){

    
    int n;
    cin >> n;
    vector<P> array(n);
    for(int i = 0;i < n;i++){
        cin >> array[i].first >> array[i].second;
    }
    int m = 0;
    long long int mini = array[0].first;
    for(int i = 0;i < n;i++){
        if(mini < array[i].first){
            m = i;
            mini = array[i].first;
        }
    }
    int ans = array[m].first + array[m].second;
    cout << ans << endl;


    return 0;
}

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

int main() {
    // input
    int N;
    cin >> N;

    // solve
    bool flag = false;
    if (N / 10 == 9) flag = true;
    if (N % 10 == 9) flag = true;

    // output
    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int count = 0;
    for (int i = 1; i <= N;i=i+2){
        count++;
    }
    if (count >= K){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int ans = 999;
    repi(i,S.size()-3){
        int x = stoi(S.substr(i,3));
        ans = min(ans, abs(753-x));
    }
    cout << ans << endl;
}

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

ll f(ll x)
{
    if(x==1) return 1;
  
    return f(x/2)*2 + 1;


}


int main()
{
  ll h;
  cin>>h;
   
  ll ans = f(h);
  
    cout<<ans<<endl;
    
    return 0;

}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, r int
	var op string

calc:
	for {
		fmt.Scan(&a)
		fmt.Scan(&op)
		fmt.Scan(&b)

		switch op {
		case "?":
			break calc
		case "+":
			r = a + b
		case "-":
			r = a - b
		case "*":
			r = a * b
		case "/":
			r = a / b
		}

		fmt.Println(r)
	}
}



Measured memory_bytes: 1116
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int w, h, maps[102][102];

inline bool check(int x, int y) {
	return x >= 0 && x < w && y >= 0 && y < h;
}

void dfs(int y, int x) {
	if (!check(x, y) || maps[y][x] != 0) return;

	maps[y][x] = 2;

	int hx, mx;
	if (y % 2 == 1) hx = x;
	else hx = x - 1;
	mx = hx + 1;

	REP(i, 2) {
		int d[] = { -1, 1 };
		dfs(y + d[i], hx);
		dfs(y + d[i], mx);
		dfs(y, x + d[i]);
	}
}

int main() {
	cin >> w >> h;
	REP(i, h) REP(j, w) scanf("%d", &maps[i + 1][j + 1]);
	w += 2; h += 2;
	
	dfs(0, 0);

	int ans = 0;
	FOR(i, 1, h - 1) FOR(j, 1, w - 1) if (maps[i][j] == 1) {
		int hx, mx;
		if (i % 2 == 1) hx = j;
		else hx = j - 1;
		mx = hx + 1;

		REP(k, 2) {
			int d[] = { -1, 1 };
			int ny = i + d[k];
			if (maps[ny][hx] == 2) ans++;
			if (maps[ny][mx] == 2) ans++;
			if (maps[i][j + d[k]] == 2) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1884
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


int ID(int a, int b)
{
    if (b < a) swap(a, b);
    return a * 10000 + b;
}

int main()
{
    int N;
    cin >> N;
    vector<queue<int>> A(N, queue<int>{});
    REP(i, N) REP(j, N - 1)
    {
        int a;
        cin >> a;
        A[i].emplace(ID(i, a - 1));
    }

    unordered_set<int> ms, m_erase;
    REP(i, N)
    {
        if (ms.count(A[i].front())) m_erase.insert(A[i].front());
        else ms.insert(A[i].front());
        A[i].pop();
    }
    int finished = 0;

    int ret = 1;
    while (true)
    {
        ret++;
        if (m_erase.empty())
        {
            puts("-1");
            return 0;
        }
        unordered_set<int> m_erase_new;
        for (auto p : m_erase)
        {
            int a = p % 10000, b = p / 10000;
            if (!A[a].empty()) (ms.count(A[a].front()) ? m_erase_new : ms).insert(A[a].front()), A[a].pop(), finished += A[a].empty();
            if (!A[b].empty()) (ms.count(A[b].front()) ? m_erase_new : ms).insert(A[b].front()), A[b].pop(), finished += A[b].empty();
        }
        m_erase = m_erase_new;
        if (finished == N)
        {
            cout << ret << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 20852
#include<cstdio>
#define rep(i, s, t) for(i = s; i <= t; ++i)

using namespace std;

int n, f[15][2];

int main() {
	int i, j, x;
	scanf("%d", &n);
	f[0][1] = 1;
	rep(i, 1, n) {
		scanf("%d", &x);
		rep(j, x-1, x+1)
			if(j & 1) {
				f[i][0] += f[i-1][0];
				f[i][1] += f[i-1][1];
			} else {
				f[i][0] += f[i-1][0] + f[i-1][1];
			}
	}
	printf("%d\n", f[n][0]);
	return 0;
}

Measured memory_bytes: 128
N, Q = map(int, input().split())
s = "_" + input() + "_"
td = [input().split() for _ in range(Q)]

td.reverse()
L_s = 0
R_s = N + 1
for i, j in enumerate(td):
    td[i][0], td[i][1] = j

    if td[i][1] == "R":
        if td[i][0] == s[R_s - 1]:
            R_s -= 1
        if td[i][0] == s[L_s]:
            L_s -= 1

    if td[i][1] == "L":
        if td[i][0] == s[R_s]:
            R_s += 1
        if td[i][0] == s[L_s + 1]:
            L_s += 1

print(max(0, R_s - L_s - 1))

Measured memory_bytes: 41204
#include<stdio.h>
int main(void) {
    char s[5];
    scanf("%s", s);

    if((s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
    || (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
    || (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]))
    printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
H,W=map(int,input().split())
S=[input() for i in range(H)]
A=[[0]*W for i in range(H)]
B=[[0]*W for i in range(H)]
for i in range(H):
    s=0
    t=0
    num=0
    while t<W:
        #print(s,t,num)
        if S[i][t]=='#':
            for k in range(s,t):
                A[i][k]=num
            num=0
            t+=1
            s=t
        else:
            t+=1
            num+=1
    for k in range(s,t):
        A[i][k] = num
for j in range(W):
    s=0
    t=0
    num=0
    while t<H:
        #print(s,t,num)
        if S[t][j]=='#':
            for k in range(s,t):
                B[k][j]=num
            num=0
            t+=1
            s=t
        else:
            t += 1
            num += 1
    for k in range(s,t):
        B[k][j] = num
#print(A)
#print(B)
ans=0
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            ans=max(ans,A[i][j]+B[i][j]-1)
print(ans)



Measured memory_bytes: 123608
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0) { break; }

		vector<vector<double> > dp(n, vector<double>(69, 0.0));

		dp[0][1] = 1.0;

		for (int i = 1; i < n; i++)
		{
			double t = 0.5;

			for (int j = 1; j < 69; j++)
			{
				dp[i][0] += dp[i - 1][j] * (1.0 - t); t *= 0.5;
			}

			t = 1.0;

			for (int j = 1; j < 69; j++)
			{
				dp[i][j] += dp[i - 1][j - 1] * t; t *= 0.5;
			}
		}

		double sum = 0;

		for (int i = 0; i < n; i++)
		{
			sum += (1 - dp[i][0]);
		}

		printf("%.49999f\n", sum);
	}

	return 0;
}

Measured memory_bytes: 60288
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val (n, s) = (sc.nextInt, sc.next.toCharArray)
  val (res, sta) = s.foldLeft(("", 0)) { case ((str, stack), next) =>
    next match {
      case '('               => (str + "(", stack + 1)
      case ')' if stack == 0 => (s"($str)", stack)
      case _                 => (str + ")", stack - 1)
    }
  }
  println(s"$res${")" * sta}")
}


Measured memory_bytes: 25536
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;
#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (n, h): (usize, usize)= (sc.input(), sc.input());
    let mut katana = vec![];
    for _ in 0..n {
        let (a, b): (isize, isize) = (sc.input(), sc.input());
        katana.push((a, 0)); katana.push((b, 1));
    }
    katana.sort_by(|a, b| b.cmp(a));

    let mut rest: isize = h as isize;
    let mut i = 0;
    let mut ans = 0;
    while rest > 0 {
        let cur = katana[i];
        if cur.1 == 0 {
            ans += (rest + cur.0 - 1) / cur.0;
            rest = 0;
        } else {
            ans += 1;
            rest -= cur.0;
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 9284
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
  long double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
	printf("%Lf\n", sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)));
  return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i=0; i<N; i++) cin >> S[i];
  map<string, int> memo; // 文字列とそれが書かれた回数
  for (int i=0; i<N; i++) {
    if (memo.count(S[i])) memo[S[i]]++;
    else memo[S[i]] = 1;
  }
  int maxi = 1;
  for (auto p: memo) {
    auto v = p.second;
    maxi = max(maxi, v);
  }
  for (auto p: memo) {
    auto k = p.first;
    auto v = p.second;
    if (v==maxi) cout << k << endl;
  }
}

Measured memory_bytes: 26752
fn main() {
    let n = read::<String>().chars().collect::<Vec<_>>()[0];
    let x = (n as u8 + 1) as char;
    println!("{}", x);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
        if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    else if(x==4||x==6||x==9||x==11){
        if(y==4||y==6||y==9||y==11){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    else if(x==2 && y==2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

const int MAX = 127;

int n, d;

void solve() {
	cin >> n >> d;
	int res = d;
	d ^= MAX;
	while(n-- > 1) {
		res -= (d ^ MAX);
		res += d;
		res += MAX;
		d ^= MAX;
	}

	cout << res << '\n';
}

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

	int tt; cin >> tt;
	while(tt--) solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    void solve(Scanner sc) {
        n = sc.nextLong();
        System.out.println(count(0));
    }

    long count(long a) {
        if (a > n) {
            return 0;
        }

        String as = String.valueOf(a);
        if (as.contains("7") && as.contains("5") && as.contains("3")) {
            return 1 + count(a * 10 + 7) + count(a * 10 + 5) + count(a * 10 + 3);
        }

        return count(a * 10 + 7) + count(a * 10 + 5) + count(a * 10 + 3);
    }
}


Measured memory_bytes: 24404
#include <stdio.h>

#define N 100
#define NIL -1
#define WHITE 0
#define BLACK 1
#define INF 1000000000

void prim(void);

int n, total = 0;
int A[N][N];

int main(){

  int i, j;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&A[i][j]);
      if(A[i][j] == NIL){
	A[i][j] = INF;
      }
    }
  }


  prim();

  return 0;
}


void prim(void){

  int u, i, v, mincost;
  int d[N], pi[N], color[N];

  for(u=0; u<n; u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = INF;
    for(i=0; i<n; i++){
      if((color[i] != BLACK) && (d[i] < mincost)){
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INF) break;

    color[u] = BLACK;

    for(v=0; v<n; v++){
      if(A[u][v] != INF){
	if((color[v] != BLACK) && (A[u][v] < d[v])){
	  pi[v] = u;
	  d[v] = A[u][v];
	}
      }
    }
  }
    for(i=0; i<n; i++){
      if(pi[i] != NIL){
	total += A[i][pi[i]];
      }
    }
  
  printf("%d\n", total);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
//const int MAXN = 200005;

int pw[25];

vector<int> get_imp(int lev, int layer) {
	if (lev <= 4) {
		if (lev == 3) return vector<int>({1, 0, 1});
		return vector<int>(lev, 1);
	}
	if (lev <= pw[layer]) {
		return get_imp(lev, layer - 1);
	}
	
	vector<int> tmp = get_imp(lev - pw[layer], layer - 1), res = tmp;
	while (res.size() + tmp.size() < lev) {
		res.push_back(0);
	}
	for (int x : tmp) res.push_back(x);
	return res;
}

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

	pw[0] = 1;
	for (int i = 1; i < 25; i++) {
		pw[i] = pw[i - 1] * 2;
	}
	
	int n, all = 1;
	cin >> n;
	vector<int> imp = get_imp(n, 20), a(n);
	for (int i = 0; i < n; i++) {
		char ch;
		cin >> ch;
		a[i] = ch - '0' - 1;
		if (a[i] == 1) {
			all = 0;
		}
	}
	
	int odd = 0;
	if (all) {
		for (int i = 0; i < n; i++) {
			a[i] /= 2;
			if (imp[i]) {
				odd ^= a[i] % 2;
			}
		}
		if (odd) {
			cout << 2 << '\n';
		}
		else {
			cout << 0 << '\n';
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			if (imp[i]) {
				odd ^= a[i] % 2;
			}
		}
		if (odd) {
			cout << 1 << '\n';
		}
		else {
			cout << 0 << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 11528
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n, m; cin >> n >> m;
    if (!n) break;
    V<> a(n); for (auto&& e : a) cin >> e;
    int res = -1;
    for (int i = 0; i < n; ++i) for (int j = 0; j < i; ++j) {
      if (a[i] + a[j] <= m) res = max(res, a[i] + a[j]);
    }
    cout << (res != -1 ? to_string(res) : "NONE") << '\n';
  }
}


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

int main() {
    int n;
    cin >>n;
    vector<int> S(n, 0);
    for (int i=0; i<n; i++)
        cin >>S.at(i);
    int q;
    cin >>q;
    vector<int> T(q, 0);
    for (int i=0; i<q; i++)
        cin >>T.at(i);
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    int is=0;
    int it=0;
    int SS=0;
    for(;;) {
        if (S.at(is)==T.at(it)) {
            SS++;
            it++;
        } else if (S.at(is)>T.at(it))
            it++;
        else
            is++;
        if (it==T.size())
            break;
        if (is==S.size())
            break;
    }
    cout <<SS <<endl;
    return 0;
}



Measured memory_bytes: 3148
n = int(input())
a = list(map(int, input().split()))
temp = [0]

for i in range(n):
    if a[i] == temp[-1] + 1:
        temp.append(a[i])

# print(temp)

if len(temp) > 1:
    print(n - len(temp) + 1)
else:
    print(-1)



Measured memory_bytes: 85840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin >> n >> m;
	string A[n],B[m],C[m];
	FOR(i,0,n)cin>>A[i];
	FOR(i,0,m)cin>>B[i];
	
	FOR(i,0,n-m+1){
		FOR(j,0,n-m+1){
			bool ans = true;
			FOR(k,0,m){
				FOR(l,0,m){
					if(A[k+i][j+l]!=B[k][l])ans = false;
				}
			}
			if(ans){
				cout << "Yes" << endl;
				return 0;
			}

		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
s = int(input())

x = s // 3

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans = 0
for i in range(x):
    Box = i + 1
    Nokori = s - 3 * Box
    ans_ = cmb(Nokori + Box - 1, Box - 1) 
    ans += ans_
print(ans % (10 ** 9 + 7))

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string ans;
    int dx = tx - sx,dy = ty - sy;
    ans += string(dy,'U')+string(dx,'R')+string(dy,'D')+string(dx,'L');
    ans += 'L';
    ans += string(dy+1,'U') + string(dx+1,'R');
    ans += 'D'; 
    ans += 'R'; 
    ans += string(dy+1,'D') + string(dx+1,'L');
    ans += 'U';
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

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

int main()
{
    int a, b;
    while (cin >> a >> b)
        cout << gcd(a, b) << " " << lcm(a, b) << endl;
}


Measured memory_bytes: 3040
N = int(input())

A = [1]
for _ in range(N):
    A.append(int(input()))

used = set()

i = 0
ans = 0
while True:
    a = A[i]

    if a == 2:
        print(ans)
        break

    if a in used:
        print(-1)
        break

    used.add(i)
    i = a
    ans += 1


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

vector<int> dfs(set<int> &used, int from, vector<vector<int>> &edges) {
    for (int to : edges[from]) {
        if (contain(used, to)) continue;
        used.insert(to);
        vector<int> k = dfs(used, to, edges);
        k.push_back(from);
        return k;
    }
    return {from};
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    set<int> used;
    used.insert(0);
    vector<int> v = dfs(used, 0, edges);
    vector<int> u = dfs(used, 0, edges);

    assert(u.back() == 0);
    u.pop_back();
    reverse(u.begin(), u.end());

    cout << v.size() + u.size() << endl;

    for (int t : v) cout << t + 1 << ' ';
    for (int t : u) cout << t + 1 << ' ';
    cout << endl;
}


Measured memory_bytes: 19964
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        Console.WriteLine(n * (n - 1) / 2 + m * (m - 1) / 2);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
bool good[105];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int x, n;
	cin>>x>>n;
	memset(good, false, sizeof good);
	for(int i=1;i<=n;i++){
		int y;
		cin>>y;
		good[y]=true;
	}
	int l, r;
	for(int i=x;i>=0;i--){
		if(!good[i]){
			l=i;
			break;
		}
	}
	for(int i=x;i<=101;i++){
		if(!good[i]){
			r=i;
			break;
		}
	}
	if(r-x < x-l) cout<<r;
	else cout<<l;
}

Measured memory_bytes: 3648
#include <iostream>
#define INF 1e9
using namespace std;

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0)break;
		int dp[(1<<n)];
		int a[n][n+1];
		for(int i = 0;i < n;i++){
			for(int j = 0;j <= n;j++){
				cin >> a[i][j];
			}
		}
		for(int i = 0;i < (1<<n);i++){
			dp[i] = INF;
		}
		dp[0] = 0;
		for(int i = 0;i < (1<<n);i++){
			for(int j = 0;j < n;j++){
				if((i & (1<<j)) != 0)continue;
				dp[i+(1<<j)] = min(dp[i] + a[j][0],dp[i+(1<<j)]);
				for(int k = 0;k < n;k++){
					if((i & (1 << k)) == 0)continue;
					dp[i + (1<<j)] = min(dp[i] + a[j][k+1],dp[i+(1<<j)]);
				}
			}
		}
		cout << dp[(1<<n)-1] << endl;
	}
	return 0;
}

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

int diff(int *a, int *b) {
    return *a > *b ? *a - *b : *b - *a;
}

int main() {
    int n;
    cin >> n;
    int *a;
    a = (int*)malloc(sizeof(int)*n);
    for (int i = 0; i < n; i++) {
        cin >> *(a + i);
    }
    int dp[n];
    dp[0] = 0; // if you dont move you burn nothing
    dp[1] = abs(*a - *(a + 1));

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 2] + diff(a + i, a + i - 2), dp[i - 1] + diff(a + i, a + i - 1));
    }

    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 3928
while 1:
    s = raw_input().replace("north","0").replace("west","1")
    if s == "#": break

    u = 90*int(s[-1])
    d = 1
    s = s[:-1]
    while s:
        if   s[-1] == "0": u = 2*u-90
        elif s[-1] == "1": u = 2*u+90
        d *= 2
        s = s[:-1]

    while u%2 == 0 and d > 1:
        u /= 2
        d /= 2
    print u if d == 1 else "%d/%d"%(u,d)

Measured memory_bytes: 4228
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            StringBuilder sb = new StringBuilder();
            int n = in.nextInt();
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) {
                ar[i] = in.nextInt();
            }
            Arrays.sort(ar);
            ArrayList<Integer> rec = new ArrayList();
            for (int i = 0; i < n - 1; i++) {
                if (ar[i] == ar[i + 1]) {
                    rec.add(ar[i]);
                    i++;
                } else {
                    // nop
                }
            }
            Collections.sort(rec, Comparator.reverseOrder());
            out.println(rec.size() >= 2 ? (long) rec.get(0) * rec.get(1) : 0);
        }

    }
}



Measured memory_bytes: 49928
#include "bits/stdc++.h"

using namespace std;

const int MOD=1000000007;

int main(){
  int N;
  cin>>N;
  vector<int>v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  long long int ans=1;
  int index =0;
  for(int i=0;i<N;i++){
    while(index+1<N&&(v[index]+1)/2>index-i)index++;
    ans*=index+1-i;
    ans%=MOD;
  }
  cout<<ans<<endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int s[8];
int main()
{

  REP(i, 40){
    double a, b;
    cin >> a >> b;
    if (a >= 1.1) s[0]++;
    else if (a >= 0.6) s[1]++;
    else if (a >= 0.2) s[2]++;
    else s[3]++;
    if (b >= 1.1) s[4]++;
    else if (b >= 0.6) s[5]++;
    else if (b >= 0.2) s[6]++;
    else s[7]++;
  }
  REP(i, 4) cout << s[i] << " " << s[i + 4] << endl;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  if(a>=1) cout<<"Positive";
  else{
    if(b>=0) cout<<"Zero";
    else{
      if((abs(a)-abs(b)+1)%2==0) cout<<"Positive";
      else cout<<"Negative";
    }
  }
  cout<<"\n";
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split(' ')))

def count_manipulation(a_list, start):
    assert start in (0, 1)
    sum = 0
    count = 0
    for i, a in enumerate(a_list):
        sum += a
        if i % 2 == start:
            if sum > 0:
                continue
            else:
                diff = 1 - sum
                count += diff
                sum += diff
        else:
            if sum < 0:
                continue
            else:
                diff = sum - (-1)
                count += diff
                sum -= diff
    return count

count_plus = count_manipulation(a_list, 0)
count_minus = count_manipulation(a_list, 1)
print(min(count_plus, count_minus))


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

using namespace std;

int main()
{
    int a[6],i,minn=9,chk,c,ans=0;
    for(i=0;i<5;i++){
        cin>>a[i];
    }
    for(i=0;i<5;i++){
        chk=a[i]%10;
        if(chk!=0 && chk<minn){
            minn=chk;
            c=i;
        }
    }
    for(i=0;i<5;i++){
        if(i!=c){
            ans+=(a[i]+9)/10*10;
        }
    }
    cout<<ans+a[c];
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
/* AtCoder Beginner Contest 106 (๑•﹏•๑｀) */

int main(){
	int N;
	SCD(N);
	int divs = 0;
	int ans = 0;

	FORq(j,1,N){
		if (j % 2 == 0) continue;
		divs = 0;

		FORq(i,1,j){
			if (j % i == 0){
				divs++;
			}
		}
	
		if (divs == 8){
			ans++;
		}

	}

	PRINTD(ans);
}

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

int main(void)
{
    uint32_t a;

    std::cin >> a;

    for (uint32_t i = 0; i < a; ++i) {
        char c;
        std::cin >> c;
        if (c == 'Y') {
            std::cout << "Four" << std::endl;
            return 0;
        }
    }

    std::cout << "Three" << std::endl;

    return 0;
}

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

int W, H, sx, sy, gx, gy, INF = (1 << 20);
int field[20][20];
int dx[4] = {0, 1, 0, -1},
    dy[4] = {-1, 0, 1, 0};

/*
void print_field(int x, int y, int d, int life)
{
  cout << "life --- " << life << endl;
  char c = '-';
  if (d == 0) {
    c = '^';
  } else if (d == 1) {
    c = '>';
  } else if (d == 2) {
    c = 'v';
  } else if (d == 3) {
    c = '<';
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (x == j && y == i) {

        cout << c <<  " ";
      } else {
        cout << field[i][j] << " ";

      }
    }
    cout << endl;
  }
}
*/

int dfs(int x, int y, int lifetime)
{
  if (lifetime == 0) {
    return INF;
  }

  int ret = INF;
  for (int k = 0; k < 4; k++) {

    int cx = x, cy = y;
    int nx = cx + dx[k], ny = cy + dy[k];
    // print_field(cx, cy, k, lifetime);

    // この方向へは滑らせることができない
    if (nx < 0 || nx >= W || ny < 0 || ny >= H || field[ny][nx] == 1) {
      continue;
    }

    // 移動
    bool moved = false;
    while (true) {
      cx = nx; cy = ny;
      nx = cx + dx[k]; ny = cy + dy[k];

      // ゴール
      if (field[cy][cx] == 3) {
        return (10 - (lifetime - 1)); 
      }

      // フィールド外に滑った
      if (nx < 0 || nx >= W || ny < 0 || ny >= H) {
        break;
      }

      // 壁にぶつかった　
      if (field[ny][nx] == 1) {
        field[ny][nx] = 0;
        moved = true;
        break;
      }
    }

    if (!moved) {
      continue;
    }

    ret = min(ret, dfs(cx, cy, lifetime - 1));

    // 変更したフィールドを元に戻す
    field[ny][nx] = 1;
  }

  return ret;
}

void solve()
{
  int res = dfs(sx, sy, 10);
  if (res == INF) {
    cout << "-1" << endl;
  } else {
    cout << res << endl;
  }
}

int main()
{
  while (cin >> W >> H && (W && H)) {

    // read
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> field[i][j];
        if (field[i][j] == 2) {
          sy = i; sx = j;
          field[i][j] = 0;
        } else if (field[i][j] == 3) {
          gy = i; gx = j;
        }
      }
    }

    solve();
  }
}

Measured memory_bytes: 868
#include <stdio.h>

int main(void)
{
	int h, n, a;
	int sum = 0;
	int i[100000];

	scanf("%d %d", &h, &n);

	for (a = 0; a < n; a++) {
		scanf("%d", &i[a]);
		sum = sum + i[a];//必殺技の合計値を求める
	}

	if (h <= sum) //必殺技の合計値より敵の体力が低い場合
	{
		printf("Yes\n");
	}
	else //必殺技の合計値より敵の体力が多い場合
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;


int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string S;
  stack <char> ans;
  cin >> S;
  numa(c, S){
    if (c == 'B') {
      if (!ans.empty()) {
        ans.pop();
      }
    }else{
      ans.push(c);
    }
  }
  string output;
  while(!ans.empty()){
    output += ans.top();
    ans.pop();
  }
  reverse(ALL(output));
  cout << output << endl;
  return 0;
}



Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n;
    String a, b;
    char[] ca, cb;
    int i, j, d;

    n = sc.nextInt();
    for(i = 0;i < n;i++){
      a = sc.next(); b = sc.next();
      d = a.length() + 1;
      if(d < b.length() + 1)d = b.length() + 1;
      ca = new char[d]; cb = new char[d];

      for(j = 0;j < a.length();j++)
        ca[j] = (char)(a.charAt(a.length() - j - 1) - '0');
      for(j = 0;j < b.length();j++)
        cb[j] = (char)(b.charAt(b.length() - j - 1) - '0');

      for(j = 0;j < d - 1;j++){
        ca[j] += cb[j];
        if(ca[j] > 9){
          ca[j + 1]++; ca[j] %= 10;
        }
      }

      if(d > 81 || (d == 81 && ca[d - 1] != 0))out.println("overflow");
      else{
        for(j = 0;j < d;j++)if(j != 0 || ca[d - j - 1] != 0)
          out.print((char)(ca[d - j - 1] + '0'));
        out.println();
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26148
#include<stdio.h>

int main(void){

	int a, b;
	int s;
	int ans = -1;

	scanf("%d %d", &a, &b);

	for(int i = 0; s < b; i++){
		ans++;
		s = 1 + a * i - ans;
	}

	printf("%d", ans);

	return 0;

}

Measured memory_bytes: 128