akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <iterator>
#include <algorithm>
#include <typeinfo>
#include <cstdlib>

typedef long long lint;

using namespace std;

void showIntArray(lint a[], lint n);

#include <iostream>
#include <string>

int main() {
  string s;
  cin >> s;
  // char s[4];
  // for (int i = 0; i < 4; i++) {
  //   cin >> s[i];
  // }

  int s12 = stoi(s.substr(0, 2));
  int s34 = stoi(s.substr(2, 2));

  if (1 <= s12 && s12 <= 12 && 1 <= s34 && s34 <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (0 <= s12 && s12 <= 99 && 1 <= s34 && s34 <= 12) {
    cout << "YYMM" << endl;
  } else if (0 <= s34 && s34 <= 99 && 1 <= s12 && s12 <= 12) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

void showIntArray(lint a[], lint n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}


Measured memory_bytes: 256
t = int(input())
for i in range(t):
  h, w = map(int, input().split())
  mp = [list("#" + input() + "#") for _ in range(h)]
  mp.insert(0, ["#"] * (w + 2))
  mp.append(["#"] * (w + 2))
  for y in range(h + 2):
    for x in range(w + 2):
      if mp[y][x] == ">":
        sx, sy, sd = x, y, 0
      if mp[y][x] == "^":
        sx, sy, sd = x, y, 1
      if mp[y][x] == "<":
        sx, sy, sd = x, y, 2
      if mp[y][x] == "v":
        sx, sy, sd = x, y, 3
  mp[sy][sx] = "."
  n = int(input())
  s = input()
  vec = ((1, 0), (0, -1), (-1, 0), (0, 1))
  dic = {"R":0, "U":1, "L":2, "D":3}
  tank = {0:">", 1:"^", 2:"<", 3:"v"}
  for c in s:
    if c == "S":
      dx, dy = vec[sd]
      nx, ny = sx, sy
      while mp[ny][nx] not in ("#", "*"):
        nx += dx
        ny += dy
      if mp[ny][nx] == "*":
        mp[ny][nx] = "."

    else:
      sd = dic[c]
      dx, dy = vec[sd]
      if mp[sy + dy][sx + dx] == ".":
        sx += dx
        sy += dy

  mp[sy][sx] = tank[sd]
  for j in range(1, h + 1):
    print("".join(mp[j][1:-1]))
  if i != t - 1:
    print()


Measured memory_bytes: 5636
n = int(input())
a = list(map(int, input().split()))
ans = 1000
stock = 0
for i in range(n-1):
    if a[i+1] > a[i]:
        buy = ans//a[i]
        stock += buy
        ans -= buy*a[i]
    else:
        ans += stock*a[i]
        stock = 0

ans += stock*a[-1]
print(ans)


Measured memory_bytes: 9176
n, m = gets.split.map(&:to_i)
values = gets.split.map(&:to_i)
total_v = values.inject(:+)
count = 0

values.each do |v|
  if v >= total_v.to_f / (4 * m)
    count += 1
  end
end

if count >= m
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = Read();
        var m = Read();
        int[] a = new int[n];
        int[] numCount = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = Read() - 1;
            numCount[a[i]]++;
        }
        long currentChange = 0;
        int[] coveredCount = new int[n];
        for (int i = 0; i < numCount.Length; i++)
        {
            for (int j = 0; j < numCount[i]; j++)
            {
                if (i - j < 0 || 1 <= coveredCount[i - j]++)
                {
                    currentChange++;
                }
            }
        }

        for (int i = 0; i < m; i++)
        {
            var x = Read() - 1;
            var y = Read() - 1;
            numCount[a[x]]--;
            if (a[x] - numCount[a[x]] < 0 || 1 <= --coveredCount[a[x] - numCount[a[x]]])
            {
                currentChange--;
            }
            a[x] = y;
            if (y - numCount[y] < 0 || 1 <= coveredCount[y - numCount[y]]++)
            {
                currentChange++;
            }
            numCount[y]++;
            Console.WriteLine(currentChange);
        }
    }

    static readonly TextReader In = Console.In;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static int Read()
    {
        int res = 0;
        int next = In.Read();
        while (48 > next || next > 57) next = In.Read();
        while (48 <= next && next <= 57)
        {
            res = res * 10 + next - 48;
            next = In.Read();
        }
        return res;
    }
}


Measured memory_bytes: 20572
from collections import defaultdict

n, k = map(int, input().split())
*a, = map(int, input().split())
a = [a[i] - 1 for i in range(n)]
ans = 0

if k <= n:
    i = 0
    while(k > 0):
        ans = a[i]
        i = a[i]
        k -= 1
        # print(ans + 1)
    ans += 1

else:
    # 周期の場所をチェック
    start_period = 1
    period_i = -1
    d = defaultdict(int)
    d[0] = 1
    i = 0
    count = 1
    while(1):
        # print(f'i = {i}, count = {count}')
        if a[i] in d.keys():
            period_i = count
            start_period = d[a[i]]
            break

        d[a[i]] = count + 1
        i = a[i]
        count += 1
        
    # 逆引き
    d_r = {i:k for k, i in d.items()}
    # print('d: ', d)
    # print('d_r: ', d_r)
    # print('period_i:', period_i)
    # print('start_period:', start_period)
    # print(f'{k - (start_period - 1)}')
    # print(f'{(k - (start_period - 1)) % (period_i - start_period + 1)}')
    # print('d_r[start_period]: ', d_r[start_period])
    # print(d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))])
    ans = d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))] + 1
    
    
print(ans)

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

int main(){	
	string a;
	cin>>a;
	int c=0;
	for(int i = 0; i<4; i++){
		if(a[i]==a[i+1] && a[i] == a[i+2]){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

//ghghg 
//ghghr

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string str;
    cin >> str;
    LL ans = 0;
    vector<vector<LL>> uku;
    vector<LL> now;
    for(int a = 0;a < str.size();a++){
        if(str.at(a) == 'A'){
            now.push_back(1);
        }else if(str.at(a) == 'B' & a != str.size()-1){
            if(str.at(a+1) == 'C'){
                now.push_back(2);
                a++;
            }else{
                uku.push_back(now);
                now.clear();
            }
        }else{
            uku.push_back(now);
            now.clear();
        }
    }
    uku.push_back(now);
    for(auto a : uku){
     //   LL A = count(a.begin(),a.end(),1);
     //   LL B = count(a.begin(),a.end(),2);
        int nowA = 0;
    //    int nowB = 0;
        for(int i = 0;i < a.size();i++){
          //  cout<<a.at(i)<<" ";
            if(a.at(i) == 2){
                ans += i-nowA;
                nowA++;
            }
        }
    //    cout<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8692
# include <bits/stdc++.h>
# define rr
# define int long long
const int N=200010,INF=0x3f3f3f3f;
int A[N],B[N];
int n;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
signed main(void){
	n=read();
	for(rr int i=1;i<=n;++i){
		A[i]=read(),B[i]=read();
	}
	std::sort(A+1,A+1+n);
	std::sort(B+1,B+1+n);
	if(n%2){
		printf("%lld",B[n/2+1]-A[n/2+1]+1);
		return 0;
	}else{
		double x=(A[n/2]+A[n/2+1])/2.0,y=(B[n/2]+B[n/2+1])/2.0;
		printf("%lld",(int)((y-x)*2+1));
		return 0;
	}
	return 0;
}


Measured memory_bytes: 6892
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		char c = nc();
		c++;
		out.println(c);
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 20180
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,k,ans=0,rans,pos,have=0;
vector <pii> v;
bool vis[100010];
priority_queue <LL,vector <LL>,greater <LL> > q;

bool cmp(pii a,pii b)
{
	return a.fi>b.fi;
}

int main()
{
	cin>>n>>k;
	rep(i,n)
	{
		LL t,d;
		cin>>t>>d;
		v.pb({d,t});
	}
	sort(v.begin(),v.end(),cmp);
	rep(i,n)
	{
		if(!vis[v[i].se])
		{
			vis[v[i].se]=true;
			ans+=v[i].fi;
			//cout<<v[i].fi<<endl;
			have++;
		}
		else ans+=v[i].fi,q.push(v[i].fi);
		if(i==k-1)
		{
			pos=i;
			break;
		}
	}
	rans=ans+sqr(have);
	for(int i=pos+1;i<n;i++)
	{
		if(q.empty()) break;
		if(vis[v[i].se]) continue;
		vis[v[i].se]=true;
		ans=ans-q.top()+v[i].fi;
		q.pop();
		have++;
		rans=max(rans,ans+sqr(have));
	}
	cout<<rans<<endl;
	rt0;
}

Measured memory_bytes: 2672
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin >> a >> b >> c;
    if(c<=b/a){
        cout << c << endl;
        return 0;
    }
    cout << b/a << endl;
    return 0;
}

Measured memory_bytes: 3608
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;

    let rec loop i mx mi =
        if i = n - 1 then mx - mi else
            if a.(i) >= 0 then loop (i + 1) mx (mi - a.(i))
                          else loop (i + 1) (mx - a.(i)) mi
    in
    Printf.printf "%d\n" @@ loop 1 a.(n - 1) a.(0);

    let rec loop i mx mi =
        if i = n - 1 then Printf.printf "%d %d\n" mx mi else
            if a.(i) >= 0 then (Printf.printf "%d %d\n" mi a.(i); loop (i + 1) mx (mi - a.(i)))
                          else (Printf.printf "%d %d\n" mx a.(i); loop (i + 1) (mx - a.(i)) mi)
    in
    loop 1 a.(n - 1) a.(0)
)

Measured memory_bytes: 6756
N = int(input())
A = [int(i) for i in input().split()]

L = [0 for i in range(9)] 

for i in A:
    if 1 <= i <= 399:
        L[0] += 1
    if 400 <= i <= 799:
        L[1] += 1
    if 800 <= i <= 1199:
        L[2] += 1
    if 1200 <= i <= 1599:
        L[3] += 1
    if 1600 <= i <= 1999:
        L[4] += 1
    if 2000 <= i <= 2399:
        L[5] += 1
    if 2400 <= i <= 2799:
        L[6] += 1
    if 2800 <= i <= 3199:
        L[7] += 1
    if 3200 <= i:
        L[8] += 1
        
count_0 = L[0:8].count(0)
count_not_0 = 8 - count_0
count_strong = L[8]

if count_not_0 == 0:
    if count_strong >= 1:
        print(1, count_strong,)
    else:
        print(0, 0)
else:
    if count_strong == 0:
        print(count_not_0, count_not_0)
    else:
        print(count_not_0, count_not_0 + count_strong)

Measured memory_bytes: 3064
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

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

    ll h, w, a, b;
    in >> h >> w >> a >> b;
    ll s[h][w] = {};
    REP(i, h){
        REP(j, w){
            if(i < b && j >= a){
                s[i][j] = 1;
            }
            if(i >= b && j < a){
                s[i][j] = 1;
            }
        }
    }
    REP(i, h){
        REP(j, w){
            out << s[i][j];
        }
        out << "\n";
    }
}


Measured memory_bytes: 9088
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;


class A {
	string s;
public:
	A()
	{
		cin >> s;
	}
	void solve()
	{
		int ans{ 0 };

		REP(i, SZ(s))
			if (s[i] == '+')
				ans++;
			else
				ans--;

		cout << ans << endl;

	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<queue>
using namespace std;
int main(){
    long N,M;
    scanf("%ld",&N);
    scanf("%ld",&M);
    std::priority_queue<long> que;
    for(long i=0;i<N;i++){
        long tmp;
        scanf("%ld",&tmp);
        que.push(tmp);
    }

    long tmp;
    for(long i=0;i<M;i++){
        tmp = que.top();
        que.pop();
        que.push(tmp/2);
    }
 
    long long ans = 0;

    for(long i=0;i<N;i++){
        ans += que.top();
        que.pop();
    }
 
    printf("%ld\n", ans);
 
    return 0;
}

Measured memory_bytes: 1400
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = LI()
acc = [0] + list(accumulate(A))
L = []
for i in range(n):
    for j in range(i + 1, n + 1):
        L += [acc[j] - acc[i]]

ans = 0
for l in range(max(L).bit_length() - 1, -1, -1):
    new_L = []
    for e in L:
        if e >> l & 1:
            new_L += [e]
    if len(new_L) >= k:
        ans |= 1 << l
        L = new_L

print(ans)















Measured memory_bytes: 67136
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
long long ans[55];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    long long k;
    cin>>k;
    long long t=k/50;
    int i;
    int n=50;
    printf("%d\n",n);
    for (i=0;i<n;i++)
    {
        ans[i]=i+t;
    }
    for (i=0;i<k%50;i++)
    {
        ans[50-i-1]++;
    }
    for (i=0;i<50;i++)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
} 


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

int main() {
  int N, K;
  long int x;
  long int y=1000000000;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i=0; i< N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  for(int i=0; i< N-K+1; i++) {
    x=vec.at(i+K-1)-vec.at(i);
    y=min(x,y);
  }
  cout << y << endl;
}


Measured memory_bytes: 640
'use strict';
process.stdin.on('data', function(chunk) {
  
  var inputs = chunk.toString().trim().split('\n');
  var cols = inputs.filter(function(v) {
    return v !== '0 0';
  })
  .map(function(v) {
    return v.split(' ')
          .map(Number)
          .sort(function(a ,b) {
            return a - b;
          })
          .join(' ');
  })
  .join('\n');
  
  console.log(cols);
  
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

int n, N, S, W, E;
char a[1005];

int main() {
	scanf("%s", a + 1);

	n = strlen(a + 1);

	for(int i = 1; i <= n; i++) {
		if(a[i] == 'N')
			N++;

		else if(a[i] == 'S')
			S++;

		else if(a[i] == 'E')
			E++;

		else W++;
	}

	if((N >= 1 && S == 0) ||
		(N == 0 && S >= 1) ||
		(E >= 1 && W == 0) ||
		(E == 0 && W >= 1))
			printf("No\n");

	else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
from collections import deque
#import numpy as np


#main
H,W=map(int,input().split())
S=[[] for a in range(H)]
for a in range(H):
    s=input()
    for b in s:
        S[a].append(b)
ans=0
for i in range(H):
    for j in range(W):
        if(S[i][j]=='#'):continue
        cost=[[-1 for b in range(W)] for a in range(H)]
        cost[i][j]=0
        Q=deque([])
        Q.append([i,j])
        
        while len(Q)>0:
            now=Q.popleft()
            dx=[-1,0,1,0]
            dy=[0,1,0,-1]
            for a in range(4):
                x=now[1]+dx[a]
                y=now[0]+dy[a]
                if(x>=0 and x<W and y>=0 and y<H and S[y][x]=='.' and cost[y][x]==-1):
                    cost[y][x]=cost[now[0]][now[1]]+1
                    Q.append([y,x])
        for b in range(H):
            for a in range(W):
                ans=max(ans,cost[b][a])
        
print(ans)



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

ans = 4
pre = 1
prepre = 2

if n == 1:
    ans = 1
elif n == 2:
    ans = 3
elif n == 3:
    ans = 4
else:
    for n in range(n - 3):
        ans += pre + prepre
        a = prepre
        prepre = pre
        pre = pre + a

print(ans)


Measured memory_bytes: 2940
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
n = ip()                                     #入力整数1つ
#n,q= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#b = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
one = 0
two = 0
four = 0
leftover = 0
for i in range(n):
    if a[i]%2: one+=1
    elif a[i]%4==0:four+=1
    else: two+=1
if one==1:
    if four==0:j(0)
    if one == four: leftover = 1
    if two%2:
        if leftover==0:
            j(0)
        else:j(1)
    else: j(1)

if one-1 > four:j(0)
else :
    if one==four:leftover=1
    if two%2:
        if leftover==0:
            j(0)
        else:j(1)
    else: j(1)

Measured memory_bytes: 24272
#include <iostream>
#include <algorithm>

using namespace std;


static const int INF = (int)1e9;
static const int N=(int)1e5;

int gcd(int x, int y) //最大公約数
{
    int temp;
    while (y != 0) {
        temp = y;
        y = x % y;
        x = temp;


    }
    return x;
}

int main()
{
	int n;
    int ans=0;
    int A[N+1];
    int dpl[N+2],dpr[N+2];

    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> A[i+1];
    }

    dpl[0]=A[1];
    dpr[n+1]=A[n];

    for(int i=1;i<n;i++){
        dpl[i]=gcd(dpl[i-1],A[i]);

        dpr[n+1-i]=gcd(dpr[n+2-i],A[n+1-i]);
    }

    for(int i=1;i<=n;i++){
        if(i==1){ans=max(ans,dpr[2]);}
        else if(i==n){ans=max(ans,dpl[n-1]);}
        else{ans=max(ans,gcd(dpl[i-1],dpr[i+1]));}
    }

    cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <set>

using namespace std;

void solve()
{
	int Q;
	cin >> Q;
	while(Q--)
	{
		int N;
		cin >> N;
		int count = 0;
		set<int> isExist;
		while(true)
		{
			if(N < 10)
			{
				cout << count << endl;
				break;
			}
			int digit = 0;
			int NBuf = N;
			while(NBuf)
			{
				NBuf /= 10;
				++digit;
			}
			int max = 0;
			int a = 10;
			for(int i = 1; i < digit; ++i)
			{
				int left = N / a;
				int right = N % a;
				if(left * right > max)
				{
					max = left * right;
				}
				a *= 10;
			}
			if(isExist.find(max) == isExist.end())
			{
				isExist.insert(max);
			}
			else
			{
				cout << -1 << endl;
				break;
			}
			N = max;
			++count;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, m;
    cin >> n >> m;
    vector<vi> g(n);

    fo(i, m) {
        int a, b;
        cin >> a >> b;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);
    }

    fo(i, n) {
        cout << g[i].size() << 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;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, a, b;
  cin >> x >> a >> b;
  if (a >= b)
    cout << "delicious" << endl;
  else if (b-a <= x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
  return 0;
}

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

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

#define REPR(i,n) for(int i =n; i >=0; --i)

#define _REP(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

using namespace std;

int main(){
    bool f = false;
    int n;cin >> n;
    _REP(i,1,10){
        _REP(j,1,10){
            if(n == i*j)f = true;
        }
    }
    if(f)cout <<"Yes" << endl;
    else cout << "No" << endl; 

    return 0;
}

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


int main(){
  
  ll N, M;
  int h, a, b, ans = 0;
  cin >> N >> M;
  vector<int>H(N);
  vector<bool>Good(N, true);
  rep(i, N){
    cin >> h; 
    H[i] = h;
  }
  
  vector<P>Road(M);
  rep(i, M){
    cin >> a >> b;
    P tempP(a, b);
    //cout << tempP.first << " " << tempP.second << endl;
    Road[i] = tempP;
  }
  
  rep(i, M){
    //cout << "first = " << Road[i].first << " " << "second = " << Road[i].second << endl;
    //cout << "height 1 = " << H[Road[i].first - 1 ] << endl;
    //cout << "height 2 = " << H[Road[i].second - 1 ] << endl;
    if(H[Road[i].first - 1 ] <= H[Road[i].second -1 ]){
      Good[Road[i].first - 1] = false;
    }
    if (H[Road[i].first -1 ] >= H[Road[i].second -1 ])
    {
      Good[Road[i].second - 1] = false;
    }
  }
  rep(i, N){
   //cout << "Good[i]" << Good[i] << endl;
   if(Good[i] == true){
     ans++;
   }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    while(1){
        string n;
        cin >> n;
        if(n=="0") break;

        int ans=0;
        for(int i=0; i<(int)n.length(); i++){
            ans += n[i]-'0';
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <utility>
#include <queue>

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

using namespace std;

typedef long long int lli;
struct Edge {
    int a, b, c;
    Edge (int a, int b, int c) : a(a), b(b), c(c) {}
    Edge () {}
};

int main () {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G;
    G.resize(N);
    vector<Edge> edges(M);

    REP (i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[b].push_back(a);
        edges[i].a = a;
        edges[i].b = b;
        edges[i].c = -c;
    }

    queue<int> q;
    vector<bool> isAccess(N, false);
    q.push(N - 1);
    while (q.size()) {
        int v = q.front();
        q.pop();
        if (isAccess[v]) continue;
        isAccess[v] = true;
        REP (i, 0, G[v].size()) {
            q.push(G[v][i]);
        }
    }

    const lli inf = 1LL << 60;
    vector<lli> dis(N, inf);
    dis[0] = 0;
    REP (i, 0, 2 * N) {
        for (auto edge : edges) {
            int from = edge.a;
            int to = edge.b;
            if (dis[from] + edge.c < dis[to]) {
                if (i >= N - 1 && (isAccess[to] || isAccess[from])) {
                    cout << "inf" << endl;
                    return 0;
                }
                dis[to] = dis[from] + edge.c;
            }
        }
    }
    cout << -dis[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
def cmb(n, r, mod):
    r = min(n-r, r)
    if r == 0:
        return 1
    over, under = 1, 1
    for i in range(1, r+1):
        over = over * (n-i+1) % mod
        under = under * i % mod
    inv = pow(under, mod-2, mod)
    return over * inv % mod


n, a, b = map(int, input().split())
mod = 10**9 + 7

print((pow(2, n, mod) - cmb(n, a, mod) - cmb(n, b, mod) - 1) % mod)


Measured memory_bytes: 3064
N, M, C = map(int, input().split())
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  sum = 0
  A = list(map(int,input().split()))
  for i in range(M):
    sum += A[i]*B[i]
  sum += C
  if sum > 0:
    ans += 1
print(ans)

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

int main(void)
{
	int n, m;
	scanf("%d %d",&n,&m);
	int *l;
	int *r;
	l = (int*)malloc(sizeof(int)*(m+2));
	r = (int*)malloc(sizeof(int)*(m+2));
	int i = 0;
	while (i < m)
	{
		scanf("%d %d",&l[i],&r[i]);
		i++;
	}
	int sum = 0;
	int min = 0;
	int max = 100000;
	i = 0;
	while (i < m)
	{
		if(l[i] > min)
			min = l[i];
		if(r[i] < max)
			max = r[i];
		//printf("max:%d, min:%d\n",max, min);
		i++;
	}
	sum = max-min + 1;
	if (sum <0)
		sum = 0;
	printf("%d\n",sum);
	return(0);
}


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

int main()
{
  ll x;
  cin >> x;
  ll ans = (x/500)*1000 + ((x%500)/5)*5;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 #define ll long long int
 int main()
  {   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
       ll a,b,c,x,i,j;
         string  y,z;
          cin>>y>>z;
          a=INT_MAX;
            for(i=0;i<y.size()-z.size()+1;i++)
            {  c=0;
                for(j=0;j<z.size();j++)
               { if(y[i+j]!=z[j])
                     c++;
               }
                a=min(a,c);
               }
               cout<<a<<endl;
            }

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string in;
    cin >> in;
    if(in[1] == 'R') {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
    return 0;
}




Measured memory_bytes: 3624
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll K;
    cin >> K;
    rep(i,0,K){
        cout << "ACL";
    }
    cout << endl;
    

}

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

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
	int A, B, K;
	scanf("%d %d %d", &A, &B, &K);

	if ((A+K) > (B-K)) {
		for (int i = 0;  A + i <= B; ++i) {
			printf("%d\n", A+i);
		}
	} else {
		for (int i = 0; i < K; ++i) {
			printf("%d\n", A+i);
		}
		for (int i = K-1; i >= 0; --i) {
			printf("%d\n", B-i);
		}
	}

	return 0;
}

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

int main() {
long long n;
string s;
cin >> n >> s;
long long sum[n+1];
sum[0]=0;
for(int i=0;i<n;i++){
    if(s[i]=='E')sum[i+1]=sum[i]+1;
    else sum[i+1]=sum[i];
}
long long people[n];
for(int i=0;i<n;i++){
    people[i]=sum[n]-sum[i];
    people[i]+=(i+1)-sum[i+1];
}
long long ans=300000;
for(int i=0;i<n;i++){
    ans=min(ans,people[i]);
}
cout << ans-1 << endl;
}


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

int main(){
  int n = 0;
  cin>>n;
  string names[n];
  for(int i=0; i<n; i++){
    cin>>names[i];
  }
  sort(names, names + n);
  int max = 1, index = 0;
  while(index < (n-1))
  {
    if(names[index] != names[index+1]){
      max++;
    }
    index++;
  }
  cout<<max;
  return 0;
}

Measured memory_bytes: 9864
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: i64 = itr.next().unwrap().parse().unwrap();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();

    if (b - a) % 2 == 0 {
        println!("{}", (b - a) / 2);
    } else {
        let v1 = n - b + 1 + (b - a) / 2;
        let v2 = a - 1 + 1 + (b - a) / 2;
        println!("{}", std::cmp::min(v1, v2));
    }
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int dp[100005][3];
int abc[100005][3];

void Main() {

    rep(i, 100005) {
        rep(j, 3) {
            dp[i][j] = 0;
        }
    }

    int n;
    cin >> n;

    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        abc[i][0] = a;
        abc[i][1] = b;
        abc[i][2] = c;
    }

    rep(i, 3) {
        dp[0][i] = 0;
    }
    for (int i = 1; i <= n; ++i) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k)continue;
                chmax(dp[i][j], dp[i - 1][k] + abc[i - 1][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 3) chmax(ans, dp[n][i]);
    cout << ans << endl;

}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  long long a,b,n;
  long long ans = 10000000000000;
  long long c;
  cin >> a >> b >> n;
  for(int i = 1;i<=n;i++){
    for(int j = 1;j<=n;j++){
      if(b%i==0){
	c = abs(a-(b*j/i));
	if(c<ans) ans = c;
      }
    }
  }  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1160
#set
counter = 0
exit_code = 0

#main
n = gets.to_i
numbers_arr = gets.chomp.split(" ").map(&:to_i)

if n != numbers_arr.length then
    exit
end

loop do
    numbers_arr = numbers_arr.map do |i| 
        if i % 2 == 1 then
            exit_code = 1
            break
        end
        i / 2
    end

    if exit_code == 1 then
        break
    end

    counter += 1
end

print ("#{counter} \n")


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <utility>
#include <stack>

using namespace std;
int n,x,y;
int ans=1;
int Q[100000+10];

pair<int,int> P[100000+10];
int cal_cross(pair<int, int> a, pair<int, int> b, pair<int, int> c){
	return (b.second-a.second)*(c.first-a.first)-(b.first-a.first)*(c.second-a.second);
}

int main() {
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> x >> y;
		P[i] = make_pair(y,x);
	}
	sort(P,P+n);
	Q[0] = 0;
	for (int i=1; i<n; i++){
		while ((ans>=2) && cal_cross(P[Q[ans-2]],P[Q[ans-1]],P[i])<0){
			ans--;
		}
		Q[ans++] = i;
	}
	for (int i=n-2; i>=0; i--){
		while ((ans>=2) && cal_cross(P[Q[ans-2]],P[Q[ans-1]],P[i])<0){
			ans--;
		}
		Q[ans++] = i;
	}
	cout << ans-1 << endl;
	for (int i=0; i<ans-1; i++){
		cout << P[Q[i]].second << ' ' << P[Q[i]].first << endl;
	}
}

Measured memory_bytes: 4200
N = int(input())
X = list(map(int, input().split()))
assert len(X) == N
# N人が点Xiに住んでいる
# 任意の整数値の点で集会を開く
# 2乗距離の体力を消耗

# 点yで集会
def sum_power(y):
  return sum([(x - y) * (x - y) for x in X])

import sys
minimum = sys.maxsize
for y in range(min(X), max(X)+1):
  minimum = min(minimum, sum_power(y))
print(minimum)

Measured memory_bytes: 64468
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int x,y,s;
  while(1){
    cin>>x>>y>>s;
    if(x==0 && y==0 && s==0)break;
    vector<int> good1,good2;
    loop(i,1,s){
      loop(j,1,s){
	int num1=i*(100+x)/100;
	int num2=j*(100+x)/100;
	if((num1+num2)==s){   
	  good1.push_back(i);
	  good2.push_back(j);
	}
      }
    }
    int ans=0;
    int size=good1.size();
    rep(i,size){
      int ans1=good1[i]*(100+y)/100;
      int ans2=good2[i]*(100+y)/100;
      ans=max(ans,ans1+ans2);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
import java.util.*;

public class Main {
	final int INF = 1 << 24;
	HashMap<C,C> pass;
	int ans;
	String [][] data;
	char [][] map;
	String [] store;
	boolean [] used;
	HashMap<Character, Character> change;
	
	class C{
		int pos ,ind;
		public C(int pos, int ind) {
			this.pos = pos;	this.ind = ind;
		}
	}
	
	private void dfs(int deep){
		if(deep == 9){
			ans++;
			return;
		}
		for(int j = 0; j< 9; j++){
			if(used[j]) continue;
			for(int i=0; i < 4; i++){
				store[deep] = data[j][i];
				if(check(deep+1)){
					used[j] = true;
					dfs(deep+1);
					used[j] = false;
				}
			}
		}
		
		return ;
	}
	
	private boolean check(int deep){
		for(C from: pass.keySet()){
			C to = pass.get(from);
			if( from.pos >= deep || from.pos <= to.pos ) continue;
			if(store[from.pos].charAt(from.ind) != change.get(store[to.pos].charAt(to.ind))){
				return false;
			}
			//System.out.println(store[from.pos].charAt(from.ind) +" "+ change.get(store[to.pos].charAt(to.ind)));
		}
		return true;
	}

	private void doit() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		pass = new HashMap<C,C>();
		passCreate();
		change = new HashMap<Character, Character>();
		change.put('R', 'r');
		change.put('G', 'g');
		change.put('B', 'b');
		change.put('W', 'w');
		change.put('r', 'R');
		change.put('g', 'G');
		change.put('b', 'B');
		change.put('w', 'W');
		while(n-- > 0){
			data = new String[9][4];
			for(int i =0; i < 9; i++){
				String str = sc.next();
				for(int j =0; j < 4; j ++){
					char [] work = new char[4];
					for(int k =0; k < 4; k++){
						work[k] = str.charAt((k+j) % 4);
					}
					data[i][j] = new String(work);
				}
			}
			//ini
			ans = 0;
			map = new char[9][9];
			store = new String[9];
			used = new boolean[9];
			for(int i = 0; i < 9; i++){
				Arrays.fill(map[i], '*');
			}
			dfs(0);
			System.out.println(ans);
		}
	}
	
	private void passCreate(){
		pass.put(new C(0,1), new C(1,3));
		pass.put(new C(0,2), new C(3,0));
		
		pass.put(new C(1,3), new C(0,1));
		pass.put(new C(1,1), new C(2,3));
		pass.put(new C(1,2), new C(4,0));
		
		pass.put(new C(2,3), new C(1,1));
		pass.put(new C(2,2), new C(5,0));
		
		pass.put(new C(3,0), new C(0,2));
		pass.put(new C(3,1), new C(4,3));
		pass.put(new C(3,2), new C(6,0));
		
		pass.put(new C(4,0), new C(1,2));
		pass.put(new C(4,1), new C(5,3));
		pass.put(new C(4,2), new C(7,0));
		pass.put(new C(4,3), new C(3,1));
		
		pass.put(new C(5,0), new C(2,2));
		pass.put(new C(5,3), new C(4,1));
		pass.put(new C(5,2), new C(8,0));
		
		pass.put(new C(6,0), new C(3,2));
		pass.put(new C(6,1), new C(7,3));
		
		pass.put(new C(7,0), new C(4,2));
		pass.put(new C(7,1), new C(8,3));
		pass.put(new C(7,3), new C(6,1));
		
		pass.put(new C(8,0), new C(5,2));
		pass.put(new C(8,3), new C(7,1));
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    a = LI()
    ma = [None] * (n + 1)
    tmp = 0
    for i in range(n, -1, -1):
        x = pow(2, i)
        tmp += a[i]
        if tmp <= x:
            tmp = (tmp - 1) // 2 + 1
            continue
        else:
            print(-1)
            return
    ma[n] = a[-1]
    for i in range(n - 1, -1, -1):
        ma[i] = min(pow(2, i), ma[i + 1] + a[i])
    tmp = 1
    ans = 1
    for i in range(1, n + 1):
        tmp = tmp * 2
        ans += min(tmp, ma[i])
        tmp = min(tmp, ma[i])
        tmp -= a[i]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 93452
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

struct edge {
  ll to, cost;
  edge(ll to, ll cost) : to(to), cost(cost) {}
};

int V, E;
vector<vector<edge>> G;
vector<ll> dist;

typedef pair<ll, int> P;  // <最短距離, 頂点の番号>

/* 負閉路の検出はできない。O(E logV) */
/* 負の辺があってもダメ */
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(dist.begin(), dist.end(), LINF);
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N - 1), b(N - 1);
  rep(i, N - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  int V = N, E = N - 1;
  G = vector<vector<edge>>(V);

  for (int i = 0; i < E; i++) {
    G[a[i]].push_back(edge(b[i], 1));
    G[b[i]].push_back(edge(a[i], 1));
  }

  dist = vector<ll>(V, 0);
  dijkstra(0);
  vector<ll> dist_F = dist;

  dist = vector<ll>(V, 0);
  dijkstra(N - 1);
  vector<ll> dist_S = dist;

  int cnt_F = 0, cnt_S = 0;
  rep(i, N) {
    if (dist_F[i] <= dist_S[i])
      cnt_F++;
    else
      cnt_S++;
  }

  if (cnt_F > cnt_S)
    cout << "Fennec" << endl;
  else
    cout << "Snuke" << endl;
}


Measured memory_bytes: 10588
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

 int main(){
     long long n, a, b;
     cin >> n >> a >> b;
     long long x = n / (a + b), y = n % (a + b);
     if (y >= a) cout << (x + 1) * a;
     else cout << x * a + y;



    
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%s', $N);

if (substr($N, 0, 1) === substr($N, 1, 1) && substr($N, 1, 1) === substr($N, 2, 1) || substr($N, 1, 1) === substr($N, 2, 1) && substr($N, 2, 1) === substr($N, 3, 1)) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;


Measured memory_bytes: 16096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i,n,count;
    count=0;
    cin >> n;
    vector<int> vec(n);
    for(i=0;i<n;i++){
        cin >> vec.at(i);
    }
    for(i=0;i<n-2;i++){
        if( (vec.at(i)<vec.at(i+1)&&vec.at(i+1)<vec.at(i+2)) ||
        (vec.at(i+2)<vec.at(i+1)&&vec.at(i+1)<vec.at(i)) ){
        count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		long ans = 0;
		for(int i = 0; i < n; i++) {
			 ans += sc.nextInt()-1;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 40760
#include <string>
using std::string;

#include <iostream>
using std::cout;
using std::cin;

#include <vector>
using std::vector;

#include <cmath>
using std::abs;

inline long long getNum(long long A, long long B, long long num){
    if(num == 0){
        return 0; 
    }
    long long firstOne = A/num + 1;
    if(A%num == 0){
        firstOne -= 1; 
    }
    long long endOne = B/num;

    return endOne - firstOne + 1;
}

inline long long gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
    long long A, B, C, D;

    cin >> A >> B >> C >> D;

    cout << B -A + 1 - (getNum(A, B, C) + getNum(A, B, D) - getNum(A, B, C*D/gcd(C,D)));

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int D;
  cin>>D;
  if(D==25) cout<<"Christmas"<<endl;
  else if(D==24) cout<<"Christmas Eve"<<endl;
  else if(D==23) cout<<"Christmas Eve Eve"<<endl;
  else if(D==22) cout<<"Christmas Eve Eve Eve"<<endl;
  return 0;
}


Measured memory_bytes: 256